-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase.lua
274 lines (248 loc) · 6.93 KB
/
Database.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
local name , AdventureGuide = ...;
local Database = {}
local datebaseDefaults = {
minimapButton = {},
characters = {},
lists = {},
notes = {},
quests = {},
containers = {},
outfits = {},
config = {
showObjectiveTracker = true,
},
mapIcons = {
npc = {
atlas = "QuestNormal",
x = 28,
y = 28,
},
object = {
atlas = "AdventureMapIcon-SandboxQuest",
x = 20,
y = 31,
},
item = {
atlas = "VignetteLoot",
x = 24,
y = 24,
},
questStartItemLooted = {
atlas = "QuestBlob",
x = 24,
y = 24,
},
questTurnInNpc = {
atlas = "QuestTurnin",
x = 26,
y = 26,
},
questStarterNpc = {
atlas = "QuestNormal",
x = 22,
y = 22,
},
questStarterObject = {
atlas = "AdventureMapIcon-SandboxQuest",
x = 25,
y = 39,
},
questObjectiveItem = {
atlas = "ChallengeMode-icon-chest",
x = 19,
y = 20,
},
questObjectiveNpc = {
--atlas = "QuestBlob", --ShipMission_DangerousSkull
atlas = "countdown-swords",
x = 21,
y = 21,
},
},
}
function Database:Init(forceReset)
if not ADVENTURE_GUIDE_GLOBAL then
ADVENTURE_GUIDE_GLOBAL = datebaseDefaults
end
if forceReset then
ADVENTURE_GUIDE_GLOBAL = datebaseDefaults
end
self.db = ADVENTURE_GUIDE_GLOBAL;
AdventureGuide.CallbackRegistry:TriggerEvent("Database_OnInitialized")
end
--[[
function Database:GetConfig(key)
if self.db then
if key then
if key:find(".", nil, true) then
local k1, k2 = strsplit(".", key)
if self.db.config[k1] and self.db.config[k1][k2] then
return self.db.config[k1][k2]
end
else
return self.db.config[key]
end
else
return self.db.config;
end
end
end
function Database:SetConfig(key, val)
if self.db then
if key:find(".", nil, true) then
local k1, k2 = strsplit(".", key)
if not self.db.config[k1] then
self.db.config[k1] = {}
end
if self.db.config[k1] then
self.db.config[k1][k2] = val
end
else
self.db.config[key] = val
end
addon:TriggerEvent("Database_OnConfigChanged", key, val)
end
end
function Database:SearchContainersForItem(itemID)
local t = {}
if self.db then
for nameRealm, containers in pairs(self.db.containers) do
if containers.bags and containers.bags.items then
for k, v in ipairs(containers.bags.items) do
if v.id == itemID then
if not t[nameRealm] then
t[nameRealm] = {}
end
if not t[nameRealm].bags then
t[nameRealm].bags = v.count
else
t[nameRealm].bags = t[nameRealm].bags + v.count
end
end
end
end
if containers.bank and containers.bank.items then
for k, v in ipairs(containers.bank.items) do
if v.id == itemID then
if not t[nameRealm] then
t[nameRealm] = {}
end
if not t[nameRealm].bank then
t[nameRealm].bank = v.count
else
t[nameRealm].bank = t[nameRealm].bank + v.count
end
end
end
end
end
end
return t
end
function Database:UpdateTable(tab, nameRealm, data)
if self.db and self.db[tab] then
self.db[tab][nameRealm] = data;
end
end
function Database:GetTable(tab, nameRealm)
if self.db and self.db[tab] then
if nameRealm then
return self.db[tab][nameRealm]
else
return self.db[tab]
end
end
end
function Database:GetList(name)
return self.db.lists[name]
end
function Database:GetAllLists()
return self.db.lists or {}
end
function Database:AddItemToList(list, item)
if self.db then
if self.db.lists[list] then
table.insert(self.db.lists[list].items, item)
addon:TriggerEvent("Database_OnListChanged", list, self.db.lists[list])
end
end
end
function Database:DeleteList(list)
if self.db then
if self.db.lists[list] then
self.db.lists[list] = nil;
addon:TriggerEvent("Database_OnListDeleted")
end
end
end
function Database:NewList(list, nameRealm, item)
if self.db then
if not self.db.lists then
self.db.lists = {}
end
self.db.lists[list] = {
created = time(),
character = nameRealm,
items = {},
}
if item then
self:AddItemToList(list, item)
end
addon:TriggerEvent("Database_OnNewList")
end
end
function Database:GetOutfits()
return self.db.outfits or {}
end
function Database:DeleteOutfit(name)
if self.db then
local keyToRemove;
for k, v in ipairs(self.db.outfits) do
if v.name == name then
keyToRemove = k
end
end
if keyToRemove then
table.remove(self.db.outfits, keyToRemove)
addon:TriggerEvent("Database_OnOutfitDeleted")
end
end
end
function Database:NewOutfit(outfit, nameRealm)
if self.db then
if not self.db.outfits then
self.db.outfits = {}
end
table.insert(self.db.outfits, {
name = outfit,
character = nameRealm,
items = {},
icon = 0,
})
-- self.db.outfits[outfit] = {
-- created = time(),
-- character = nameRealm,
-- items = {},
-- icon = 0,
-- }
addon:TriggerEvent("Database_OnNewOutfit", self.db.outfits[#self.db.outfits]) --Database_OnOutfitChanged
end
end
function Database:GetCharacterInfo(nameRealm)
if self.db and self.db.characters[nameRealm] then
return self.db.characters[nameRealm]
end
end
function Database:NewCharacter(nameRealm, classID, raceID)
if not self.db.characters[nameRealm] then
self.db.characters[nameRealm] = {
nameRealm = nameRealm,
classID = classID,
raceID = raceID,
}
self.db.quests[nameRealm] = {}
self.db.containers[nameRealm] = {}
end
end
]]
AdventureGuide.Database = Database;