-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvent.lua
493 lines (444 loc) · 17.8 KB
/
Event.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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
local _G = _G
local L = LibStub("AceLocale-3.0"):GetLocale("APR-Recorder")
AprRC.event = AprRC:NewModule("AprRC-Event")
-- global event framePool for register
AprRC.event.framePool = {}
AprRC.event.functions = {}
---------------------------------------------------------------------------------------
------------------------------------- EVENTS ------------------------------------------
---------------------------------------------------------------------------------------
local events = {
load = "ADDON_LOADED",
accept = "QUEST_ACCEPTED",
remove = "QUEST_REMOVED",
done = "QUEST_TURNED_IN",
gossip = "GOSSIP_SHOW",
setHS = "HEARTHSTONE_BOUND",
spell = "UNIT_SPELLCAST_SUCCEEDED",
raidIcon = "RAID_TARGET_UPDATE",
pet = { "PET_BATTLE_CLOSE", "PET_BATTLE_OPENING_START" },
emote = "CHAT_MSG_TEXT_EMOTE",
taxi = { "TAXIMAP_OPENED", "TAXIMAP_CLOSED" },
fly = { "PLAYER_CONTROL_LOST", "PLAYER_CONTROL_GAINED" },
buy = "MERCHANT_SHOW",
qpart = "QUEST_WATCH_UPDATE"
-- warMode = "WAR_MODE_STATUS_UPDATE",
-- vehicle = { "UNIT_ENTERING_VEHICLE", "UNIT_EXITING_VEHICLE" },
}
---------------------------------------------------------------------------------------
-------------------------------------- DATA -------------------------------------------
---------------------------------------------------------------------------------------
local boatsNodeID = { 2052, 2053, 2054, 2055, 2056, 2057, 2104, 2105 }
local chromieTimelineSpellID = {
[325400] = { name = "TheBurningCrusade", optionID = 6 },
[325042] = { name = "WrathOfTheLichKing", optionID = 7 },
[325537] = { name = "Cataclysm", optionID = 5 },
[325530] = { name = "MistsOfPandaria", optionID = 8 },
[325534] = { name = "WarlordsOfDraenor", optionID = 9 },
[325539] = { name = "Legion", optionID = 10 },
[420123] = { name = "BattleForAzeroth", optionID = 15 },
[397733] = { name = "Shadowlands", optionID = 14 }
-- Dragonflight
}
local controlLostTime = 0
---------------------------------------------------------------------------------------
---------------------------------- Events register ------------------------------------
---------------------------------------------------------------------------------------
function AprRC.event:MyRegisterEvent()
for tag, event in pairs(events) do
local container = self.framePool[tag] or CreateFrame("Frame")
container.tag = tag
container.callback = self.functions[tag]
if type(event) == "string" then
container:RegisterEvent(event)
container:SetScript("OnEvent", self.EventHandler)
elseif type(event) == "table" then
for _, e in ipairs(event) do
container:RegisterEvent(e)
container:SetScript("OnEvent", self.EventHandler)
end
end
end
end
function AprRC.event.EventHandler(self, event, ...)
if not AprRC.settings.profile.enableAddon or not AprRC.settings.profile.recordBarFrame.isRecording then
return
end
if self.callback and self.tag then
AprRC:Debug("Callback Event", event)
pcall(self.callback, event, ...)
else
AprRC:Debug("Unregister Event", event)
self.callback = nil
self:UnregisterEvent(event)
end
end
---------------------------------------------------------------------------------------
---------------------------------- Events always sub ----------------------------------
---------------------------------------------------------------------------------------
local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent(events.load)
eventFrame:SetScript("OnEvent", function(self, event, ...)
if event == events.load then
local addOnName, containsBindings = ...
if addOnName == "APR-Recorder" then
if ExtraActionButton1 and not ExtraActionButton1.isHookedAprRC then
ExtraActionButton1:HookScript("OnClick", function()
if not AprRC.settings.profile.enableAddon or not AprRC.settings.profile.recordBarFrame.isRecording then
return
end
local currentStep = AprRC:GetLastStep()
currentStep.ExtraActionB = 1
end)
ExtraActionButton1.isHookedAprRC = true
end
end
end
end)
---------------------------------------------------------------------------------------
---------------------------------- Events Functions -----------------------------------
---------------------------------------------------------------------------------------
function AprRC.event.functions.accept(event, questId)
-- Pickup
if AprRC:HasStepOption("ChromiePick") then
local currentStep = AprRC:GetLastStep()
currentStep.PickUp = { questId }
return
end
if not AprRC:IsCurrentStepFarAway() and AprRC:HasStepOption("PickUp") then
local currentStep = AprRC:GetLastStep()
tinsert(currentStep["PickUp"], questId)
else
local step = { PickUp = { questId } }
AprRC:SetStepCoord(step)
AprRC:NewStep(step)
end
-- update saved quest
AprRC:saveQuestInfo()
end
function AprRC.event.functions.remove(event, questId, ...)
-- LeaveQuests
if not C_QuestLog.IsQuestFlaggedCompleted(questId) then
if AprRC:HasStepOption("LeaveQuests") then
local currentStep = AprRC:GetLastStep()
tinsert(currentStep["LeaveQuests"], questId)
else
local step = { LeaveQuests = { questId } }
AprRC:NewStep(step)
end
--remove quest from state list
AprRC.lastQuestState[questId] = nil
end
end
function AprRC.event.functions.done(event, questId, ...)
if not AprRC:IsCurrentStepFarAway() and AprRC:HasStepOption("Done") then
local currentStep = AprRC:GetLastStep()
tinsert(currentStep["Done"], questId)
else
local step = { Done = { questId } }
AprRC:SetStepCoord(step)
AprRC:NewStep(step)
end
--remove quest from state list
AprRC.lastQuestState[questId] = nil
end
function AprRC.event.functions.raidIcon(...)
local targetId = _G.GetTargetID()
if targetId then
local currentStep = AprRC:GetLastStep()
currentStep.RaidIcon = targetId
end
end
function AprRC.event.functions.setHS(...)
local step = { SetHS = AprRC:FindClosestIncompleteQuest() }
AprRC:SetStepCoord(step)
AprRC:NewStep(step)
end
function AprRC.event.functions.spell(event, unitTarget, castGUID, spellID)
local key = nil
if unitTarget == "player" then
if spellID == APR.dalaHSSpellID then
key = "UseDalaHS"
elseif spellID == APR.garrisonHSSpellID then
key = "UseGarrisonHS"
elseif AprRC:Contains(APR.hearthStoneSpellID, spellID) then
key = "UseHS"
elseif spellID == 126389 then
local currentStep = AprRC:GetLastStep()
currentStep.UseGlider = 1
return
elseif chromieTimelineSpellID[spellID] then
local step = {}
step.ChromiePick = chromieTimelineSpellID[spellID].optionID
step.GossipOptionIDs = { 51901, 51902 }
AprRC:SetStepCoord(step)
AprRC:NewStep(step)
return
end
if key then
local step = {}
step[key] = AprRC:FindClosestIncompleteQuest()
AprRC:NewStep(step)
end
end
end
function AprRC.event.functions.warMode(event, warModeEnabled)
if warModeEnabled then
local step = { WarMode = AprRC:FindClosestIncompleteQuest() }
AprRC:NewStep(step)
end
end
function AprRC.event.functions.vehicle(event, ...)
if event == "UNIT_EXITING_VEHICLE" then
if not AprRC:HasStepOption("VehicleExit") then
local currentStep = AprRC:GetLastStep()
currentStep["VehicleExit"] = 1
end
end
end
local function SetGossipOptionID(self)
local gossipInfo = self:GetData().info
local gossipIcon = gossipInfo.icon
local gossipOptionID = gossipInfo.gossipOptionID
if gossipIcon == 132053 and not AprRC:Contains({ 51901, 51902 }, gossipOptionID) then --bubble icon and not chromie select timeline
if not AprRC:IsCurrentStepFarAway() then
local currentStep = AprRC:GetLastStep()
if AprRC:HasStepOption("GossipOptionIDs") then
tinsert(currentStep["GossipOptionIDs"], gossipOptionID)
else
currentStep["GossipOptionIDs"] = { gossipOptionID }
end
else
local step = { GossipOptionIDs = { gossipOptionID } }
AprRC:SetStepCoord(step)
AprRC:NewStep(step)
end
end
end
function AprRC.event.functions.gossip(event, ...)
local childs = { GossipFrame.GreetingPanel.ScrollBox.ScrollTarget:GetChildren() }
for k, child in ipairs(childs) do
local data = child.GetData and child:GetData()
if data and data.info and data.info.gossipOptionID then
if not child.hookedGossipExtraction then
child:HookScript("OnClick", SetGossipOptionID)
child.hookedGossipExtraction = true
end
end
end
end
function AprRC.event.functions.emote(event, ...)
local message, sender = ...
if APR.Username == sender then
local function getEmoteKey()
for emoteKey, phrases in pairs(L.Emotes) do
for _, phrase in ipairs(phrases) do
local pattern = phrase:gsub("%%s", ".+") -- replace placeholders patern to lua
pattern = "^" .. pattern .. "$" -- cast as regex
if string.match(message, pattern) then
return emoteKey
end
end
end
return nil
end
local emote = getEmoteKey()
if emote then
local currentStep = AprRC:GetLastStep()
if not AprRC:IsCurrentStepFarAway() and AprRC:HasStepOption("Emote") then
currentStep["Emote"] = emote
else
local step = { Emote = emote }
AprRC:SetStepCoord(step)
AprRC:NewStep(step)
end
end
end
end
function AprRC.event.functions.taxi(event, ...)
if event == "TAXIMAP_OPENED" then
local playerMapID = C_Map.GetBestMapForUnit("player")
local taxiNodes = C_TaxiMap.GetAllTaxiNodes(playerMapID)
for _, node in ipairs(taxiNodes) do
if node.state == Enum.FlightPathState.Current then
AprRC.CurrentTaxiNode = node
end
end
elseif event == "TAXIMAP_CLOSED" then
C_Timer.After(2, function()
if AprRC.CurrentTaxiNode and not UnitOnTaxi("player") then
local step = {}
step.GetFP = AprRC.CurrentTaxiNode.nodeID
AprRC:SetStepCoord(step)
AprRC:NewStep(step)
end
end)
end
end
function AprRC.event.functions.fly(event, ...)
if event == "PLAYER_CONTROL_LOST" then
C_Timer.After(2, function()
if UnitOnTaxi("player") then
AprRC.isOnTaxi = true
controlLostTime = GetTime()
local step = {}
step.UseFlightPath = AprRC:FindClosestIncompleteQuest()
AprRC:SetStepCoord(step)
AprRC:NewStep(step)
end
end)
elseif event == "PLAYER_CONTROL_GAINED" then
if AprRC.isOnTaxi then
local currentStep = AprRC:GetLastStep()
-- ETA
local controlGainTime = GetTime()
local duration = math.floor(controlGainTime - controlLostTime)
currentStep.ETA = duration
--NodeID
local posY, posX = UnitPosition("player")
local taxiNodeId, taxiName, taxiX, taxiY = APR.transport:ClosestTaxi(posX, posY)
currentStep.NodeID = taxiNodeId
--Boat
if AprRC:Contains(boatsNodeID, AprRC.CurrentTaxiNode) then
currentStep.Boat = 1
end
-- reset
AprRC.isOnTaxi = false
controlLostTime = 0
AprRC.CurrentTaxiNode = nill
end
end
end
function AprRC.event.functions.buy(event, ...)
local numItems = GetMerchantNumItems()
for i = 1, numItems do
local button = _G["MerchantItem" .. i .. "ItemButton"]
if button and not button.isHooked then
button:HookScript("OnClick", function(self)
local itemID = GetMerchantItemID(i)
if itemID then
local step = {}
step.BuyMerchant = itemID
AprRC:SetStepCoord(step)
AprRC:NewStep(step)
end
end)
button.isHooked = true
end
end
end
function AprRC.event.functions.qpart(event, questID)
local function setButton(questID, index, step)
-- itemID
local questLogIndex = C_QuestLog.GetLogIndexForQuestID(questID)
local link = GetQuestLogSpecialItemInfo(questLogIndex)
if link then
local itemID = AprRC:GetItemIDFromLink(link)
if not step.Button then
step.Button = {}
end
step.Button[questID .. "-" .. index] = itemID
end
end
local function setQpart(lastState, objective, questID, index)
if lastState.numFulfilled < objective.numFulfilled then
local currentStep = AprRC:GetLastStep()
--
if (currentStep.Qpart and currentStep.Qpart[questID] and currentStep.Qpart[questID][index]) or AprRC:IsQuestInLookup(questID, index) then
-- update
AprRC.lastQuestState[questID][index] = { numFulfilled = objective.numFulfilled }
return
end
local range = (objective.type == "monster" or objective.type == "item") and 30 or 5
local function newStep()
local step = {}
step.Qpart = {}
step.Qpart[questID] = { index }
if AprRC:IsInInstanceQuest() then
step.InstanceQuest = true
end
setButton(questID, index, step)
AprRC:SetStepCoord(step, range)
AprRC:NewStep(step)
end
if AprRC:HasStepOption("PickUp")
or AprRC:HasStepOption("Done")
or AprRC:HasStepOption("LeaveQuests")
or AprRC:HasStepOption("GetFP")
or AprRC:HasStepOption("setHS")
or AprRC:HasStepOption("Waypoint") then
newStep()
else
if not AprRC:IsCurrentStepFarAway() then
if not AprRC:HasStepOption("Qpart") then
currentStep.Qpart = {}
currentStep.Qpart[questID] = {}
if not AprRC:HasStepOption("Coord") then
AprRC:SetStepCoord(currentStep, range)
end
if AprRC:IsInInstanceQuest() then
currentStep.InstanceQuest = true
end
setButton(questID, index, currentStep)
elseif not currentStep.Qpart[questID] then
currentStep.Qpart[questID] = {}
end
tinsert(currentStep.Qpart[questID], index)
else
newStep()
end
end
-- update
AprRC.lastQuestState[questID][index] = { numFulfilled = objective.numFulfilled }
AprRC:AddQuestToLookup(questID, index)
end
end
C_Timer.After(2, function()
local objectives = C_QuestLog.GetQuestObjectives(questID)
for index, objective in ipairs(objectives) do
local lastState = AprRC.lastQuestState[questID] and AprRC.lastQuestState[questID][index]
if lastState then
setQpart(lastState, objective, questID, index)
else
-- save if not existing
AprRC.lastQuestState[questID] = AprRC.lastQuestState[questID] or {}
AprRC.lastQuestState[questID][index] = { numFulfilled = objective.numFulfilled }
local lastState = AprRC.lastQuestState[questID] and AprRC.lastQuestState[questID][index]
setQpart(lastState, objective, questID, index)
end
end
end)
end
function AprRC.event.functions.pet(event, ...)
AprRC.record:RefreshFrameAnchor()
end
---------------------
-- V2
---------------------
-- - Button / SpellButton / Achievement (autoComplete)
-- Check how
-- - DroppableQuest = { Text = "Tideblood", Qid = 50593, MobId = 130116 },
-- - DropQuest ["DropQuest"] = 62567 (questID)
-- - Treasure ["Treasure"] = 31401 (questID)
-- sur l'action d'un DB check si y a la quest ID dans un PickUpDB et l'ajouter automatiquemejnt
-- - QpartDB
-- - DoneDB ["DoneDB"] = { questID1, questID2}
-- si on get une nouvelle quete ou actualise une quete -> info = C_QuestLog.GetInfo(questLogIndex); info.suggestedGroup
-- - Group ["Group"] = { Number = 3, QuestId = 51384},
-- - GroupTask ["GroupTask"] = 51384, (the questId from Group, step to check if player want to do the group quest)
-- - QuestLineSkip ???? (block group quest if present) ["QuestLineSkip"] = 51226,
-- - QpartPart (rework ?)
-- - TrigText (rework ?)
---------------------
-- V3 - maybe
---------------------
-- - DoIHaveFlight ?? check si on peut en faire quelque chose pour des waypoints (avec ajout unAutoSkipableWaypoint)
-- - NoAutoFlightMap
-- - PickedLoa
-- - SpecialETAHide ??
-- - Bloodlust
-- - Dontskipvid
-- - DenyNPC
-- - ExitTutorial ["ExitTutorial"] = 62567 (IsOnQuest(questID)
-------------------------------
-- AprRC.EventFrame:RegisterEvent("CONFIRM_XP_LOSS") -- deathskip ??