This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEvents.lua
640 lines (601 loc) · 26.1 KB
/
Events.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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
--[[--
@module MyDungeonsBook
]]
--[[--
Event Handlers
@section EventHandlers
]]
local L = LibStub("AceLocale-3.0"):GetLocale("MyDungeonsBook");
--[[--
Check combat events while player is in challenge.
It's triggered only when challenge is active.
]]
function MyDungeonsBook:COMBAT_LOG_EVENT_UNFILTERED()
if (not self.db.char.activeChallengeId) then
return;
end
local timestamp, subEventName, hideCaster, srcGUID, srcName, srcFlags, srcFlags2, dstGUID, dstName, dstFlags, dstFlags2 = CombatLogGetCurrentEventInfo();
local subEventPrefix, subEventSuffix = subEventName:match("^(.-)_?([^_]*)$");
self:TrackEnemyUnitAppearsInCombat(srcName, srcGUID, srcFlags, dstName, dstGUID, dstFlags);
self:TrackUnitsAppearsInCombatWrapper(srcGUID, dstGUID); -- TODO remove later
if (subEventSuffix == "SUMMON" or
subEventSuffix == "CREATE") then
self:TrackSummonnedByPartyMembersUnit(srcName, srcGUID, dstName, dstGUID);
end
if (subEventName == "UNIT_DIED") then
self:TrackDeath(timestamp, dstName, dstGUID);
self:TrackSummonByPartyMemberUnitDeath(dstName, dstGUID);
self:TrackEnemyUnitDied(dstName, dstGUID, dstFlags);
self:RemoveAurasFromPartyMember(dstName, dstGUID);
self:SaveDeathLogsForPartyMember(timestamp, dstName);
end
if (subEventName == "UNIT_DESTROYED") then
self:TrackSummonByPartyMemberUnitDeath(dstName, dstGUID);
end
if (subEventSuffix == "HEAL") then
local spellId, _, _, amount, overheal, _, crit = select(12, CombatLogGetCurrentEventInfo());
self:TrackAllHealDoneByPartyMembersToEachOther(srcName, srcGUID, dstName, dstGUID, spellId, amount, overheal);
self:TrackAllHealDoneByEnemiesToEachOther(srcName, srcGUID, srcFlags, dstName, dstGUID, dstFlags, spellId, amount, overheal, crit);
self:TrackAllHealBySpellDoneByPartyMembers(srcName, srcGUID, srcFlags, dstName, dstGUID, dstFlags, spellId, amount, overheal, crit);
self:TrackCombatEventWithPartyMember(timestamp, dstName, dstGUID);
end
if (subEventName == "DAMAGE_SPLIT" or
subEventName == "DAMAGE_SHIELD") then
local spellId, _, _, amount, overheal = select(12, CombatLogGetCurrentEventInfo());
self:TrackAllHealDoneByPartyMembersToEachOther(srcName, srcGUID, dstName, dstGUID, spellId, amount, overheal);
self:TrackAllHealDoneByEnemiesToEachOther(srcName, srcGUID, srcFlags, dstName, dstGUID, dstFlags, spellId, amount, overheal, false);
self:TrackAllHealBySpellDoneByPartyMembers(srcName, srcGUID, srcFlags, dstName, dstGUID, dstFlags, spellId, amount, overheal, false);
self:TrackCombatEventWithPartyMember(timestamp, dstName, dstGUID);
end
if (subEventName == "SPELL_ABSORBED") then
local unitGUID, unitName, unitFlags, _, spellId, _, _, amount = select(12, CombatLogGetCurrentEventInfo());
local N22 = select(22, CombatLogGetCurrentEventInfo());
if (N22 ~= nil) then
unitGUID, unitName, unitFlags, _, spellId, _, _, amount = select(15, CombatLogGetCurrentEventInfo());
end
self:TrackAllHealDoneByPartyMembersToEachOther(unitName, unitGUID, dstName, dstGUID, spellId, amount, -1);
self:TrackAllHealDoneByEnemiesToEachOther(srcName, srcGUID, srcFlags, dstName, dstGUID, dstFlags, spellId, amount, -1, false);
self:TrackAllHealBySpellDoneByPartyMembers(unitName, unitGUID, unitFlags, dstName, dstGUID, dstFlags, spellId, amount, -1, false);
self:TrackCombatEventWithPartyMember(timestamp, dstName, dstGUID);
end
if (subEventSuffix == "INTERRUPT") then
local spellId, _, _, extraSpellId = select(12, CombatLogGetCurrentEventInfo());
self:TrackInterrupt(srcName, srcGUID, spellId, extraSpellId, dstFlags2);
end
if (subEventSuffix == "DISPEL" or
subEventName == "SPELL_STOLEN") then
local spellId, _, _, extraSpellId = select(12, CombatLogGetCurrentEventInfo());
self:TrackDispel(srcName, srcGUID, spellId, extraSpellId, dstFlags2);
self:TrackCombatEventWithPartyMember(timestamp, dstName, dstGUID);
end
if (subEventName == "SPELL_CAST_SUCCESS") then
local spellId = select(12, CombatLogGetCurrentEventInfo());
self:TrackTryInterrupt(srcName, srcGUID, spellId);
self:TrackPassedCastsWrapper(srcName, spellId, srcFlags2);
self:TrackAllEnemiesPassedCasts(srcName, srcGUID, srcFlags, spellId);
self:TrackSpellsCaster(srcName, srcGUID, spellId);
self:TrackSpecificCastDoneByPartyMembersWrapper(srcName, spellId);
self:TrackAllCastsDoneByPartyMembers(srcName, srcGUID, spellId);
self:TrackSpecificItemUsedByPartyMembersWrapper(srcName, spellId);
self:TrackOwnCastDoneByPartyMembers(timestamp, srcName, spellId, dstName, dstGUID);
end
if ((subEventPrefix:match("^SPELL") or subEventPrefix:match("^RANGE")) and subEventSuffix == "DAMAGE") then
local spellId, _, _, amount, overkill, _, _, _, _, crit = select(12, CombatLogGetCurrentEventInfo());
if (not srcName or not srcGUID) then
srcName = L["Environment"];
srcFlags = 64; -- Just an enemy
end
self:TrackAllDamageDoneToPartyMembers(srcName, dstName, srcGUID, srcFlags, spellId, amount);
self:TrackAllEnemiesFriendlyFire(srcName, srcGUID, srcFlags, dstName, dstGUID, dstFlags);
self:TrackAllDamageDoneByPartyMembers(srcName, srcGUID, srcFlags, dstName, dstGUID, dstFlags, spellId, amount, overkill, crit);
self:TrackDamageDoneToSpecificUnitsWrapper(srcName, srcGUID, spellId, amount, overkill, dstName, dstGUID);
self:TrackCombatEventWithPartyMember(timestamp, dstName, dstGUID);
end
if (subEventName == "SWING_DAMAGE") then
local amount, overkill, _, _, _, _, crit = select(12, CombatLogGetCurrentEventInfo());
self:TrackAllDamageDoneToPartyMembers(srcName, dstName, srcGUID, srcFlags, -2, amount);
self:TrackAllDamageDoneByPartyMembers(srcName, srcGUID, srcFlags, dstName, dstGUID, dstFlags, -2, amount, overkill, crit);
self:TrackDamageDoneToSpecificUnitsWrapper(srcName, srcGUID, -2, amount, overkill, dstName, dstGUID);
self:TrackCombatEventWithPartyMember(timestamp, dstName, dstGUID);
end
if (subEventName == "SPELL_EXTRA_ATTACKS") then
local amount = select(12, CombatLogGetCurrentEventInfo());
self:TrackAllDamageDoneToPartyMembers(srcName, dstName, srcGUID, srcFlags, -2, amount);
self:TrackAllDamageDoneByPartyMembers(srcName, srcGUID, srcFlags, dstName, dstGUID, dstFlags, -2, amount, 0, false);
end
if ((subEventPrefix:match("^SPELL") or subEventPrefix:match("^RANGE")) and subEventSuffix == "MISSED") then
local spellId, _, _, _, _, amount = select(12, CombatLogGetCurrentEventInfo());
self:TrackAllDamageDoneToPartyMembers(srcName, dstName, srcGUID, srcFlags, spellId, amount);
self:TrackAllDamageDoneByPartyMembers(srcName, srcGUID, srcFlags, dstName, dstGUID, dstFlags, spellId, amount, 0, false);
end
if (subEventName == "SPELL_AURA_APPLIED" or
subEventName == "SPELL_AURA_APPLIED_DOSE") then
local spellId, _, _, auraType, amount = select(12, CombatLogGetCurrentEventInfo());
self:TrackSpecificBuffOrDebuffOnPartyMembersWrapper(dstName, spellId);
self:TrackSpecificBuffOrDebuffOnUnit(dstName, dstGUID, dstFlags, spellId, auraType, amount or 1);
self:TrackAllBuffOrDebuffOnUnit(dstName, dstGUID, dstFlags, spellId, auraType, amount or 1);
self:TrackAuraAddedToPartyMember(dstName, dstGUID, spellId, auraType, amount or 1);
self:TrackAuraAddedToEnemyUnit(srcName, srcGUID, srcFlags, dstName, dstGUID, dstFlags, spellId, auraType, amount or 1);
self:TrackCombatEventWithPartyMember(timestamp, dstName, dstGUID);
self:TrackDebuffDispelType(dstName, dstGUID);
self:TrackEnemyBuffDispelType(dstGUID);
end
if (subEventName == "SPELL_AURA_REMOVED" or
subEventName == "SPELL_AURA_REMOVED_DOSE" or
subEventName == "SPELL_AURA_BROKEN" or
subEventName == "SPELL_AURA_BROKEN_SPELL") then
local spellId, _, _, auraType, amount = select(12, CombatLogGetCurrentEventInfo());
self:TrackAuraRemovedFromPartyMember(dstName, dstGUID, spellId, auraType, amount or 0);
self:TrackAuraRemovedFromEnemyUnit(dstName, dstGUID, spellId, auraType, amount or 0);
self:TrackSpecificBuffOrDebuffRemovedFromUnit(dstName, dstGUID, dstFlags, spellId, auraType, amount or 0);
self:TrackCombatEventWithPartyMember(timestamp, dstName, dstGUID);
end
if (subEventName == "SPELL_AURA_BROKEN" or
subEventName == "SPELL_AURA_BROKEN_SPELL") then
local brokenSpellId, _, _, spellId = select(12, CombatLogGetCurrentEventInfo());
if (type(spellId) ~= "number") then
spellId = -2; -- Swing Damage
end
self:TrackEnemyAuraBrokenByDamage(timestamp, srcName, srcGUID, srcFlags, dstName, dstGUID, dstFlags, brokenSpellId, spellId);
end
end
--[[--
Save info about started challenge to the db.
Next fields are saved:
* key level
* affixes
* time
* zone name and its id
* map id
* team roster - name, race, class, spec, realm, items
]]
function MyDungeonsBook:CHALLENGE_MODE_START()
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
self:RegisterEvent("PLAYER_REGEN_DISABLED");
self:RegisterEvent("PLAYER_REGEN_ENABLED");
self:RegisterEvent("CHAT_MSG_LOOT");
self:RegisterEvent("UNIT_SPELLCAST_START");
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START");
self:RegisterEvent("CHAT_MSG_RAID_BOSS_EMOTE");
self:RegisterEvent("CHAT_MSG_MONSTER_EMOTE");
self:RegisterEvent("COMBAT_RATING_UPDATE");
self:RegisterEvent("NAME_PLATE_UNIT_ADDED");
self:COMBAT_RATING_UPDATE();
self:DebugPrint("CHALLENGE_MODE_START");
wipe(self.allPartyMemberLogs or {});
if (self.partyAliveStatusCheckTimer) then
self:CancelTimer(self.partyAliveStatusCheckTimer);
end
self.partyAliveStatusCheckTimer = self:ScheduleRepeatingTimer("PartyAliveStatusCheck", 1);
if (self.db.char.activeChallengeId) then
self:DebugPrint(string.format("Challenge already exists with id %s", self.db.char.activeChallengeId));
return;
end
local startTimestamp = time();
local id = startTimestamp;
self:InitNewDungeonChallenge(id);
self.db.char.activeChallengeId = id;
local _, _, _, _, _, _, _, currentZoneId = GetInstanceInfo();
self:DebugPrint(string.format("currentZoneId is %s", currentZoneId));
local cmLevel, affixes = C_ChallengeMode.GetActiveKeystoneInfo();
self:DebugPrint(string.format("cmLevel is %s", cmLevel));
local currentMapId = C_ChallengeMode.GetActiveChallengeMapID();
self:DebugPrint(string.format("currentMapId is %s", currentMapId));
local _, _, steps = C_Scenario.GetStepInfo();
local zoneName, _, maxTime = C_ChallengeMode.GetMapUIInfo(currentMapId);
self:DebugPrint(string.format("zoneName is %s", zoneName));
self:DebugPrint(string.format("maxTime is %s", maxTime));
local affixIds = {};
for _, affixId in pairs(affixes) do
table.insert(affixIds, affixId);
end
local affixesKey = "affixes";
for _, k in ipairs(affixIds) do
affixesKey = string.format("%s-%s", affixesKey, k);
end
self:DebugPrint(string.format("affixesKey is %s", affixesKey));
self.db.char.challenges[id].players.player = self:ParseUnitInfoWithWowApi("player");
local playersRealm = self.db.char.challenges[id].players.player.realm;
for _, unitId in pairs(self:GetPartyRoster()) do
self:UpdateUnitInfo(UnitGUID(unitId)); -- must be done first!
local name, nameAndRealm = self:GetNameByPartyUnit(id, unitId);
local nameToUse = name;
if (playersRealm ~= self.db.char.challenges[id].players[unitId].realm) then
nameToUse = nameAndRealm;
end
self:AddAurasToPartyMember(nameToUse, unitId);
local petUnitId = unitId .. "pet";
if (UnitExists(petUnitId)) then
self:TrackSummonnedByPartyMembersUnit(nameToUse, UnitGUID(unitId), UnitName(petUnitId), UnitGUID(petUnitId));
end
end
self:NotifyUpdateGroupInfo();
local version, build, date, tocversion = GetBuildInfo();
self:DebugPrint(string.format("version - %s, build - %s, date - %s, tocversion - %s", version, build, date, tocversion));
self.db.char.challenges[id].gameInfo = {
version = version,
build = build,
date = date,
tocversion = tocversion
};
local damageMod, healthMod = C_ChallengeMode.GetPowerLevelDamageHealthMod(cmLevel);
self:DebugPrint(string.format("damageMod - %s%%, healthMod - %s%%", damageMod, healthMod));
self.db.char.challenges[id].challengeInfo = {
cmLevel = cmLevel,
levelKey = "l" .. cmLevel,
affixes = affixes,
affixesKey = affixesKey,
zoneName = zoneName,
currentZoneId = currentZoneId,
currentMapId = currentMapId,
maxTime = maxTime,
steps = steps,
startTime = startTimestamp,
damageMod = damageMod,
healthMod = healthMod,
numDeaths = 0,
neededEnemyForces = self:GetNeededEnemyForcesForActiveChallenge()
};
if (self.challengesTable) then
self.challengesTable:SetData(self:ChallengesFrame_GetDataForTable());
end
self:LogPrint(string.format(L["%s +%s is started"], zoneName, cmLevel));
end
--[[--
Mark active challenge as completed.
]]
function MyDungeonsBook:CHALLENGE_MODE_RESET()
self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
self:UnregisterEvent("PLAYER_REGEN_DISABLED");
self:UnregisterEvent("PLAYER_REGEN_ENABLED");
self:UnregisterEvent("CHAT_MSG_LOOT");
self:UnregisterEvent("UNIT_SPELLCAST_START");
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_START");
self:UnregisterEvent("CHAT_MSG_RAID_BOSS_EMOTE");
self:UnregisterEvent("CHAT_MSG_MONSTER_EMOTE");
self:UnregisterEvent("COMBAT_RATING_UPDATE");
self:UnregisterEvent("NAME_PLATE_UNIT_ADDED");
if (self.partyAliveStatusCheckTimer) then
self:CancelTimer(self.partyAliveStatusCheckTimer);
end
local id = self.db.char.activeChallengeId;
if (self.db.char.challenges[id]) then
self.db.char.challenges[id].endTime = time();
self:LogPrint(string.format(L["%s +%s is reset"], self.db.char.challenges[id].challengeInfo.zoneName, self.db.char.challenges[id].challengeInfo.cmLevel));
end
self.db.char.activeChallengeId = nil;
end
--[[--
Mark active challenge as completed and store additional info about it.
Next information is saved:
* Info from Details addon
* time lost by deaths
* key level upgrade
* challenge duration
]]
function MyDungeonsBook:CHALLENGE_MODE_COMPLETED()
self:COMBAT_RATING_UPDATE();
self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
if (self.partyAliveStatusCheckTimer) then
self:CancelTimer(self.partyAliveStatusCheckTimer);
end
local id = self.db.char.activeChallengeId;
if (self.db.char.challenges[id]) then
self.db.char.challenges[id].challengeInfo.endTime = time();
local mapID, level, time, onTime, keystoneUpgradeLevels, practiceRun = C_ChallengeMode.GetCompletionInfo();
local numDeaths, timeLost = C_ChallengeMode.GetDeathCount();
self.db.char.challenges[id].challengeInfo.onTime = onTime;
self.db.char.challenges[id].challengeInfo.duration = time;
self.db.char.challenges[id].challengeInfo.keystoneUpgradeLevels = keystoneUpgradeLevels;
self.db.char.challenges[id].challengeInfo.timeLost = timeLost;
self.db.char.challenges[id].challengeInfo.numDeaths = numDeaths;
self:LogPrint(string.format(L["%s +%s is completed"], self.db.char.challenges[id].challengeInfo.zoneName or "", self.db.char.challenges[id].challengeInfo.cmLevel or ""));
if (self.challengesTable) then
self.challengesTable:SetData(self:ChallengesFrame_GetDataForTable());
end
if (self.db.char.challenges[id].mechanics["PARTY-MEMBERS-SUMMON"]) then
wipe(self.db.char.challenges[id].mechanics["PARTY-MEMBERS-SUMMON"]); -- no sense to store hundreds of GUIDs
end
local playersRealm = self.db.char.challenges[id].players.player.realm;
for _, unitId in pairs(self:GetPartyRoster()) do
local name, nameAndRealm = self:GetNameByPartyUnit(id, unitId);
local nameToUse = name;
if (playersRealm ~= self.db.char.challenges[id].players[unitId].realm) then
nameToUse = nameAndRealm;
end
self:RemoveAurasFromPartyMember(nameToUse, UnitGUID(unitId));
end
--[[for i = 1, 4 do
local target = "party" .. i;
self:Message_CharacterData_Send(target);
self:Message_IdleTime_Send(target);
end]]
self:ScheduleTimer(function()
self.db.char.activeChallengeId = nil;
end, 5);
-- must be last!
--[[if (self.db.profile.performance.compress) then
for k, _ in pairs(self.db.char.challenges[id].mechanics) do
self.db.char.challenges[id].mechanics[k] = self:Compress(self.db.char.challenges[id].mechanics[k]);
end
end]]
end
self:UnregisterEvent("PLAYER_REGEN_DISABLED");
self:UnregisterEvent("PLAYER_REGEN_ENABLED");
self:UnregisterEvent("CHAT_MSG_LOOT");
self:UnregisterEvent("UNIT_SPELLCAST_START");
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_START");
self:UnregisterEvent("CHAT_MSG_RAID_BOSS_EMOTE");
self:UnregisterEvent("CHAT_MSG_MONSTER_EMOTE");
self:UnregisterEvent("COMBAT_RATING_UPDATE");
self:UnregisterEvent("NAME_PLATE_UNIT_ADDED");
wipe(self.allPartyMemberLogs or {});
end
--[[--
Reset `activeChallengeId` if player is not in challenge.
]]
function MyDungeonsBook:PLAYER_ENTERING_WORLD()
if (not self:IsInChallengeMode()) then
self.db.char.activeChallengeId = nil;
end
end
--[[--
Parse info about party member if it'ready.
Its request is sent in the `MyDungeonsBook:CHALLENGE_MODE_START`
@param[type=string] _ "INSPECT_READY"
@param[type=GUID] guid
]]
function MyDungeonsBook:INSPECT_READY(_, guid)
self:UpdateUnitInfo(guid);
end
--[[--
Get info for each encounter when it's started.
Encounters have unique IDs, however encounters can be ended not successfully (e.g. boss is not killed and team is dead) and can be restarted.
So, only last try will be saved (typically it should be successful try).
Each encounter has next fields:
* `id` - encounter id
* `name` - encounter name (usually, name of the boss)
* `startTime` - timestamp, when encounter is started
* `deathCountOnStart` - number of deaths when encounter starts
* `endTime` - timestamp, when encounter is ended (it's set in the `MyDungeonsBook:ENCOUNTER_END`)
* `deathCountOnEnd` - number of deaths when encounter ends (it's set in the `MyDungeonsBook:ENCOUNTER_END`)
* `success` - was encounter passed or not (it's set in the `MyDungeonsBook:ENCOUNTER_END`)
@param[type=string] _
@param[type=number] encounterId
@param[type=string] encounterName
]]
function MyDungeonsBook:ENCOUNTER_START(_, encounterId, encounterName, ...)
local id = self.db.char.activeChallengeId;
if (not id) then
return;
end
if (not self.db.char.challenges[id]) then
return;
end
local ts = time();
self.db.char.challenges[id].misc.lastEncounterId = ts;
local enemyForcesProgressMechanic = self:SafeNestedGet(self.db.char.challenges[id].mechanics, "ENEMY-FORCES-PROGRESS");
local enemyForcesOnStart;
if (enemyForcesProgressMechanic) then
enemyForcesOnStart = (enemyForcesProgressMechanic[#enemyForcesProgressMechanic] or {})[2];
end
self.db.char.challenges[id].encounters[ts] = {
id = encounterId,
name = encounterName,
startTime = ts,
deathCountOnStart = C_ChallengeMode.GetDeathCount(),
enemyForcesOnStart = enemyForcesOnStart
};
self:NotifyUpdateGroupInfo();
self:DebugPrint("ENCOUNTER_START", encounterId, encounterName);
end
--[[--
Get additional info (`endTime`, `deathCountOnEnd`, `success`) about each encounter when it's ended.
@param[type=string] _ "ENCOUNTER_END"
@param[type=number] encounterId
@param[type=string] encounterName
@param[type=number] difficultyId
@param[type=number] groupSize
@param[type=?bool] success
]]
function MyDungeonsBook:ENCOUNTER_END(_, encounterId, encounterName, difficultyId, groupSize, success)
local id = self.db.char.activeChallengeId;
if (not id) then
return;
end
if (not self.db.char.challenges[id]) then
return;
end
local lastEncounterId = self.db.char.challenges[id].misc.lastEncounterId;
if (not lastEncounterId) then
-- is it possible???
return;
end
local enemyForcesProgressMechanic = self:SafeNestedGet(self.db.char.challenges[id].mechanics, "ENEMY-FORCES-PROGRESS");
local enemyForcesOnEnd;
if (enemyForcesProgressMechanic) then
enemyForcesOnEnd = (enemyForcesProgressMechanic[#enemyForcesProgressMechanic] or {})[2];
end
self.db.char.challenges[id].encounters[lastEncounterId].endTime = time();
self.db.char.challenges[id].encounters[lastEncounterId].success = success;
self.db.char.challenges[id].encounters[lastEncounterId].deathCountOnEnd = C_ChallengeMode.GetDeathCount();
self.db.char.challenges[id].encounters[lastEncounterId].enemyForcesOnEnd = enemyForcesOnEnd;
self.db.char.challenges[id].misc.lastEncounterId = nil;
self:DebugPrint("ENCOUNTER_END", encounterId, encounterName, difficultyId, groupSize, success);
end
--[[--
Track when player leaves a combat
Used to calculate idle time
]]
function MyDungeonsBook:PLAYER_REGEN_ENABLED()
local id = self.db.char.activeChallengeId;
if (not id) then
return;
end
local KEY = "PARTY_MEMBERS_IDLE";
local name = UnitName("player");
self:InitMechanics3Lvl(KEY, name, "meta");
self:InitMechanics4Lvl(KEY, name, "meta", "duration", true);
self:InitMechanics3Lvl(KEY, name, "timeline");
local timestamp = time();
self.db.char.challenges[id].mechanics[KEY][name].meta.lastStartTime = timestamp;
tinsert(self.db.char.challenges[id].mechanics[KEY][name].timeline, {timestamp, 0});
self:DebugPrint("Combat is finished.");
end
--[[--
Track when player enters a combat
Used to calculate idle time
]]
function MyDungeonsBook:PLAYER_REGEN_DISABLED()
local id = self.db.char.activeChallengeId;
if (not id) then
return;
end
local KEY = "PARTY_MEMBERS_IDLE";
local name = UnitName("player");
local now = time();
self:InitMechanics3Lvl(KEY, name, "meta");
self:InitMechanics4Lvl(KEY, name, "meta", "duration", true);
self:InitMechanics3Lvl(KEY, name, "timeline");
local currentIdle = time() - (self.db.char.challenges[id].mechanics[KEY][name].meta.lastStartTime or now);
local overallIdle = self.db.char.challenges[id].mechanics[KEY][name].meta.duration + currentIdle;
self.db.char.challenges[id].mechanics[KEY][name].meta.duration = overallIdle;
self.db.char.challenges[id].mechanics[KEY][name].meta.lastStartTime = nil;
self:DebugPrint(string.format("Combat is started. Idle time - %s, overall - %s", self:FormatTime(currentIdle * 1000), self:FormatTime(overallIdle * 1000)));
local timestamp = time();
tinsert(self.db.char.challenges[id].mechanics[KEY][name].timeline, {timestamp, 1});
end
--[[--
Track enemy forces progress
]]
function MyDungeonsBook:SCENARIO_CRITERIA_UPDATE()
local id = self.db.char.activeChallengeId;
if (not id) then
return;
end
local KEY = "ENEMY-FORCES-PROGRESS";
self:InitMechanics1Lvl(KEY);
local _, _, steps = C_Scenario.GetStepInfo();
if (steps and steps > 0) then
for i = 1, steps do
local name, _, completed, curValue, finalValue, _, _, quantity, criteriaId = C_Scenario.GetCriteriaInfo(i);
if (criteriaId == 0) then
local quantityNumber = string.sub(quantity, 1, string.len(quantity) - 1);
local quantityPercent = tonumber(quantityNumber) / finalValue;
if (completed) then
quantityPercent = 1;
end
tinsert(self.db.char.challenges[id].mechanics[KEY], {time(), quantityPercent});
end
end
end
end
--[[--
Used to track anima-powers for SL season 2 (for now)
]]
function MyDungeonsBook:CHAT_MSG_LOOT(_, text, partyMemberName)
if (not self.db.char.activeChallengeId) then
return;
end
if (not string.find(text, "mawpower")) then
return;
end
local partyUnitId = self:GetPartyUnitByName(self.db.char.activeChallengeId, partyMemberName);
if (not partyUnitId) then
return;
end
self:UpdatePartyMemberAnimaPowers(self.db.char.activeChallengeId, text, partyUnitId);
end
--[[--
Used to track loot from challenges gotten by party members
]]
function MyDungeonsBook:ENCOUNTER_LOOT_RECEIVED(_, encounterId, itemId, itemLink, quantity, playerName, className)
--[[if (not self:IsEncounterLastForAnyDungeon(encounterId)) then
self:DebugPrint(string.format("Encounter %s is not last for any dungeon", encounterId));
return;
end]]
local lastChallengeId = self:GetLastChallengeId();
local challenge = self:Challenge_GetById(lastChallengeId);
if (not challenge) then
self:DebugPrint(string.format("Challenge '%s' does not exist", lastChallengeId));
return;
end
if (not challenge.challengeInfo or not challenge.challengeInfo.endTime) then
return;
end
if (time() - challenge.challengeInfo.endTime > 600) then
self:DebugPrint("Challenge is too old");
return;
end
local partyUnitId = self:GetPartyUnitByName(lastChallengeId, playerName);
if (not partyUnitId) then
self:DebugPrint(string.format("Player %s does not exist in the party roster", playerName));
return;
end
if (not challenge.misc.loot[playerName]) then
challenge.misc.loot[playerName] = {};
end
tinsert(challenge.misc.loot[playerName], {itemid, itemLink, quantity});
end
function MyDungeonsBook:CHAT_MSG_RAID_BOSS_EMOTE(_, ...)
if (not self.db.char.activeChallengeId) then
return;
end
self:TrackChatMsgRaidBossEmotes(...);
end
function MyDungeonsBook:CHAT_MSG_MONSTER_EMOTE(_, ...)
if (not self.db.char.activeChallengeId) then
return;
end
self:TrackChatMsgMonsterEmotes(...);
end
function MyDungeonsBook:UNIT_SPELLCAST_START(_, sourceUnit, castId, spellId)
if (not self.db.char.activeChallengeId) then
return;
end
if (not self.db.global.meta.spells[spellId]) then
self.db.global.meta.spells[spellId] = {};
end
local name, _, icon, startMs, endMs, _, _, notInterruptible = UnitCastingInfo(sourceUnit);
self.db.global.meta.spells[spellId].kickable = not notInterruptible;
end
function MyDungeonsBook:UNIT_SPELLCAST_CHANNEL_START(_, sourceUnit, castId, spellId)
if (not self.db.char.activeChallengeId) then
return;
end
if (not self.db.global.meta.spells[spellId]) then
self.db.global.meta.spells[spellId] = {};
local name, _, icon, startMs, endMs, _, _, notInterruptible = UnitChannelInfo(sourceUnit);
self.db.global.meta.spells[spellId].chainable = true;
self.db.global.meta.spells[spellId].chainableKickable = not notInterruptible;
end
end
function MyDungeonsBook:COMBAT_RATING_UPDATE()
local id = self.db.char.activeChallengeId;
local KEY = "COMBAT-RATING";
if (not self.db.char.activeChallengeId) then
return;
end
local secondaries = {
["crit"] = CR_CRIT_SPELL,
["haste"] = CR_HASTE_SPELL,
["vers"] = CR_VERSATILITY_DAMAGE_DONE,
["mastery"] = CR_MASTERY
};
for secondary, cr in pairs(secondaries) do
self:InitMechanics2Lvl(KEY, secondary);
local l = #self.db.char.challenges[id].mechanics[KEY][secondary];
local lastValue = l >= 1 and self.db.char.challenges[id].mechanics[KEY][secondary][l].value or -1;
local newValue = GetCombatRating(cr);
if (lastValue ~= newValue) then
tinsert(self.db.char.challenges[id].mechanics[KEY][secondary], {
value = newValue,
timestamp = time(),
});
end
end
end
function MyDungeonsBook:NAME_PLATE_UNIT_ADDED(_, nameplateUnitId)
local guid = UnitGUID(nameplateUnitId);
self:TrackEnemyBuffDispelType(guid);
end