-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmobs.lua
executable file
·367 lines (353 loc) · 10.3 KB
/
mobs.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
local myname, ns = ...
local HBD = LibStub("HereBeDragons-2.0")
local core = LibStub("AceAddon-3.0"):GetAddon("SilverDragon")
local module = core:NewModule("Mobs", "AceConsole-3.0")
local Debug = core.Debug
local function toggle_mob(id)
return {
arg = id,
name = core:GetMobLabel(id),
desc = "ID: " .. id,
type = "toggle",
-- width = "double",
descStyle = "inline",
order = id,
}
end
local mob_names = {}
local function input_to_mobid(value)
if not value then return end
value = value:trim()
if value == "target" or value == "mouseover" then
return core:UnitID(value)
end
if value:match("^%d+$") then
return tonumber(value)
end
return mob_names[value] or core:IdForMob(value)
end
ns.input_to_mobid = input_to_mobid
local function mob_input(name, desc, order, setter)
return {
type = "input",
name = name,
desc = desc,
get = function() return "" end,
set = function(info, value)
setter(info, input_to_mobid(value))
end,
validate = function(info, value)
if input_to_mobid(value) then
return true
end
end,
order = order,
}
end
function module:OnEnable()
local config = core:GetModule("Config", true)
if not config then return end
core.RegisterCallback(self, "OptionsRequested")
core.RegisterCallback(self, "IgnoreChanged")
core.RegisterCallback(self, "CustomChanged")
core.RegisterCallback(self, "Seen")
end
function module:Seen(callback, id, zone, x, y, dead, source)
local name = core:NameForMob(id)
if name then
mob_names[name] = id
end
local config = core:GetModule("Config", true)
if config and config.options.plugins.mobs then
local args = config.options.plugins.mobs.mobs.args.ignore.args.mobs.args
args["mob"..id] = args["mob"..id] or toggle_mob(id)
end
end
function module:IgnoreChanged(callback, id, ignored)
if not ignored then return end
local config = core:GetModule("Config", true)
if config and config.options.plugins.mobs then
config.options.plugins.mobs.mobs.args.ignore.args.mobs.args["mob"..id] = toggle_mob(id)
end
end
function module:CustomChanged(callback, id, watched, uiMapID)
if not watched then return end
local config = core:GetModule("Config", true)
if config and config.options.plugins.mobs then
if not config.options.plugins.mobs.mobs.args.custom.args["map"..uiMapID] then
self:BuildCustomList(config.options)
else
config.options.plugins.mobs.mobs.args.custom.args["map"..uiMapID].args["mob"..id] = toggle_mob(id)
end
end
end
function module:OptionsRequested(callback, options)
options.plugins.mobs = {
mobs = {
type = "group",
name = "Mobs",
childGroups = "tab",
order = 15,
args = {
custom = {
type = "group",
name = CUSTOM,
order = 1,
args = {
add = {
type = "input",
name = ADD,
desc = "Add a new zone to watch by entering its id or 'current'",
get = function() return "" end,
set = function(info, value)
if value == "current" then
value = HBD:GetPlayerZone()
end
value = tonumber(value)
if value and not core.db.global.custom[value] then
core.db.global.custom[value] = {}
end
self:BuildCustomList(options)
end,
validate = function(info, value)
if value == "current" then return true end
return tonumber(value)
end,
order = 1,
},
zones = {
type = "group",
name = ZONE,
inline = false,
childGroups = "tree",
args = {},
order = 10,
},
},
},
ignore = {
type = "group",
name = IGNORE,
desc = "Mobs you just want to ignore, already",
args = {
add = mob_input(ADD, "Add a mob by entering its id, name, 'target', or 'mouseover'.", 1, function(info, id)
core:SetIgnore(id, true)
end),
mobs = {
type = "group",
name = REMOVE,
inline = true,
get = function(info) return core.db.global.ignore[info.arg] end,
set = function(info, value)
core:SetIgnore(info.arg, not core.db.global.ignore[info.arg])
end,
args = {
desc = core:GetModule("Config").desc("This will fill in as rare mobs are seen in the current session.", 0),
},
}
},
order = 2,
},
},
},
}
self:BuildIgnoreList(options)
self:BuildCustomList(options)
self:BuildMobList(options)
core.UnregisterCallback(self, "OptionsRequested")
end
function module:BuildIgnoreList(options)
-- wipe(options.plugins.mobs.mobs.args.ignore.args.mobs.args)
local args = options.plugins.mobs.mobs.args.ignore.args.mobs.args
for id, ignored in pairs(core.db.global.ignore) do
if ignored then
args["mob"..id] = args["mob"..id] or toggle_mob(id)
end
end
for name, id in pairs(mob_names) do
args["mob"..id] = args["mob"..id] or toggle_mob(id)
end
end
function module:BuildCustomList(options)
-- wipe(options.plugins.mobs.mobs.args.custom.args.mobs.args)
local args = options.plugins.mobs.mobs.args.custom.args.zones.args
for uiMapID, mobs in pairs(core.db.global.custom) do
args["map"..uiMapID] = {
type = "group",
get = function(info)
return core.db.global.custom[uiMapID][info.arg]
end,
set = function(info, value)
core:SetCustom(uiMapID, info.arg, value)
end,
inline = false,
name = uiMapID == "any" and ALL or core.zone_names[uiMapID] or ("map"..uiMapID),
desc = "ID: " .. uiMapID,
args = {
add = mob_input(ADD, "Add a mob by entering its id, name, 'target', or 'mouseover'", 1, function(info, id)
core:SetCustom(uiMapID, id, true)
end),
},
order = uiMapID == "any" and 0 or uiMapID,
}
for mobid, enabled in pairs(mobs) do
if enabled then
args["map"..uiMapID].args["mob"..mobid] = toggle_mob(mobid)
end
end
end
end
function module:BuildMobList(options)
ns:LoadAllAchievementMobs()
for source, data in pairs(core.datasources) do
local group = {
type = "group",
name = source,
get = function(info)
return not core.db.global.ignore[info.arg]
end,
set = function(info, value)
core:SetIgnore(info.arg, not value)
end,
args = {
enabled = {
type = "toggle",
name = ENABLE,
desc = "If you disable this, SilverDragon will just not know about these mobs. They'll still be announced when you mouse over them, like any unknown rare.",
arg = source,
get = function(info) return core.db.global.datasources[info.arg] end,
set = function(info, value)
core.db.global.datasources[info.arg] = value
core:BuildLookupTables()
end,
disabled = false,
},
ignore = {
type = "toggle",
name = IGNORE,
desc = "Ignore every mob provided by this module. This will make them all not be announced, regardless of any other settings.",
arg = source,
get = function(info) return core.db.global.ignore_datasource[info.arg] end,
set = function(info, value)
core.db.global.ignore_datasource[info.arg] = value
core:BuildLookupTables()
end,
disabled = function(info)
return not core.db.global.datasources[info.arg]
end,
},
zones = {
type = "group",
name = ZONE,
inline = false,
childGroups = "tree",
args = {},
},
},
}
local mob_toggle_disabled = function(info)
return not core.db.global.datasources[info[#info - 3]]
end
for id, mob in pairs(data) do
if ns.mobs_to_achievement[id] then
local achievement = ns.mobs_to_achievement[id]
if not group.args.achievements then
group.args.achievements = {
type = "group",
name = ACHIEVEMENTS,
inline = false,
childGroups = "tree",
args = {},
}
end
if not group.args.achievements.args["achievement"..achievement] then
group.args.achievements.args["achievement"..achievement] = {
type = "group",
inline = false,
name = select(2, GetAchievementInfo(achievement)) or "achievement:"..achievement,
desc = "ID: " .. achievement,
args = {
all = {
type = "execute",
name = ALL,
desc = "Select every mob in the list",
func = function(info)
if not ns.achievements[achievement] then return end
for mobid, criteria in pairs(ns.achievements[achievement]) do
core:SetIgnore(mobid, false, true)
end
self:BuildIgnoreList(info.options)
end,
width = "half",
order = 1,
},
none = {
type = "execute",
name = NONE,
desc = "Deselect every mob in the list",
func = function(info)
if not ns.achievements[achievement] then return end
for mobid, criteria in pairs(ns.achievements[achievement]) do
core:SetIgnore(mobid, true, true)
end
self:BuildIgnoreList(info.options)
end,
width = "half",
order = 2,
},
},
}
end
local toggle = toggle_mob(id)
toggle.disabled = mob_toggle_disabled
group.args.achievements.args["achievement"..achievement].args["mob"..id] = toggle
end
if not mob.hidden and mob.locations then
for zone in pairs(mob.locations) do
if not group.args.zones.args["map"..zone] then
group.args.zones.args["map"..zone] = {
type = "group",
inline = false,
name = core.zone_names[zone] or ("map"..zone),
desc = "ID: " .. zone,
args = {
all = {
type = "execute",
name = ALL,
desc = "Select every mob in the list",
func = function(info)
if not ns.mobsByZone[zone] then return end
for mobid, locations in pairs(ns.mobsByZone[zone]) do
core:SetIgnore(mobid, false, true)
end
self:BuildIgnoreList(info.options)
end,
width = "half",
order = 1,
},
none = {
type = "execute",
name = NONE,
desc = "Deselect every mob in the list",
func = function(info)
if not ns.mobsByZone[zone] then return end
for mobid, locations in pairs(ns.mobsByZone[zone]) do
core:SetIgnore(mobid, true, true)
end
self:BuildIgnoreList(info.options)
end,
width = "half",
order = 2,
},
},
}
end
local toggle = toggle_mob(id)
toggle.disabled = mob_toggle_disabled
group.args.zones.args["map"..zone].args["mob"..id] = toggle
end
end
end
options.plugins.mobs.mobs.args[source] = group
end
end