-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecialItems.lua
426 lines (363 loc) · 10.4 KB
/
SpecialItems.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
local _, addon = ...
local module = addon:NewModule("SpecialItems", "AceEvent-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("PetLeash")
local AceConfig = LibStub("AceConfig-3.0")
local GetItemCount = C_Item.GetItemCount
local IsEquippedItem = C_Item.IsEquippedItem
local GetItemInfo = C_Item.GetItemInfo
local GetSpellInfo = C_Spell.GetSpellInfo
local GetQuestLogTitle = C_QuestLog.GetInfo
local _G = _G
--
-- Item Entries
--
local SpecialItems = {}
-- Orcish Orphan Whistle
SpecialItems["item:18597"] = function(item)
item:RegisterEvent("BAG_UPDATE")
function item:Check()
return GetItemCount(18597) > 0
end
end
-- Human Orphan Whistle
SpecialItems["item:18598"] = function(item)
item:RegisterEvent("BAG_UPDATE")
function item:Check()
return GetItemCount(18598) > 0
end
end
-- Bloodsail Hat
SpecialItems["item:12185"] = function(item)
item:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
item:RegisterEvent("EQUIPMENT_SWAP_FINISHED")
function item:Check()
return IsEquippedItem(12185)
end
end
-- Felhound Whistle (TODO TEST ME)
SpecialItems["item:30803"] = function(item)
item:RegisterEvent("BAG_UPDATE")
function item:Check()
return GetItemCount(30803) > 0
end
end
-- Zeppit's Crystal (Bloody Imp-ossible!)
SpecialItems["item:31815"] = function(item)
item:RegisterEvent("BAG_UPDATE")
function item:Check()
return GetItemCount(31815) > 0
end
end
-- Blood Elf Orphan Whistle
SpecialItems["item:31880"] = function(item)
item:RegisterEvent("BAG_UPDATE")
function item:Check()
return GetItemCount(31880) > 0
end
end
-- Draenei Orphan Whistle
SpecialItems["item:31881"] = function(item)
item:RegisterEvent("BAG_UPDATE")
function item:Check()
return GetItemCount(31881) > 0
end
end
-- Nether Ray Cage (TODO CHECK ME)
SpecialItems["item:32834"] = function(item)
item:RegisterEvent("BAG_UPDATE")
function item:Check()
return GetItemCount(32834) > 0
end
end
-- Warsong Flare Gun (Alliance Deserter) (TODO TEST ME)
SpecialItems["item:34971"] = function(item)
item:RegisterEvent("BAG_UPDATE")
function item:Check()
return GetItemCount(34971) > 0
end
end
-- Golem Control Unit (TODO TEST ME)
SpecialItems["item:36936"] = function(item)
item:RegisterEvent("BAG_UPDATE")
function item:Check()
return GetItemCount(36936) > 0
end
end
-- Venomhide Hatchling (20day Raptor Mount quest)
SpecialItems["item:46362"] = function(item)
item:RegisterEvent("BAG_UPDATE")
item:RegisterEvent("ZONE_CHANGED")
item:RegisterEvent("ZONE_CHANGED_NEW_AREA")
function item:Check()
local mapname = GetZoneText()
return GetItemCount(46362) > 0 and mapname == "Un'Goro Crater" or mapname == "Tanaris"
end
end
-- Wolvar Orphan Whistle
SpecialItems["item:46396"] = function(item)
item:RegisterEvent("BAG_UPDATE")
function item:Check()
return GetItemCount(46396) > 0
end
end
-- Oracle Orphan Whistle
SpecialItems["item:46397"] = function(item)
item:RegisterEvent("BAG_UPDATE")
function item:Check()
return GetItemCount(46397) > 0
end
end
-- TODO check me
SpecialItems["item:46831"] = function(item)
item:RegisterEvent("BAG_UPDATE")
function item:Check()
return GetItemCount(46831) > 0
end
end
-- Winterspring Cub (20day Winterspring Frostsaber quest)
SpecialItems["item:68646"] = function(item)
item:RegisterEvent("BAG_UPDATE")
item:RegisterEvent("ZONE_CHANGED")
item:RegisterEvent("ZONE_CHANGED_NEW_AREA")
function item:Check()
local mapname = GetZoneText()
return GetItemCount(68646) > 0 and mapname == "Winterspring"
end
end
SpecialItems["item:71137"] = function(item)
item:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
function item:TimerFinished()
self.timer = nil
self:Update(false)
end
function item:Check(event, ...)
if event == "UNIT_SPELLCAST_SUCCEEDED" then
local unit, name, _, _, spellid = ...
if unit == "player" and spellid == 100959 then
self.timer = self:ScheduleTimer("TimerFinished", 180)
return true
end
end
return self.timer ~= nil
end
end
-- TODO check me
SpecialItems["quest:11878"] = function(item)
item:RegisterQuestEvent()
function item:Check()
return self:PlayerHasQuest(11878)
end
end
-- TODO check me
SpecialItems["quest:26831"] = function(item)
item:RegisterQuestEvent()
function item:Check()
return self:PlayerHasQuest(26831)
end
end
-- TODO check me
SpecialItems["quest:25371"] = function(item)
item:RegisterQuestEvent()
function item:Check()
return self:PlayerHasQuest(25371)
end
end
-- Various Nagrand Quests
SpecialItems["quest:35396"] = function(item)
item:RegisterQuestEvent()
function item:Check()
return self:PlayerHasQuest(25371)
or self:PlayerHasQuest(35317)
or self:PlayerHasQuest(35331)
or self:PlayerHasQuest(34965)
end
end
--
--
--
local defaults = {
profile = {
enable = true,
items = {
["*"] = true
}
},
global = {
localeCache = {
["*"] = {}
}
}
}
local options = {
type = "group",
name = L["Special Items"],
order = 11,
cmdHidden = true,
args = {
explain = {
type = "description",
name = L["EXPLAIN_SPECIAL_ITEMS"],
order = 0,
},
enable = {
type = "toggle",
name = ENABLE,
order = 1,
get = function()
return module.db.profile.enable
end,
set = function(_, val)
module.db.profile.enable = val
module:UpdateReadyEnabled()
end,
},
itemsGroup = {
type = "group",
name = ITEMS,
inline = true,
order = 2,
get = function(info)
return module.db.profile.items[info[#info]]
end,
set = function(info, val)
module.db.profile.items[info[#info]] = val
module:UpdateReadyEnabled()
end,
args = {},
},
}
}
--
--
--
function module:OnInitialize()
self.items = {}
self.event_item_map = {}
self.event_handler = CreateFrame("FRAME")
self.event_handler:SetScript("OnEvent", function(f, ev, ...)
self:HandleEvent(ev, ...)
end)
self.ready = addon:GetModule("Ready")
self.db = addon.db:RegisterNamespace("SpecialItems", defaults)
self.currentQuests = {}
self:RegisterEvent("QUEST_LOG_UPDATE", "UpdateQuestList")
self:RegisterEvent("QUEST_ACCEPTED", "UpdateQuestList")
self:RegisterEvent("QUEST_FINISHED", "UpdateQuestList")
self:RegisterEvent("PLAYER_ENTERING_WORLD", "UpdateQuestList")
self:UpdateQuestList()
self:InitWatchers()
self:UpdateReadyEnabled()
end
function module:SetupOptions(setup)
AceConfig:RegisterOptionsTable(self.name, options)
setup(self.name, L["Special Items"])
end
function module:UpdateReadyEnabled()
for item in pairs(SpecialItems) do
self.ready:EnableCheck(item, module.db.profile.enable and module.db.profile.items[item])
end
end
local function config_localize_string(info)
return module:LocalizeString(info[#info])
end
function module:InitWatchers()
local args = options.args.itemsGroup.args
for itemName, func in pairs(SpecialItems) do
if not args[itemName] then
args[itemName] = {
type = "toggle",
name = config_localize_string,
}
end
local item = self.items[itemName] or self:InitItem(itemName, func)
item:Update(item:Check("Init"))
end
end
function module:SI_RegisterEvent(item, event)
if not self.event_item_map[event] then
self.event_item_map[event] = {}
if event ~= "UpdateQuestList" then
self.event_handler:RegisterEvent(event)
end
end
tinsert(self.event_item_map[event], item)
end
function module:HandleEvent(event, ...)
if self.event_item_map[event] then
for _,item in ipairs(self.event_item_map[event]) do
item:Update(item:Check(event, ...))
end
end
end
function module:UpdateQuestList()
_G.wipe(self.currentQuests)
for i = 1, (C_QuestLog:GetNumQuestLogEntries() or 0) do
local link = GetQuestLink(i)
if link ~= nil then
local _,_,qid = strfind(link, "|Hquest:(%d+):(%d+)|")
if qid ~= nil then
self.currentQuests[tonumber(qid)] = true
end
end
end
self:HandleEvent("UpdateQuestList")
end
function module:LocalizeString(s)
local cache = self.db.global.localeCache[GetLocale()]
if cache[s] then
return cache[s]
end
local name = self:AskClientForName(s)
if name then
cache[s] = name
return name
end
return s
end
function module:AskClientForName(item)
if strsub(item, 1,5) == "item:" then
return (GetItemInfo(item))
elseif strsub(item, 1,6) == "spell:" then
return (GetSpellInfo(strsub(item,7)))
elseif strsub(item, 1,6) == "quest:" then
local questid = strsub(item,7)
for i = 1, (C_QuestLog:GetNumQuestLogEntries() or 0) do
local link = GetQuestLink(i)
if link ~= nil then
local _,_,qid = strfind(link, "|Hquest:(%d+):(%d+)|")
if qid == questid then
return (GetQuestLogTitle(i))
end
end
end
end
end
--
-- SpecialItem construction
--
local SpecialItemMeta = {}
SpecialItemMeta.__index = SpecialItemMeta
LibStub("AceTimer-3.0"):Embed(SpecialItemMeta)
function SpecialItemMeta:RegisterEvent(event)
module:SI_RegisterEvent(self, event)
end
function SpecialItemMeta:RegisterQuestEvent()
self:RegisterEvent("UpdateQuestList")
end
function SpecialItemMeta:PlayerHasQuest(questID)
return module.currentQuests[questID]
end
function SpecialItemMeta:Check(...)
print("WARNING: Check not implemented for "..tostring(self.name))
end
function SpecialItemMeta:Update(value)
module.ready:SetReady(self.name, not value)
end
function module:InitItem(name, func)
local item = setmetatable({}, SpecialItemMeta)
item.name = name
item:RegisterEvent("PLAYER_ENTERING_WORLD")
self.items[name] = item
func(item)
return item
end