-
Notifications
You must be signed in to change notification settings - Fork 11
/
quest.lua
410 lines (345 loc) · 13.9 KB
/
quest.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
CodexQuest = CreateFrame("Frame")
CodexQuest.queue = {}
CodexQuest.queueEmptied = false
CodexQuest.abandon = ""
CodexQuest.questLog = {}
CodexQuest.questLogTemp = {}
CodexQuest:RegisterEvent("QUEST_WATCH_UPDATE")
CodexQuest:RegisterEvent("QUEST_LOG_UPDATE")
CodexQuest:RegisterEvent("QUEST_FINISHED")
CodexQuest:RegisterEvent("PLAYER_LEVEL_UP")
CodexQuest:RegisterEvent("PLAYER_ENTERING_WORLD")
CodexQuest:RegisterEvent("QUEST_DETAIL")
CodexQuest:RegisterEvent("QUEST_PROGRESS")
CodexQuest:RegisterEvent("QUEST_COMPLETE")
CodexQuest:RegisterEvent("QUEST_GREETING")
CodexQuest:RegisterEvent("QUEST_REMOVED")
CodexQuest:RegisterEvent("GOSSIP_SHOW")
CodexQuest:RegisterEvent("NAME_PLATE_UNIT_ADDED")
CodexQuest:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
CodexQuest:RegisterEvent("ADDON_LOADED")
CodexQuest:SetScript("OnEvent", function(self, event, ...)
if event == "ADDON_LOADED" then
arg1 = ...
if arg1 == "ClassicCodex" then
CodexQuest:AddQuestLogIntegration()
-- CodexQuest:AddWorldMapIntegration()
else
return
end
elseif event == "PLAYER_LEVEL_UP" or event == "PLAYER_ENTERING_WORLD" then
CodexQuest.updateQuestGivers = true
elseif (event == "GOSSIP_SHOW") then
if (IsControlKeyDown()) then
return
end
local activeQuests = {GetGossipActiveQuests()}
local activeQuestCount = GetNumGossipActiveQuests()
local availableQuests = {GetGossipAvailableQuests()}
local availableQuestCount = GetNumGossipAvailableQuests()
-- Turn in everything
if activeQuests and not IsControlKeyDown() then
for index = 1, activeQuestCount do
if (activeQuests[(((index - 1) * 6) + 4)] == true) then -- Check if quest complete
SelectGossipActiveQuest(index)
return
end
end
end
if (availableQuestCount > 0 and not IsControlKeyDown()) then
SelectGossipAvailableQuest(1)
return
end
-- Auto Gossip Feature
-- if not IsControlKeyDown() then
-- SelectGossipOption(1)
-- return
-- end
elseif (event == "QUEST_DETAIL") then
if (IsControlKeyDown()) then
return
end
AcceptQuest()
elseif (event == "QUEST_PROGRESS") then
if (IsControlKeyDown()) then
return
end
CompleteQuest()
elseif (event == "QUEST_COMPLETE") then
if (IsControlKeyDown()) then
return
end
if (GetNumQuestChoices() <= 1) then
GetQuestReward(1)
end
elseif (event == "QUEST_GREETING") then
if (IsControlKeyDown()) then
return
end
local availableQuestCount = GetNumAvailableQuests()
local lastAvailableQuest = 0
local activeQuestCount = GetNumActiveQuests()
local lastActiveQuest = 0
for id, entry in pairs(CodexQuest.queue) do
match = true
if CodexConfig["trackingmethod"] ~= 3 and (CodexConfig["trackingmethod"] ~= 2 or IsQuestWatched(entry[3])) then
CodexMap:DeleteNode("CODEX", entry[1])
local meta = {["addon"] = "CODEX", ["questLogId"] = entry[3]}
for _, id in pairs(entry[2]) do
CodexDatabase:SearchQuestById(id, meta)
end
end
CodexQuest.queue[id] = nil
if table.getn(CodexQuest.queue) == 0 then
CodexQuest.queueEmptied = true
end
return
end
if activeQuestCount > 0 then
for index = 1, activeQuestCount do
for questLogId = 1, 40 do
local title, _, _, header, _, complete = GetQuestLogTitle(questLogId)
if GetActiveTitle(index) == title and complete == 1 then
SelectActiveQuest(index)
end
end
end
end
if availableQuestCount > 0 then
for index = 1, availableQuestCount do
if not IsControlKeyDown() then
SelectAvailableQuest(index)
end
end
end
elseif (event == "NAME_PLATE_UNIT_ADDED") then
CodexQuest:CheckNamePlate()
else
CodexQuest.updateQuestLog = true
end
end)
CodexQuest:SetScript("OnUpdate", function()
if (CodexQuest.tick or 0.2) > GetTime() then return else CodexQuest.tick = GetTime() + 0.2 end
if CodexQuest.updateQuestLog == true then
CodexQuest:UpdateQuestLog()
CodexQuest.updateQuestLog = false
end
if CodexQuest.updateQuestGivers == true then
-- If config trackingmethod == 4 then return end
local meta = {["addon"] = "CODEX"}
CodexDatabase:SearchQuests(meta)
CodexMap:UpdateNodes()
CodexQuest.updateQuestGivers = false
end
-- if config trackingmethod == 4 then return end
if table.getn(CodexQuest.queue) == 0 and not CodexQuest.queueEmptied then
return
elseif table.getn(CodexQuest.queue) == 0 and CodexQuest.queueEmptied then
CodexQuest.queueEmptied = false
CodexMap:UpdateNodes()
return
end
-- process queue
local match = false
for id, entry in pairs(CodexQuest.queue) do
match = true
-- if CodexConfig["trackingmethod"] ~= 3 and (CodexConfig["trackingmethod"] ~= 2 or IsQuestWatched(entry[3])) then
if true and (true or IsQuestWatched(entry[3])) then
CodexMap:DeleteNode("CODEX", entry[1])
local meta = {["addon"] = "CODEX", ["questLogId"] = entry[3]}
for _, id in pairs(entry[2]) do
CodexDatabase:SearchQuestById(id, meta)
end
end
CodexQuest.queue[id] = nil
if table.getn(CodexQuest.queue) == 0 then
CodexQuest.queueEmptied = true
end
return
end
-- trigger questgiver update
if match == false then
CodexQuest.updateQuestGivers = true
CodexQuest.queue = {}
end
end)
function CodexQuest:UpdateQuestLog()
CodexQuest.questLogTemp = {}
local _, numQuests = GetNumQuestLogEntries()
local found = 0
-- iterate over all quests
for questLogId = 1, 40 do
local title, _, _, header, _, complete = GetQuestLogTitle(questLogId)
local objectives = GetNumQuestLeaderBoards(questLogId)
local watched = IsQuestWatched(questLogId)
if title and not header then
-- add new quest to the quest log
if not CodexQuest.questLog[title] then
local questId = CodexDatabase:GetQuestIds(questLogId)
CodexQuest.questLogTemp[title] = {ids = questId, questLogId = questLogId, state = "init"}
elseif CodexQuest.questLog[title].questLogId ~= questLogId then
CodexQuest.questLogTemp[title] = {ids = CodexQuest.questLog[title].ids, questLogId = questLogId, state = CodexQuest.questLog[title].state}
else
CodexQuest.questLogTemp[title] = {ids = CodexQuest.questLog[title].ids, questLogId = CodexQuest.questLog[title].questLogId, state = CodexQuest.questLog[title].state}
end
-- update progress state
if objectives then
local state = watched and "trck" or ""
for i=1, objectives do
local text, _, done = GetQuestLogLeaderBoard(i, questLogId)
local _, _, obj, objNum, objNeeded = strfind(text, "(.*):%s*([%d]+)%s*/%s*([%d]+)")
if obj then
state = state .. i .. (((objNum + 0 >= objNeeded + 0) or done) and "done" or "todo")
end
end
CodexQuest.questLogTemp[title].state = state
end
found = found + 1
if found >= numQuests then
break
end
end
end
-- quest add events
for title, data in pairs(CodexQuest.questLogTemp) do
if not CodexQuest.questLog[title] then
table.insert(CodexQuest.queue, {title, data.ids, data.questLogId})
elseif CodexQuest.questLogTemp[title].state ~= CodexQuest.questLog[title].state then
table.insert(CodexQuest.queue, {title, data.ids, data.questLogId})
end
end
-- quest removal events
for title, data in pairs(CodexQuest.questLog) do
if not CodexQuest.questLogTemp[title] then
CodexMap:DeleteNode("CODEX", title)
CodexMap:UpdateNodes()
for _, questId in pairs(CodexQuest.questLog[title].ids) do
-- Add to history
if title == CodexQuest.abandon then
CodexHistory[questId] = nil
else
CodexHistory[questId] = true
end
end
CodexQuest.abandon = ""
CodexQuest.updateQuestGivers = true
end
end
-- set new questlog
CodexQuest.questLog = CodexQuest.questLogTemp
end
-- Force reset
function CodexQuest:ResetAll()
CodexMap.DeleteNode("CODEX")
CodexQuest.questLog = {}
CodexQuest.updateQuestLog = true
CodexQuest.updateQuestGivers = true
CodexMap.UpdateNodes()
end
function CodexQuest:AddQuestLogIntegration()
local dockFrame = QuestLogDetailScrollChildFrame
local dockTitle = QuestLogDescriptionTitle
dockTitle:SetHeight(dockTitle:GetHeight() + 30)
dockTitle:SetJustifyV("BOTTOM")
CodexQuest.buttonShow = CodexQuest.buttonShow or CreateFrame("Button", "CodexQuestShow", dockFrame, "UIPanelButtonTemplate")
CodexQuest.buttonShow:SetWidth(70)
CodexQuest.buttonShow:SetHeight(20)
CodexQuest.buttonShow:SetText("Show")
CodexQuest.buttonShow:SetPoint("TOP", dockTitle, "TOP", -110, 0)
CodexQuest.buttonShow:SetScript("OnClick", function()
-- CodexQuest:ResetAll()
local questIndex = GetQuestLogSelection()
local title, _, _, header, _, complete = GetQuestLogTitle(questIndex)
if header then return end
local ids = CodexQuest.questLog[title].ids
local maps, meta = {}, {["addon"] = "CODEX", ["questLogId"] = questIndex}
for _, id in pairs(ids) do
maps = CodexDatabase:SearchQuestById(id, meta, maps)
end
CodexMap:ShowMapId(CodexDatabase:GetBestMap(maps))
end)
CodexQuest.buttonHide = CodexQuest.buttonHide or CreateFrame("Button", "CodexQuestHide", dockFrame, "UIPanelButtonTemplate")
CodexQuest.buttonHide:SetWidth(70)
CodexQuest.buttonHide:SetHeight(20)
CodexQuest.buttonHide:SetText("Hide")
CodexQuest.buttonHide:SetPoint("TOP", dockTitle, "TOP", -37, 0)
CodexQuest.buttonHide:SetScript("OnClick", function()
local questIndex = GetQuestLogSelection()
local title, _, _, header, _, complete = GetQuestLogTitle(questIndex)
if header then return end
CodexMap:DeleteNode("CODEX", title)
CodexMap:UpdateNodes()
end)
-- CodexQuest.buttonClean = CodexQuest.buttonClean or CreateFrame("Button", "CodexQuestClean", dockFrame, "UIPanelButtonTemplate")
-- CodexQuest.buttonClean:SetWidth(70)
-- CodexQuest.buttonClean:SetHeight(20)
-- CodexQuest.buttonClean:SetText("Clean")
-- CodexQuest.buttonClean:SetPoint("TOP", dockTitle, "TOP", 37, 0)
-- CodexQuest.buttonClean:SetScript("OnClick", function()
-- CodexMap:DeleteNode("CODEX")
-- CodexMap:UpdateNodes()
-- end)
CodexQuest.buttonReset = CodexQuest.buttonReset or CreateFrame("Button", "CodexQuestReset", dockFrame, "UIPanelButtonTemplate")
CodexQuest.buttonReset:SetWidth(70)
CodexQuest.buttonReset:SetHeight(20)
CodexQuest.buttonReset:SetText("Reset")
CodexQuest.buttonReset:SetPoint("TOP", dockTitle, "TOP", 37, 0)
CodexQuest.buttonReset:SetScript("OnClick", function()
CodexQuest:ResetAll()
end)
end
function CodexQuest:CheckNamePlate()
local something = WorldFrame:GetNumChildren()
local index = 1
local plateList = {}
for index = 1, something do
local frame = select(index, WorldFrame:GetChildren())
if frame:GetName() and frame:GetName():find("NamePlate%d") and not frame.skinned then
frame.skinned = 1
frame.icon = CreateFrame("Frame", nil, frame)
frame.icon:SetFrameStrata("HIGH")
frame.icon:SetWidth(25)
frame.icon:SetHeight(25)
local texture = frame.icon:CreateTexture(nil, "HIGH")
texture:SetTexture("Interface\\Addons\\ClassicCodex\\img\\pickup.tga")
texture:SetAllPoints(frame.icon)
frame.icon.texture = texture
frame.icon:SetPoint("BOTTOM", frame, "TOP", 0, 0)
end
if frame["UnitFrame"] and frame["UnitFrame"]["displayedUnit"] then
local name = frame["UnitFrame"]["name"]:GetText()
frame.icon:Hide()
for title in pairs(CodexQuest.questLog) do
if name and CodexMap.tooltips[name] and CodexMap.tooltips[name][title] then
frame.icon:Show()
break
else
frame.icon:Hide()
end
end
end
end
end
-- [[ Hook UI Functions ]] --
-- Set certain events on quest watch
local CodexHookRemoveQuestWatch = RemoveQuestWatch
RemoveQuestWatch = function(questIndex)
local ret = CodexHookRemoveQuestWatch(questIndex)
local title, _, _, header, _, complete = GetQuestLogTitle(questIndex)
CodexMap:DeleteNode("CODEX", title)
CodexQuest.updateQuestLog = true
CodexQuest.updateQuestGivers = true
return ret
end
local CodexHookAddQuestWatch = AddQuestWatch
AddQuestWatch = function(questIndex)
local ret = CodexHookAddQuestWatch(questIndex)
CodexQuest.updateQuestLog = true
CodexQuest.updateQuestGivers = true
return re
end
local CodexHookAbandonQuest = AbandonQuest
AbandonQuest = function()
CodexQuest.abandon = GetAbandonQuestName()
CodexHookAbandonQuest()
end