-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inventorious.lua
112 lines (87 loc) · 3.32 KB
/
Inventorious.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
Inventorious = Inventorious or {}
Inventorious.name = "Inventorious"
-- imports
local AccountHoldings = Inventorious.imports.AccountHoldings
-- locals
local bagNames = {
[BAG_WORN] = "Equipped",
[BAG_BACKPACK] = "Backpack",
[BAG_BANK] = "Bank",
[BAG_SUBSCRIBER_BANK] = "Bank",
[BAG_HOUSE_BANK_ONE] = "Housing Storage #1",
[BAG_HOUSE_BANK_TWO] = "Housing Storage #2",
[BAG_HOUSE_BANK_THREE] = "Housing Storage #3",
[BAG_HOUSE_BANK_FOUR] = "Housing Storage #4",
[BAG_HOUSE_BANK_FIVE] = "Housing Storage #5",
[BAG_HOUSE_BANK_SIX] = "Housing Storage #6",
[BAG_HOUSE_BANK_SEVEN] = "Housing Storage #7",
[BAG_HOUSE_BANK_EIGHT] = "Housing Storage #8",
[BAG_HOUSE_BANK_NINE] = "Housing Storage #9",
[BAG_HOUSE_BANK_TEN] = "Housing Storage #10"
}
local initialized = false
local bagList
local holdings
local function checkInventory(character, bagId, isTest)
d("Checking Bag " .. bagNames[bagId])
local nBagItems = GetBagSize(bagId)
for slotIdx = 0, nBagItems - 1 do
local itemId = GetItemId(bagId, slotIdx)
if itemId > 0 then
local isWorn = (bagId == BAG_WORN)
holdings.CheckHoldings(character, bagId, slotIdx, isWorn, isTest)
end
end
end
local checkAll = function(isTest)
local character = GetUnitName("player")
for idx, bagId in ipairs(bagList) do
checkInventory(character, bagId, isTest)
end
end
local initialize = function()
if IsESOPlusSubscriber() then
bagList = { BAG_WORN, BAG_BACKPACK, BAG_BANK, BAG_SUBSCRIBER_BANK, BAG_HOUSE_BANK_ONE, BAG_HOUSE_BANK_TWO, BAG_HOUSE_BANK_THREE, BAG_HOUSE_BANK_FOUR, BAG_HOUSE_BANK_FIVE, BAG_HOUSE_BANK_SIX, BAG_HOUSE_BANK_SEVEN, BAG_HOUSE_BANK_EIGHT, BAG_HOUSE_BANK_NINE, BAG_HOUSE_BANK_TEN }
else
bagList = { BAG_WORN, BAG_BACKPACK, BAG_BANK, BAG_HOUSE_BANK_ONE, BAG_HOUSE_BANK_TWO, BAG_HOUSE_BANK_THREE, BAG_HOUSE_BANK_FOUR, BAG_HOUSE_BANK_FIVE, BAG_HOUSE_BANK_SIX, BAG_HOUSE_BANK_SEVEN, BAG_HOUSE_BANK_EIGHT, BAG_HOUSE_BANK_NINE, BAG_HOUSE_BANK_TEN }
end
holdings = AccountHoldings.create()
local savedVars = ZO_SavedVars:NewAccountWide("Inventorious_State", 1, nil, {})
holdings.Load(savedVars)
SLASH_COMMANDS["/inventorious"] = function(command)
if (initialized == false) then
d("Inventorious is still initializing - please wait...")
return
end
if ("save" == command) then
d("Saving...")
holdings.Save(savedVars)
elseif ("load" == command) then
d("Loading...")
holdings.Load(savedVars)
elseif ("clear" == command) then
d("Clearing...")
holdings.Clear()
elseif ("test" == command) then
d("Testing...")
checkAll(true)
elseif ("check" == command) then
d("Checking...")
checkAll(false)
holdings.Save(savedVars)
end
d("Done!")
end
holdings.Load(savedVars)
initialized = true
end
EVENT_MANAGER:RegisterForEvent(Inventorious.name, EVENT_ADD_ON_LOADED, function(event, addonName)
if addonName == Inventorious.name then
EVENT_MANAGER:UnregisterForEvent(Inventorious.name, EVENT_ADD_ON_LOADED)
initialize()
end
end)
-- Globals
Inventorious.GetInitialized = function()
return initialized
end