-
Notifications
You must be signed in to change notification settings - Fork 0
/
bag_browser.lua
49 lines (48 loc) · 1.8 KB
/
bag_browser.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
local alchemy_material_ids = require("static_data.alchemy_material_ids")
local function get_bag_contents(bag_data)
local concatenated_bags = {}
for i = 0, 4 do
local bag_content = bag_data[i]
if bag_content then
for _, item in ipairs(bag_content) do
table.insert(concatenated_bags, item)
end
end
end
return concatenated_bags
end
local function get_item_counts_by_ids(item_ids, bags_content)
local item_amounts_by_id = {}
for _, str in ipairs(bags_content) do
local string_id, string_amount = str:match("([^:]+)::::::::.-:::::::::;([^:]+)")
if string_id and string_amount ~= "" then
local found_item_id = tonumber(string_id)
for _, lookup_item_id in ipairs(item_ids) do
if found_item_id == lookup_item_id then
table.insert(item_amounts_by_id, {tonumber(found_item_id), tonumber(string_amount)})
break
end
end
end
end
local summed_item_amounts_by_id = {}
for _, entry in ipairs(item_amounts_by_id) do
local id = tonumber(entry[1])
local count = tonumber(entry[2])
if summed_item_amounts_by_id[id] then
summed_item_amounts_by_id[id] = summed_item_amounts_by_id[id] + count
else
summed_item_amounts_by_id[id] = count
end
end
return summed_item_amounts_by_id
end
local function get_all_herbs_from_inventory(bag_contents)
local formatted_bag_contents = get_bag_contents(bag_contents)
return get_item_counts_by_ids(alchemy_material_ids, formatted_bag_contents)
end
return {
get_all_herbs_from_inventory = get_all_herbs_from_inventory,
get_bag_contents = get_bag_contents,
get_item_counts_by_ids = get_item_counts_by_ids
}