forked from Sidoine/Ovale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAura.lua
1708 lines (1616 loc) · 59.9 KB
/
Aura.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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[--------------------------------------------------------------------
Copyright (C) 2013, 2014, 2015 Johnny C. Lam.
See the file LICENSE.txt for copying permission.
--]]--------------------------------------------------------------------
--[[
This addon tracks all auras for all units.
--]]
local OVALE, Ovale = ...
local OvaleAura = Ovale:NewModule("OvaleAura", "AceEvent-3.0")
Ovale.OvaleAura = OvaleAura
--<private-static-properties>
local L = Ovale.L
local OvaleDebug = Ovale.OvaleDebug
local OvalePool = Ovale.OvalePool
local OvaleProfiler = Ovale.OvaleProfiler
-- Forward declarations for module dependencies.
local OvaleData = nil
local OvaleFuture = nil
local OvaleGUID = nil
local OvalePaperDoll = nil
local OvaleSpellBook = nil
local OvaleState = nil
local bit_band = bit.band
local bit_bor = bit.bor
local floor = math.floor
local ipairs = ipairs
local next = next
local pairs = pairs
local strfind = string.find
local strlower = string.lower
local strsub = string.sub
local tconcat = table.concat
local tinsert = table.insert
local tonumber = tonumber
local tsort = table.sort
local type = type
local wipe = wipe
local API_GetTime = GetTime
local API_UnitAura = UnitAura
local INFINITY = math.huge
local SCHOOL_MASK_ARCANE = SCHOOL_MASK_ARCANE
local SCHOOL_MASK_FIRE = SCHOOL_MASK_FIRE
local SCHOOL_MASK_FROST = SCHOOL_MASK_FROST
local SCHOOL_MASK_HOLY = SCHOOL_MASK_HOLY
local SCHOOL_MASK_NATURE = SCHOOL_MASK_NATURE
local SCHOOL_MASK_SHADOW = SCHOOL_MASK_SHADOW
-- Register for debugging messages.
OvaleDebug:RegisterDebugging(OvaleAura)
-- Register for profiling.
OvaleProfiler:RegisterProfiling(OvaleAura)
-- Player's GUID.
local self_playerGUID = nil
-- Player's pet's GUID.
local self_petGUID = nil
-- Table pool.
local self_pool = OvalePool("OvaleAura_pool")
-- Some auras have a nil caster, so treat those as having a GUID of zero for indexing purposes.
local UNKNOWN_GUID = 0
do
local output = {}
local debugOptions = {
playerAura = {
name = L["Auras (player)"],
type = "group",
args = {
buff = {
name = L["Auras on the player"],
type = "input",
multiline = 25,
width = "full",
get = function(info)
wipe(output)
local helpful = OvaleState.state:DebugUnitAuras("player", "HELPFUL")
if helpful then
output[#output + 1] = "== BUFFS =="
output[#output + 1] = helpful
end
local harmful = OvaleState.state:DebugUnitAuras("player", "HARMFUL")
if harmful then
output[#output + 1] = "== DEBUFFS =="
output[#output + 1] = harmful
end
return tconcat(output, "\n")
end,
},
},
},
targetAura = {
name = L["Auras (target)"],
type = "group",
args = {
targetbuff = {
name = L["Auras on the target"],
type = "execute",
type = "input",
multiline = 25,
width = "full",
get = function(info)
wipe(output)
local helpful = OvaleState.state:DebugUnitAuras("target", "HELPFUL")
if helpful then
output[#output + 1] = "== BUFFS =="
output[#output + 1] = helpful
end
local harmful = OvaleState.state:DebugUnitAuras("target", "HARMFUL")
if harmful then
output[#output + 1] = "== DEBUFFS =="
output[#output + 1] = harmful
end
return tconcat(output, "\n")
end,
},
},
},
}
-- Insert debug options into OvaleDebug.
for k, v in pairs(debugOptions) do
OvaleDebug.options.args[k] = v
end
end
-- Aura debuff types.
local DEBUFF_TYPE = {
Curse = true,
Disease = true,
Enrage = true,
Magic = true,
Poison = true,
}
local SPELLINFO_DEBUFF_TYPE = {}
do
for debuffType in pairs(DEBUFF_TYPE) do
local siDebuffType = strlower(debuffType)
SPELLINFO_DEBUFF_TYPE[siDebuffType] = debuffType
end
end
-- CLEU events triggered by auras being applied, removed, refreshed, or changed in stack size.
local CLEU_AURA_EVENTS = {
SPELL_AURA_APPLIED = true,
SPELL_AURA_REMOVED = true,
SPELL_AURA_APPLIED_DOSE = true,
SPELL_AURA_REMOVED_DOSE = true,
SPELL_AURA_REFRESH = true,
SPELL_AURA_BROKEN = true,
SPELL_AURA_BROKEN_SPELL = true,
}
-- CLEU events triggered by a periodic aura.
local CLEU_TICK_EVENTS = {
SPELL_PERIODIC_DAMAGE = true,
SPELL_PERIODIC_HEAL = true,
SPELL_PERIODIC_ENERGIZE = true,
SPELL_PERIODIC_DRAIN = true,
SPELL_PERIODIC_LEECH = true,
}
-- Spell school bitmask to identify magic effects.
local CLEU_SCHOOL_MASK_MAGIC = bit_bor(SCHOOL_MASK_ARCANE, SCHOOL_MASK_FIRE, SCHOOL_MASK_FROST, SCHOOL_MASK_HOLY, SCHOOL_MASK_NATURE, SCHOOL_MASK_SHADOW)
--</private-static-properties>
--<public-static-properties>
-- Auras on the target (past & present): aura[guid][auraId][casterGUID] = aura.
OvaleAura.aura = {}
-- Current age of auras per unit: serial[guid] = age.
OvaleAura.serial = {}
-- Begin aura bypass code
OvaleAura.bypassState = {}
-- End aura bypass code
-- Unused public property to suppress lint warnings.
--OvaleAura.defaultTarget = nil
--</public-static-properties>
--<private-static-methods>
local function PutAura(auraDB, guid, auraId, casterGUID, aura)
if not auraDB[guid] then
auraDB[guid] = self_pool:Get()
end
if not auraDB[guid][auraId] then
auraDB[guid][auraId] = self_pool:Get()
end
-- Remove any pre-existing aura at that slot.
if auraDB[guid][auraId][casterGUID] then
self_pool:Release(auraDB[guid][auraId][casterGUID])
end
-- Save the aura into that slot.
auraDB[guid][auraId][casterGUID] = aura
-- Set aura properties as a result of where it's slotted.
aura.guid = guid
aura.spellId = auraId
aura.source = casterGUID
end
local function GetAura(auraDB, guid, auraId, casterGUID)
if auraDB[guid] and auraDB[guid][auraId] and auraDB[guid][auraId][casterGUID] then
-- TODO: Use a SpellInfo instead of hard numbers here so it could be declared in the script in case any other abilities do this?
-- Wrecking Ball Buff
if auraId == 215570 then
local spellcast = OvaleFuture:LastInFlightSpell()
-- Whirlwind
if spellcast and spellcast.spellId and spellcast.spellId == 190411 and spellcast.start then
local aura = auraDB[guid][auraId][casterGUID]
if aura.start and aura.start < spellcast.start then
-- If the aura began before the start of the Whirlwind, then the aura has ended
-- Shows as an active aura in game until the animation of Whirlwind ends.
aura.ending = spellcast.start
end
end
end
return auraDB[guid][auraId][casterGUID]
end
end
local function GetAuraAnyCaster(auraDB, guid, auraId)
local auraFound
if auraDB[guid] and auraDB[guid][auraId] then
for casterGUID, aura in pairs(auraDB[guid][auraId]) do
-- Find the aura with the latest expiration time.
if not auraFound or auraFound.ending < aura.ending then
auraFound = aura
end
end
end
return auraFound
end
local function GetDebuffType(auraDB, guid, debuffType, filter, casterGUID)
local auraFound
if auraDB[guid] then
for auraId, whoseTable in pairs(auraDB[guid]) do
local aura = whoseTable[casterGUID]
if aura and aura.debuffType == debuffType and aura.filter == filter then
-- Find the aura with the latest expiration time.
if not auraFound or auraFound.ending < aura.ending then
auraFound = aura
end
end
end
end
return auraFound
end
local function GetDebuffTypeAnyCaster(auraDB, guid, debuffType, filter)
local auraFound
if auraDB[guid] then
for auraId, whoseTable in pairs(auraDB[guid]) do
for casterGUID, aura in pairs(whoseTable) do
if aura and aura.debuffType == debuffType and aura.filter == filter then
-- Find the aura with the latest expiration time.
if not auraFound or auraFound.ending < aura.ending then
auraFound = aura
end
end
end
end
end
return auraFound
end
local function GetAuraOnGUID(auraDB, guid, auraId, filter, mine)
local auraFound
if DEBUFF_TYPE[auraId] then
if mine then
-- Check for aura applied by player, then player's pet if it exists.
auraFound = GetDebuffType(auraDB, guid, auraId, filter, self_playerGUID)
if not auraFound then
for petGUID in pairs(self_petGUID) do
local aura = GetDebuffType(auraDB, guid, auraId, filter, petGUID)
-- Find the aura with the latest expiration time.
if aura and (not auraFound or auraFound.ending < aura.ending) then
auraFound = aura
end
end
end
else
auraFound = GetDebuffTypeAnyCaster(auraDB, guid, auraId, filter)
end
else
if mine then
-- Check for aura applied by player, then player's pet if it exists.
auraFound = GetAura(auraDB, guid, auraId, self_playerGUID)
if not auraFound then
for petGUID in pairs(self_petGUID) do
local aura = GetAura(auraDB, guid, auraId, petGUID)
-- Find the aura with the latest expiration time.
if aura and (not auraFound or auraFound.ending < aura.ending) then
auraFound = aura
end
end
end
else
auraFound = GetAuraAnyCaster(auraDB, guid, auraId)
end
end
return auraFound
end
local function RemoveAurasOnGUID(auraDB, guid)
if auraDB[guid] then
local auraTable = auraDB[guid]
for auraId, whoseTable in pairs(auraTable) do
for casterGUID, aura in pairs(whoseTable) do
self_pool:Release(aura)
whoseTable[casterGUID] = nil
end
self_pool:Release(whoseTable)
auraTable[auraId] = nil
end
self_pool:Release(auraTable)
auraDB[guid] = nil
end
end
local function IsWithinAuraLag(time1, time2, factor)
factor = factor or 1
local auraLag = Ovale.db.profile.apparence.auraLag
local tolerance = factor * auraLag / 1000
return (time1 - time2 < tolerance) and (time2 - time1 < tolerance)
end
--</private-static-methods>
--<public-static-methods>
function OvaleAura:OnInitialize()
-- Resolve module dependencies.
OvaleData = Ovale.OvaleData
OvaleFuture = Ovale.OvaleFuture
OvaleGUID = Ovale.OvaleGUID
OvalePaperDoll = Ovale.OvalePaperDoll
OvaleSpellBook = Ovale.OvaleSpellBook
OvaleState = Ovale.OvaleState
end
function OvaleAura:OnEnable()
self_playerGUID = Ovale.playerGUID
self_petGUID = OvaleGUID.petGUID
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("UNIT_AURA")
self:RegisterMessage("Ovale_GroupChanged", "ScanAllUnitAuras")
self:RegisterMessage("Ovale_UnitChanged")
OvaleData:RegisterRequirement("buff", "RequireBuffHandler", self)
OvaleData:RegisterRequirement("buff_any", "RequireBuffHandler", self)
OvaleData:RegisterRequirement("debuff", "RequireBuffHandler", self)
OvaleData:RegisterRequirement("debuff_any", "RequireBuffHandler", self)
OvaleData:RegisterRequirement("pet_buff", "RequireBuffHandler", self)
OvaleData:RegisterRequirement("pet_debuff", "RequireBuffHandler", self)
OvaleData:RegisterRequirement("stealth", "RequireStealthHandler", self)
OvaleData:RegisterRequirement("stealthed", "RequireStealthHandler", self)
OvaleData:RegisterRequirement("target_buff", "RequireBuffHandler", self)
OvaleData:RegisterRequirement("target_buff_any", "RequireBuffHandler", self)
OvaleData:RegisterRequirement("target_debuff", "RequireBuffHandler", self)
OvaleData:RegisterRequirement("target_debuff_any", "RequireBuffHandler", self)
OvaleState:RegisterState(self, self.statePrototype)
end
function OvaleAura:OnDisable()
OvaleState:UnregisterState(self)
OvaleData:UnregisterRequirement("buff")
OvaleData:UnregisterRequirement("buff_any")
OvaleData:UnregisterRequirement("debuff")
OvaleData:UnregisterRequirement("debuff_any")
OvaleData:UnregisterRequirement("pet_buff")
OvaleData:UnregisterRequirement("pet_debuff")
OvaleData:UnregisterRequirement("stealth")
OvaleData:UnregisterRequirement("stealthed")
OvaleData:UnregisterRequirement("target_buff")
OvaleData:UnregisterRequirement("target_buff_any")
OvaleData:UnregisterRequirement("target_debuff")
OvaleData:UnregisterRequirement("target_debuff_any")
self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
self:UnregisterEvent("PLAYER_UNGHOST")
self:UnregisterEvent("UNIT_AURA")
self:UnregisterMessage("Ovale_GroupChanged")
self:UnregisterMessage("Ovale_UnitChanged")
for guid in pairs(self.aura) do
RemoveAurasOnGUID(self.aura, guid)
end
self_pool:Drain()
end
function OvaleAura:COMBAT_LOG_EVENT_UNFILTERED(event, timestamp, cleuEvent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, ...)
local arg12, arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24, arg25 = ...
local mine = (sourceGUID == self_playerGUID or OvaleGUID:IsPlayerPet(sourceGUID))
-- Begin aura bypass code.
if mine and cleuEvent == "SPELL_MISSED" then
local spellId, spellName, spellSchool = arg12, arg13, arg14
local si = OvaleData.spellInfo[spellId]
local bypassState = OvaleAura.bypassState
-- Bypass the state for auras applied to player.
if si and si.aura and si.aura.player then
for filter, auraTable in pairs(si.aura.player) do
for auraId in pairs(auraTable) do
if not bypassState[auraId] then
bypassState[auraId] = {}
end
bypassState[auraId][self_playerGUID] = true
end
end
end
-- Bypass the state for auras applied to target.
if si and si.aura and si.aura.target then
for filter, auraTable in pairs(si.aura.target) do
for auraId in pairs(auraTable) do
if not bypassState[auraId] then
bypassState[auraId] = {}
end
bypassState[auraId][destGUID] = true
end
end
end
-- Bypass the state for auras applied to pet.
if si and si.aura and si.aura.pet then
for filter, auraTable in pairs(si.aura.pet) do
for auraId, index in pairs(auraTable) do
for petGUID in pairs(self_petGUID) do
if not bypassState[petGUID] then
bypassState[auraId] = {}
end
bypassState[auraId][petGUID] = true
end
end
end
end
end
-- End aura bypass code
if CLEU_AURA_EVENTS[cleuEvent] then
local unitId = OvaleGUID:GUIDUnit(destGUID)
if unitId then
-- Only update auras on the unit if it is not a unit type that receives UNIT_AURA events.
if not OvaleGUID.UNIT_AURA_UNIT[unitId] then
self:DebugTimestamp("%s: %s (%s)", cleuEvent, destGUID, unitId)
self:ScanAuras(unitId, destGUID)
end
elseif mine then
-- There is no unit ID, but the action was caused by the player, so update this aura on destGUID.
local spellId, spellName, spellSchool = arg12, arg13, arg14
self:DebugTimestamp("%s: %s (%d) on %s", cleuEvent, spellName, spellId, destGUID)
local now = API_GetTime()
if cleuEvent == "SPELL_AURA_REMOVED" or cleuEvent == "SPELL_AURA_BROKEN" or cleuEvent == "SPELL_AURA_BROKEN_SPELL" then
self:LostAuraOnGUID(destGUID, now, spellId, sourceGUID)
else
local auraType, amount = arg15, arg16
local filter = (auraType == "BUFF") and "HELPFUL" or "HARMFUL"
local si = OvaleData.spellInfo[spellId]
-- Find an existing aura applied by the player on destGUID.
local aura = GetAuraOnGUID(self.aura, destGUID, spellId, filter, true)
local duration
if aura then
-- Re-use the duration of the previous aura on the target.
duration = aura.duration
elseif si and si.duration then
-- Look up the duration from the SpellInfo.
duration = OvaleData:GetSpellInfoProperty(spellId, now, "duration", destGUID)
if si.addduration then
duration = duration + si.addduration
end
else
-- No aura duration information known and we can't scan the aura on that GUID,
-- so assume the aura lasts 15 seconds.
-- TODO: There is probably something smarter to be done here.
duration = 15
end
local expirationTime = now + duration
local count
if cleuEvent == "SPELL_AURA_APPLIED" then
count = 1
elseif cleuEvent == "SPELL_AURA_APPLIED_DOSE" or cleuEvent == "SPELL_AURA_REMOVED_DOSE" then
count = amount
elseif cleuEvent == "SPELL_AURA_REFRESH" then
count = aura and aura.stacks or 1
end
self:GainedAuraOnGUID(destGUID, now, spellId, sourceGUID, filter, true, nil, count, nil, duration, expirationTime, nil, spellName)
end
end
elseif mine and CLEU_TICK_EVENTS[cleuEvent] then
-- Update the latest tick time of the periodic aura cast by the player.
local spellId, spellName, spellSchool = arg12, arg13, arg14
local multistrike
if strsub(cleuEvent, -7) == "_DAMAGE" then
multistrike = arg25
elseif strsub(cleuEvent, -5) == "_HEAL" then
multistrike = arg19
end
if not multistrike then
self:DebugTimestamp("%s: %s", cleuEvent, destGUID)
local aura = GetAura(self.aura, destGUID, spellId, self_playerGUID)
local now = API_GetTime()
if self:IsActiveAura(aura, now) then
local name = aura.name or "Unknown spell"
local baseTick, lastTickTime = aura.baseTick, aura.lastTickTime
local tick = baseTick
if lastTickTime then
-- Update the tick length based on the timestamps of the current tick and the previous tick.
tick = timestamp - lastTickTime
elseif not baseTick then
-- This isn't a known periodic aura, but it's ticking so treat this as the first tick.
self:Debug(" First tick seen of unknown periodic aura %s (%d) on %s.", name, spellId, destGUID)
local si = OvaleData.spellInfo[spellId]
baseTick = (si and si.tick) and si.tick or 3
tick = OvaleData:GetTickLength(spellId)
end
aura.baseTick = baseTick
aura.lastTickTime = timestamp
aura.tick = tick
self:Debug(" Updating %s (%s) on %s, tick=%s, lastTickTime=%s", name, spellId, destGUID, tick, lastTickTime)
Ovale.refreshNeeded[destGUID] = true
end
end
end
end
function OvaleAura:PLAYER_ENTERING_WORLD(event)
-- Initialize aura databases by scanning all unit auras.
self:ScanAllUnitAuras()
end
function OvaleAura:PLAYER_REGEN_ENABLED(event)
self:RemoveAurasOnInactiveUnits()
self_pool:Drain()
end
function OvaleAura:UNIT_AURA(event, unitId)
self:Debug("%s: %s", event, unitId)
self:ScanAuras(unitId)
end
function OvaleAura:Ovale_UnitChanged(event, unitId, guid)
if (unitId == "pet" or unitId == "target") and guid then
self:Debug(event, unitId, guid)
self:ScanAuras(unitId, guid)
end
end
function OvaleAura:ScanAllUnitAuras()
-- Update auras on all visible units.
for unitId in pairs(OvaleGUID.UNIT_AURA_UNIT) do
self:ScanAuras(unitId)
end
end
function OvaleAura:RemoveAurasOnInactiveUnits()
-- Remove all auras from GUIDs that can no longer be referenced by a unit ID,
-- i.e., not in the group or not targeted by anyone in the group or focus.
for guid in pairs(self.aura) do
local unitId = OvaleGUID:GUIDUnit(guid)
if not unitId then
self:Debug("Removing auras from GUID %s", guid)
RemoveAurasOnGUID(self.aura, guid)
self.serial[guid] = nil
end
end
end
function OvaleAura:IsActiveAura(aura, atTime)
local boolean = false
if aura then
atTime = atTime or API_GetTime()
if aura.serial == self.serial[aura.guid] and aura.stacks > 0 and aura.gain <= atTime and atTime <= aura.ending then
boolean = true
elseif aura.consumed and IsWithinAuraLag(aura.ending, atTime) then
boolean = true
end
end
return boolean
end
function OvaleAura:GainedAuraOnGUID(guid, atTime, auraId, casterGUID, filter, visible, icon, count, debuffType, duration, expirationTime, isStealable, name, value1, value2, value3)
self:StartProfiling("OvaleAura_GainedAuraOnGUID")
-- Whose aura is it?
casterGUID = casterGUID or UNKNOWN_GUID
-- UnitAura() can return zero count for auras that are present.
count = (count and count > 0) and count or 1
-- "Zero" or nil duration and expiration actually mean the aura never expires.
duration = (duration and duration > 0) and duration or INFINITY
expirationTime = (expirationTime and expirationTime > 0) and expirationTime or INFINITY
local aura = GetAura(self.aura, guid, auraId, casterGUID)
local auraIsActive
if aura then
auraIsActive = (aura.stacks > 0 and aura.gain <= atTime and atTime <= aura.ending)
else
aura = self_pool:Get()
PutAura(self.aura, guid, auraId, casterGUID, aura)
auraIsActive = false
end
-- Only overwrite an active aura's information if the aura has changed.
-- An aura's "fingerprint" is its: caster, duration, expiration time, stack count, value
local auraIsUnchanged = (
aura.source == casterGUID
and aura.duration == duration
and aura.ending == expirationTime
and aura.stacks == count
and aura.value1 == value1
and aura.value2 == value2
and aura.value3 == value3
)
-- Update age of aura, regardless of whether it's changed.
aura.serial = self.serial[guid]
if not auraIsActive or not auraIsUnchanged then
self:Debug(" Adding %s %s (%s) to %s at %f, aura.serial=%d", filter, name, auraId, guid, atTime, aura.serial)
aura.name = name
aura.duration = duration
aura.ending = expirationTime
if duration < INFINITY and expirationTime < INFINITY then
aura.start = expirationTime - duration
else
aura.start = atTime
end
aura.gain = atTime
aura.lastUpdated = atTime
local direction = aura.direction or 1
if aura.stacks then
if aura.stacks < count then
direction = 1 -- increasing stack count
elseif aura.stacks > count then
direction = -1 -- decreasing stack count
end
end
aura.direction = direction
aura.stacks = count
aura.consumed = nil
aura.filter = filter
aura.visible = visible
aura.icon = icon
aura.debuffType = debuffType
aura.enrage = (debuffType == "Enrage") or nil
aura.stealable = isStealable
aura.value1, aura.value2, aura.value3 = value1, value2, value3
-- Snapshot stats for auras applied by the player or player's pet.
local mine = (casterGUID == self_playerGUID or OvaleGUID:IsPlayerPet(casterGUID))
if mine then
-- Determine whether to snapshot player stats for the aura or to keep the existing stats.
local spellcast = OvaleFuture:LastInFlightSpell()
if spellcast and spellcast.stop and not IsWithinAuraLag(spellcast.stop, atTime) then
spellcast = OvaleFuture.lastSpellcast
if spellcast and spellcast.stop and not IsWithinAuraLag(spellcast.stop, atTime) then
spellcast = nil
end
end
if spellcast and spellcast.target == guid then
local spellId = spellcast.spellId
local spellName = OvaleSpellBook:GetSpellName(spellId) or "Unknown spell"
-- Parse the spell data for this aura to see if this is a "refresh_keep_snapshot" aura.
local keepSnapshot = false
local si = OvaleData.spellInfo[spellId]
if si and si.aura then
local auraTable = OvaleGUID:IsPlayerPet(guid) and si.aura.pet or si.aura.target
if auraTable and auraTable[filter] then
local spellData = auraTable[filter][auraId]
if spellData == "refresh_keep_snapshot" then
keepSnapshot = true
elseif type(spellData) == "table" and spellData[1] == "refresh_keep_snapshot" then
-- Comma-separated value.
keepSnapshot = OvaleData:CheckRequirements(spellId, atTime, spellData, 2, guid)
end
end
end
if keepSnapshot then
self:Debug(" Keeping snapshot stats for %s %s (%d) on %s refreshed by %s (%d) from %f, now=%f, aura.serial=%d",
filter, name, auraId, guid, spellName, spellId, aura.snapshotTime, atTime, aura.serial)
else
self:Debug(" Snapshot stats for %s %s (%d) on %s applied by %s (%d) from %f, now=%f, aura.serial=%d",
filter, name, auraId, guid, spellName, spellId, spellcast.snapshotTime, atTime, aura.serial)
-- TODO: damageMultiplier isn't correct if spellId spreads the DoT.
OvaleFuture:CopySpellcastInfo(spellcast, aura)
end
end
local si = OvaleData.spellInfo[auraId]
if si then
-- Set the tick information for known DoTs.
if si.tick then
self:Debug(" %s (%s) is a periodic aura.", name, auraId)
-- Only set the initial tick information for new auras.
if not auraIsActive then
aura.baseTick = si.tick
if spellcast and spellcast.target == guid then
aura.tick = OvaleData:GetTickLength(auraId, spellcast)
else
aura.tick = OvaleData:GetTickLength(auraId)
end
end
end
-- Set the cooldown expiration time for player buffs applied by items with a cooldown.
if si.buff_cd and guid == self_playerGUID then
self:Debug(" %s (%s) is applied by an item with a cooldown of %ds.", name, auraId, si.buff_cd)
if not auraIsActive then
-- cooldownEnding is the earliest time at which we expect to gain this buff again.
aura.cooldownEnding = aura.gain + si.buff_cd
end
end
end
end
if not auraIsActive then
self:SendMessage("Ovale_AuraAdded", atTime, guid, auraId, aura.source)
elseif not auraIsUnchanged then
self:SendMessage("Ovale_AuraChanged", atTime, guid, auraId, aura.source)
end
Ovale.refreshNeeded[guid] = true
end
self:StopProfiling("OvaleAura_GainedAuraOnGUID")
end
function OvaleAura:LostAuraOnGUID(guid, atTime, auraId, casterGUID)
self:StartProfiling("OvaleAura_LostAuraOnGUID")
local aura = GetAura(self.aura, guid, auraId, casterGUID)
if aura then
local filter = aura.filter
self:Debug(" Expiring %s %s (%d) from %s at %f.", filter, aura.name, auraId, guid, atTime)
if aura.ending > atTime then
aura.ending = atTime
end
-- Snapshot stats for auras applied by the player or player's pet.
local mine = (casterGUID == self_playerGUID or OvaleGUID:IsPlayerPet(casterGUID))
if mine then
-- Clear old tick information for player-applied periodic auras.
aura.baseTick = nil
aura.lastTickTime = nil
aura.tick = nil
-- Check if the aura was consumed by the last spellcast.
-- The aura must have ended early, i.e., start + duration > ending.
if aura.start + aura.duration > aura.ending then
local spellcast
if guid == self_playerGUID then
-- Player aura, so it was possibly consumed by an in-flight spell.
spellcast = OvaleFuture:LastSpellSent()
else
-- Non-player aura, so it was possibly consumed by a spell that landed on its target.
spellcast = OvaleFuture.lastSpellcast
end
if spellcast then
-- If last spell is successful, check against stop time, i.e., end of cast for cast time spells or succeeded time for instant-cast spells
if (spellcast.success and spellcast.stop and IsWithinAuraLag(spellcast.stop, aura.ending)) or
-- If last spell sent was not successful, check against the time it was queued, i.e., when the ability was sent
-- Required as sometimes UNIT_AURA event fires before UNIT_SPELLCAST_SUCCEEDED event
(spellcast.queued and IsWithinAuraLag(spellcast.queued, aura.ending)) then
aura.consumed = true
local spellName = OvaleSpellBook:GetSpellName(spellcast.spellId) or "Unknown spell"
self:Debug(" Consuming %s %s (%d) on %s with queued %s (%d) at %f.", filter, aura.name, auraId, guid, spellName, spellcast.spellId, spellcast.queued)
end
end
end
end
aura.lastUpdated = atTime
self:SendMessage("Ovale_AuraRemoved", atTime, guid, auraId, aura.source)
Ovale.refreshNeeded[guid] = true
end
self:StopProfiling("OvaleAura_LostAuraOnGUID")
end
-- Scan auras on the given GUID and update the aura database.
function OvaleAura:ScanAuras(unitId, guid)
self:StartProfiling("OvaleAura_ScanAuras")
guid = guid or OvaleGUID:UnitGUID(unitId)
if guid then
self:DebugTimestamp("Scanning auras on %s (%s)", guid, unitId)
-- Advance the age of the unit's auras.
local serial = self.serial[guid] or 0
serial = serial + 1
self:Debug(" Advancing age of auras for %s (%s) to %d.", guid, unitId, serial)
self.serial[guid] = serial
-- Add all auras on the unit into the database.
local i = 1
local filter = "HELPFUL"
local now = API_GetTime()
while true do
local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellId,
canApplyAura, isBossDebuff, isCastByPlayer, value1, value2, value3 = API_UnitAura(unitId, i, filter)
if not name then
if filter == "HELPFUL" then
filter = "HARMFUL"
i = 1
else
break
end
else
local casterGUID = OvaleGUID:UnitGUID(unitCaster)
if debuffType == "" then
-- Empty string for the debuff type means this is an Enrage effect.
debuffType = "Enrage"
end
self:GainedAuraOnGUID(guid, now, spellId, casterGUID, filter, true, icon, count, debuffType, duration, expirationTime, isStealable, name, value1, value2, value3)
i = i + 1
end
end
-- Find recently expired auras on the unit.
if self.aura[guid] then
local auraTable = self.aura[guid]
for auraId, whoseTable in pairs(auraTable) do
for casterGUID, aura in pairs(whoseTable) do
if aura.serial == serial - 1 then
if aura.visible then
-- Remove the aura if it was visible.
self:LostAuraOnGUID(guid, now, auraId, casterGUID)
else
-- Age any hidden auras that are managed by outside modules.
aura.serial = serial
self:Debug(" Preserving aura %s (%d), start=%s, ending=%s, aura.serial=%d", aura.name, aura.spellId, aura.start, aura.ending, aura.serial)
end
end
end
end
end
self:Debug("End scanning of auras on %s (%s).", guid, unitId)
end
self:StopProfiling("OvaleAura_ScanAuras")
end
function OvaleAura:GetAuraByGUID(guid, auraId, filter, mine)
-- If this GUID has no auras in the database, then do an aura scan.
if not self.serial[guid] then
local unitId = OvaleGUID:GUIDUnit(guid)
self:ScanAuras(unitId, guid)
end
local auraFound
if OvaleData.buffSpellList[auraId] then
for id in pairs(OvaleData.buffSpellList[auraId]) do
local aura = GetAuraOnGUID(self.aura, guid, id, filter, mine)
if aura and (not auraFound or auraFound.ending < aura.ending) then
auraFound = aura
end
end
else
auraFound = GetAuraOnGUID(self.aura, guid, auraId, filter, mine)
end
return auraFound
end
function OvaleAura:GetAura(unitId, auraId, filter, mine)
local guid = OvaleGUID:UnitGUID(unitId)
return self:GetAuraByGUID(guid, auraId, filter, mine)
end
-- Run-time check for an aura on the player or the target.
-- NOTE: Mirrored in statePrototype below.
function OvaleAura:RequireBuffHandler(spellId, atTime, requirement, tokens, index, targetGUID)
local verified = false
-- If index isn't given, then tokens holds the actual token value.
local buffName = tokens
local stacks = 1
if index then
buffName = tokens[index]
index = index + 1
-- Peek at the next token to see if it is an optional minimum stack count.
local count = tonumber(tokens[index])
if count then
stacks = count
index = index + 1
end
end
if buffName then
local isBang = false
if strsub(buffName, 1, 1) == "!" then
isBang = true
buffName = strsub(buffName, 2)
end
local buffName = tonumber(buffName) or buffName
local guid, unitId, filter, mine
if strsub(requirement, 1, 7) == "target_" then
if targetGUID then
guid = targetGUID
unitId = OvaleGUID:GUIDUnit(guid)
else
unitId = self.defaultTarget or "target"
end
filter = (strsub(requirement, 8, 11) == "buff") and "HELPFUL" or "HARMFUL"
mine = not (strsub(requirement, -4) == "_any")
elseif strsub(requirement, 1, 4) == "pet_" then
unitId = "pet"
filter = (strsub(requirement, 5, 11) == "buff") and "HELPFUL" or "HARMFUL"
mine = false
else
unitId = "player"
filter = (strsub(requirement, 1, 4) == "buff") and "HELPFUL" or "HARMFUL"
mine = not (strsub(requirement, -4) == "_any")
end
guid = guid or OvaleGUID:UnitGUID(unitId)
local aura = self:GetAuraByGUID(guid, buffName, filter, mine)
local isActiveAura = self:IsActiveAura(aura, atTime) and aura.stacks >= stacks
if not isBang and isActiveAura or isBang and not isActiveAura then
verified = true
end
local result = verified and "passed" or "FAILED"
if isBang then
self:Log(" Require aura %s with at least %d stack(s) NOT on %s at time=%f: %s", buffName, stacks, unitId, atTime, result)
else
self:Log(" Require aura %s with at least %d stack(s) on %s at time=%f: %s", buffName, stacks, unitId, atTime, result)
end
else
Ovale:OneTimeMessage("Warning: requirement '%s' is missing a buff argument.", requirement)
end
return verified, requirement, index
end
-- Run-time check for the player being stealthed.
-- NOTE: Mirrored in statePrototype below.
function OvaleAura:RequireStealthHandler(spellId, atTime, requirement, tokens, index, targetGUID)
local verified = false
-- If index isn't given, then tokens holds the actual token value.
local stealthed = tokens
if index then
stealthed = tokens[index]
index = index + 1
end
if stealthed then
stealthed = tonumber(stealthed)
local aura = self:GetAura("player", "stealthed_buff", "HELPFUL", true)
local isActiveAura = self:IsActiveAura(aura, atTime)
if stealthed == 1 and isActiveAura or stealthed ~= 1 and not isActiveAura then
verified = true
end
local result = verified and "passed" or "FAILED"
if stealthed == 1 then
self:Log(" Require stealth at time=%f: %s", atTime, result)
else
self:Log(" Require NOT stealth at time=%f: %s", atTime, result)
end
else
Ovale:OneTimeMessage("Warning: requirement '%s' is missing an argument.", requirement)
end
return verified, requirement, index
end
--</public-static-methods>
--[[----------------------------------------------------------------------------
State machine for simulator.
--]]----------------------------------------------------------------------------
--<public-static-properties>
OvaleAura.statePrototype = {
aura = nil,
serial = nil,
}
--</public-static-properties>
--<private-static-properties>
local statePrototype = OvaleAura.statePrototype
--</private-static-properties>
--<state-properties>
-- Aura database: aura[guid][auraId][casterId] = aura
statePrototype.aura = nil
-- Age of active auras in the simulator.
statePrototype.serial = nil
--</state-properties>
--<public-static-methods>
-- Initialize the state.
function OvaleAura:InitializeState(state)
state.aura = {}
state.serial = 0
end
-- Reset the state to the current conditions.
function OvaleAura:ResetState(state)
self:StartProfiling("OvaleAura_ResetState")
-- Advance age of auras in state machine.
state.serial = state.serial + 1
-- Garbage-collect auras in the state machine that are more recently updated in the true aura database.
if next(state.aura) then
state:Log("Resetting aura state:")
end
for guid, auraTable in pairs(state.aura) do
for auraId, whoseTable in pairs(auraTable) do
for casterGUID, aura in pairs(whoseTable) do
self_pool:Release(aura)
whoseTable[casterGUID] = nil
state:Log(" Aura %d on %s removed.", auraId, guid)
end
if not next(whoseTable) then
self_pool:Release(whoseTable)
auraTable[auraId] = nil
end
end