forked from p3lim-wow/QuickQuest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuickQuest.lua
392 lines (342 loc) · 10.6 KB
/
QuickQuest.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
local QuickQuest = CreateFrame('Frame')
QuickQuest:SetScript('OnEvent', function(self, event, ...) self[event](...) end)
local L = select(2, ...)
local metatable = {
__call = function(methods, ...)
for _, method in next, methods do
method(...)
end
end
}
local modifier = false
function QuickQuest:Register(event, method, override)
local newmethod
if(not override) then
newmethod = function(...)
if(QuickQuestDB.reverse == modifier) then
method(...)
end
end
end
local methods = self[event]
if(methods) then
self[event] = setmetatable({methods, newmethod or method}, metatable)
else
self[event] = newmethod or method
self:RegisterEvent(event)
end
end
local function GetNPCID()
return tonumber(string.match(UnitGUID('npc') or '', '%w+%-.-%-.-%-.-%-.-%-(.-)%-'))
end
local function IsTrackingHidden()
for index = 1, GetNumTrackingTypes() do
local name, _, active = GetTrackingInfo(index)
if(name == (MINIMAP_TRACKING_TRIVIAL_QUESTS or MINIMAP_TRACKING_HIDDEN_QUESTS)) then
return active
end
end
end
local ignoreQuestNPC = {
[88570] = true, -- Fate-Twister Tiklal
[87391] = true, -- Fate-Twister Seress
[111243] = true, -- Archmage Lan'dalock
[103792] = true, -- Griftah (one of his quests is a scam)
[119388] = true, -- Chieftain Hatuun (repeatable resource quest)
[124312] = true, -- High Exarch Turalyon (repeatable resource quest)
[126954] = true, -- High Exarch Turalyon (repeatable resource quest)
[127037] = true, -- Nabiru (repeatable resource quest)
[141584] = true, -- Zurvan (Seal of Wartorn Fate, Horde)
[142063] = true, -- Tezran (Seal of Wartorn Fate, Alliance)
}
local function GetQuestLogQuests(onlyComplete)
local quests = {}
for index = 1, GetNumQuestLogEntries() do
local title, _, _, isHeader, _, isComplete, _, questID = GetQuestLogTitle(index)
if(not isHeader) then
if(onlyComplete and isComplete or not onlyComplete) then
quests[title] = questID
end
end
end
return quests
end
QuickQuest:Register('QUEST_GREETING', function()
local npcID = GetNPCID()
if(ignoreQuestNPC[npcID]) then
return
end
local active = GetNumActiveQuests()
if(active > 0) then
local logQuests = GetQuestLogQuests(true)
for index = 1, active do
local name, complete = GetActiveTitle(index)
if(complete) then
local questID = logQuests[name]
if(not questID) then
SelectActiveQuest(index)
else
local _, _, worldQuest = GetQuestTagInfo(questID)
if(not worldQuest) then
SelectActiveQuest(index)
end
end
end
end
end
local available = GetNumAvailableQuests()
if(available > 0) then
for index = 1, available do
local isTrivial, _, _, _, isIgnored = GetAvailableQuestInfo(index)
if((not isTrivial and not isIgnored) or IsTrackingHidden()) then
SelectAvailableQuest(index)
end
end
end
end)
local ignoreGossipNPC = {
-- Bodyguards
[86945] = true, -- Aeda Brightdawn (Horde)
[86933] = true, -- Vivianne (Horde)
[86927] = true, -- Delvar Ironfist (Alliance)
[86934] = true, -- Defender Illona (Alliance)
[86682] = true, -- Tormmok
[86964] = true, -- Leorajh
[86946] = true, -- Talonpriest Ishaal
-- Sassy Imps
[95139] = true,
[95141] = true,
[95142] = true,
[95143] = true,
[95144] = true,
[95145] = true,
[95146] = true,
[95200] = true,
[95201] = true,
-- Misc NPCs
[117871] = true, -- War Councilor Victoria (Class Challenges @ Broken Shore)
[143925] = true, -- Dark Iron Mole Machine (Dark Iron Dwarf racial)
}
local rogueClassHallInsignia = {
[97004] = true, -- "Red" Jack Findle
[96782] = true, -- Lucian Trias
[93188] = true, -- Mongar
}
local darkmoonDailyNPCs = {
[54601] = true, -- Mola
[15303] = true, -- Maxima Blastenheimer
[14841] = true, -- Rinling
[54605] = true, -- Finlay Coolshot
[85546] = true, -- Ziggie Sparks
[54485] = true, -- Jessica Rogers
[85519] = true, -- Christoph VonFeasel
[67370] = true, -- Jeremy Feasel
}
local function GetAvailableGossipQuestInfo(index)
local name, level, isTrivial, frequency, isRepeatable, isLegendary, isIgnored = select(((index * 7) - 7) + 1, GetGossipAvailableQuests())
return name, level, isTrivial, isIgnored, isRepeatable, frequency == 2, frequency == 3, isLegendary
end
local function GetActiveGossipQuestInfo(index)
local name, level, isTrivial, isComplete, isLegendary, isIgnored = select(((index * 6) - 6) + 1, GetGossipActiveQuests())
return name, level, isTrivial, isIgnored, isComplete, isLegendary
end
QuickQuest:Register('GOSSIP_SHOW', function()
local npcID = GetNPCID()
if(ignoreQuestNPC[npcID]) then
return
end
local active = GetNumGossipActiveQuests()
if(active > 0) then
local logQuests = GetQuestLogQuests(true)
for index = 1, active do
local name, _, _, _, completed = GetActiveGossipQuestInfo(index)
if(completed) then
local questID = logQuests[name]
if(not questID) then
SelectGossipActiveQuest(index)
else
local _, _, worldQuest = GetQuestTagInfo(questID)
if(not worldQuest) then
SelectGossipActiveQuest(index)
end
end
end
end
end
local available = GetNumGossipAvailableQuests()
if(available > 0) then
for index = 1, available do
local _, _, trivial, ignored = GetAvailableGossipQuestInfo(index)
if((not trivial and not ignored) or IsTrackingHidden()) then
SelectGossipAvailableQuest(index)
elseif(trivial and npcID == 64337 and QuickQuestDB.nomi) then
SelectGossipAvailableQuest(index)
end
end
end
if(rogueClassHallInsignia[npcID]) then
return SelectGossipOption(1)
end
if(darkmoonDailyNPCs[npcID] and active == 1 and not select(5, GetActiveGossipQuestInfo(1))) then
-- auto-start the daily interaction
for index = 1, GetNumGossipOptions() do
if(string.find((select((index * 2) - 1, GetGossipOptions())), 'FF0008E8')) then
-- matching by the blue text color is sufficient
return SelectGossipOption(index)
end
end
end
if(available == 0 and active == 0 and GetNumGossipOptions() == 1) then
if(string.match((GetGossipOptions()), TRACKER_HEADER_PROVINGGROUNDS)) then
-- ignore proving grounds queue
return
end
if(QuickQuestDB.faireport) then
if(npcID == 57850) then
return SelectGossipOption(1)
end
end
if(QuickQuestDB.gossip) then
local _, instanceType, _, _, _, _, _, instanceMapID = GetInstanceInfo()
if(QuickQuestDB.withered and instanceType == 'scenario' and instanceMapID == 1626) then
return
end
if(instanceType == 'raid' and QuickQuestDB.gossipraid > 0) then
if(GetNumGroupMembers() > 1 and QuickQuestDB.gossipraid < 2) then
return
end
SelectGossipOption(1)
elseif(instanceType ~= 'raid' and not ignoreGossipNPC[npcID]) then
SelectGossipOption(1)
end
end
end
end)
local darkmoonNPC = {
[57850] = true, -- Teleportologist Fozlebub
[55382] = true, -- Darkmoon Faire Mystic Mage (Horde)
[54334] = true, -- Darkmoon Faire Mystic Mage (Alliance)
}
QuickQuest:Register('GOSSIP_CONFIRM', function(index)
if(not QuickQuestDB.faireport) then return end
local npcID = GetNPCID()
if(npcID and darkmoonNPC[npcID]) then
SelectGossipOption(index, '', true)
StaticPopup_Hide('GOSSIP_CONFIRM')
end
end)
-- FIXME: 8.2 broke this logic, Show|HideUIPanel is now protected
-- QuestFrame:UnregisterEvent('QUEST_DETAIL')
-- QuickQuest:Register('QUEST_DETAIL', function(...)
-- if(not QuestGetAutoAccept() and not QuestIsFromAreaTrigger() and not QuickQuestBlacklistDB[GetQuestID()]) then
-- QuestFrame_OnEvent(QuestFrame, 'QUEST_DETAIL', ...)
-- end
-- end, true)
QuickQuest:Register('QUEST_DETAIL', function(questStartItemID)
if(QuestGetAutoAccept() or (questStartItemID ~= nil and questStartItemID ~= 0)) then
AcknowledgeAutoAcceptQuest()
else
-- XXX: no way to tell if the quest is trivial
AcceptQuest()
end
end)
local function AttemptAutoComplete(event)
if(GetNumAutoQuestPopUps() > 0) then
if(UnitIsDeadOrGhost('player')) then
QuickQuest:Register('PLAYER_REGEN_ENABLED', AttemptAutoComplete)
return
end
local questID, popUpType = GetAutoQuestPopUp(1)
if(popUpType == 'OFFER') then
ShowQuestOffer(GetQuestLogIndexByID(questID))
else
ShowQuestComplete(GetQuestLogIndexByID(questID))
end
else
C_Timer.After(1, AttemptAutoComplete)
end
if(event == 'PLAYER_REGEN_ENABLED') then
QuickQuest:UnregisterEvent('PLAYER_REGEN_ENABLED')
end
end
QuickQuest:Register('PLAYER_LOGIN', AttemptAutoComplete)
QuickQuest:Register('QUEST_AUTOCOMPLETE', AttemptAutoComplete)
QuickQuest:Register('QUEST_ACCEPT_CONFIRM', AcceptQuest)
QuickQuest:Register('QUEST_ACCEPTED', function(id)
if(QuickQuestDB.share) then
QuestLogPushQuest(id)
end
end)
local choiceQueue
QuickQuest:Register('QUEST_ITEM_UPDATE', function()
if(choiceQueue and QuickQuest[choiceQueue]) then
QuickQuest[choiceQueue]()
end
end, true)
QuickQuest:Register('QUEST_PROGRESS', function()
if(IsQuestCompletable()) then
local requiredItems = GetNumQuestItems()
if(requiredItems > 0) then
for index = 1, requiredItems do
local link = GetQuestItemLink('required', index)
if(link) then
local id = GetItemInfoFromHyperlink(link)
for _, itemID in next, QuickQuestBlacklistDB.items do
if(itemID == id) then
return
end
end
else
choiceQueue = 'QUEST_PROGRESS'
return
end
end
end
CompleteQuest()
end
end)
QuickQuest:Register('QUEST_COMPLETE', function()
local choices = GetNumQuestChoices()
if(choices <= 1) then
GetQuestReward(1)
end
end)
local cashRewards = {
[45724] = 1e5, -- Champion's Purse, 10 gold
[64491] = 2e6, -- Royal Reward, 200 gold
-- Items from the Sixtrigger brothers quest chain in Stormheim
[138127] = 15, -- Mysterious Coin, 15 copper
[138129] = 11, -- Swatch of Priceless Silk, 11 copper
[138131] = 24, -- Magical Sprouting Beans, 24 copper
[138123] = 15, -- Shiny Gold Nugget, 15 copper
[138125] = 16, -- Crystal Clear Gemstone, 16 copper
[138133] = 27, -- Elixir of Endless Wonder, 27 copper
}
QuickQuest:Register('QUEST_COMPLETE', function()
local choices = GetNumQuestChoices()
if(choices > 1) then
local bestValue, bestIndex = 0
for index = 1, choices do
local link = GetQuestItemLink('choice', index)
if(link) then
local _, _, _, _, _, _, _, _, _, _, value = GetItemInfo(link)
value = cashRewards[(GetItemInfoFromHyperlink(link))] or value
if(value > bestValue) then
bestValue, bestIndex = value, index
end
else
choiceQueue = 'QUEST_COMPLETE'
return GetQuestItemInfo('choice', index)
end
end
if(bestIndex) then
QuestInfoItem_OnClick(QuestInfoRewardsFrame.RewardButtons[bestIndex])
end
end
end, true)
local sub = string.sub
QuickQuest:Register('MODIFIER_STATE_CHANGED', function(key, state)
if(sub(key, 2) == QuickQuestDB.modifier) then
modifier = state == 1
end
end, true)