forked from Sidoine/Ovale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFuture.lua
1439 lines (1346 loc) · 52.5 KB
/
Future.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) 2012, 2013 Sidoine De Wispelaere.
Copyright (C) 2012, 2013, 2014, 2015 Johnny C. Lam.
See the file LICENSE.txt for copying permission.
--]]--------------------------------------------------------------------
--[[
OvaleFuture tracks player/pet spells that are being cast or are
in flight to their targets.
The UNIT_SPELLCAST_* events are treated as the definitive events for
the spellcasts, but CLEU events are used to fix up target GUIDs in
active spellcasts and to track when a spell has landed on its target.
--]]
local OVALE, Ovale = ...
local OvaleFuture = Ovale:NewModule("OvaleFuture", "AceEvent-3.0")
Ovale.OvaleFuture = OvaleFuture
--<private-static-properties>
local OvaleDebug = Ovale.OvaleDebug
local OvalePool = Ovale.OvalePool
local OvaleProfiler = Ovale.OvaleProfiler
-- Forward declarations for module dependencies.
local OvaleAura = nil
local OvaleCooldown = nil
local OvaleData = nil
local OvaleGUID = nil
local OvalePaperDoll = nil
local OvaleScore = nil
local OvaleSpellBook = nil
local OvaleState = nil
local assert = assert
local ipairs = ipairs
local pairs = pairs
local strsub = string.sub
local tinsert = table.insert
local tremove = table.remove
local type = type
local wipe = wipe
local API_GetSpellInfo = GetSpellInfo
local API_GetTime = GetTime
local API_UnitCastingInfo = UnitCastingInfo
local API_UnitChannelInfo = UnitChannelInfo
local API_UnitExists = UnitExists
local API_UnitGUID = UnitGUID
local API_UnitName = UnitName
-- Register for debugging.
OvaleDebug:RegisterDebugging(OvaleFuture)
-- Register for profiling.
OvaleProfiler:RegisterProfiling(OvaleFuture)
-- Player's GUID.
local self_playerGUID = nil
-- Pool of spellcast tables.
local self_pool = OvalePool("OvaleFuture_pool")
-- Time at which an aura on the player was most recently added.
local self_timeAuraAdded = nil
--[[
List of registered modules with methods to save and copy module-specific
information to and from spellcasts.
module:CopySpellcastInfo(spellcast, dest)
module:SaveSpellcastInfo(spellcast, atTime, state)
--]]
local self_modules = {}
-- These CLEU events are eventually received after a successful spellcast.
local CLEU_AURA_EVENT = {
SPELL_AURA_APPLIED = "hit",
SPELL_AURA_APPLIED_DOSE = "hit",
SPELL_AURA_BROKEN = "hit",
SPELL_AURA_BROKEN_SPELL = "hit",
SPELL_AURA_REFRESH = "hit",
SPELL_AURA_REMOVED = "hit",
SPELL_AURA_REMOVED_DOSE = "hit",
}
local CLEU_SPELLCAST_FINISH_EVENT = {
SPELL_DAMAGE = "hit",
SPELL_DISPEL = "hit",
SPELL_DISPEL_FAILED = "miss",
SPELL_HEAL = "hit",
SPELL_INTERRUPT = "hit",
SPELL_MISSED = "miss",
SPELL_STOLEN = "hit",
}
local CLEU_SPELLCAST_EVENT = {
SPELL_CAST_FAILED = true,
SPELL_CAST_START = true,
SPELL_CAST_SUCCESS = true,
}
do
-- Aura events are also spellcast finishing events.
for cleuEvent, v in pairs(CLEU_AURA_EVENT) do
CLEU_SPELLCAST_FINISH_EVENT[cleuEvent] = v
end
-- Spellcast finishing events are also spellcast events.
for cleuEvent, v in pairs(CLEU_SPELLCAST_FINISH_EVENT) do
CLEU_SPELLCAST_EVENT[cleuEvent] = true
end
end
-- The order in which auras applied or refreshed by a spell are checked.
local SPELLCAST_AURA_ORDER = { "target", "pet" }
-- Use zero as the target GUID of spells that have no target.
local UNKNOWN_GUID = 0
-- Table of aura additions.
local SPELLAURALIST_AURA_VALUE = {
count = true,
extend = true,
refresh = true,
refresh_keep_snapshot = true,
}
local WHITE_ATTACK = {
[ 75] = true, -- Auto Shot
[ 5019] = true, -- Shoot
[ 6603] = true, -- Auto Attack
}
local WHITE_ATTACK_NAME = {}
do
for spellId in pairs(WHITE_ATTACK) do
local name = API_GetSpellInfo(spellId)
if name then
WHITE_ATTACK_NAME[name] = true
end
end
end
--[[
This is the delta added to the starting cast time of the spell in the simulator.
This ensures that the time in the simulator is just after the spell has started
being cast.
--]]
local SIMULATOR_LAG = 0.005
--</private-static-properties>
--<public-static-properties>
-- Whether the player is in combat.
OvaleFuture.inCombat = nil
-- The time that combat started.
OvaleFuture.combatStartTime = nil
-- List of queued spellcasts.
OvaleFuture.queue = {}
-- Table of most recent cast times of spells, indexed by spell ID.
OvaleFuture.lastCastTime = {}
-- The most recent spellcast.
OvaleFuture.lastSpellcast = nil
-- The most recent spellcast that triggered the global cooldown.
OvaleFuture.lastGCDSpellcast = {}
-- The most recent spellcast that was off the global cooldown.
OvaleFuture.lastOffGCDSpellcast = {}
-- Spell counters.
OvaleFuture.counter = {}
--</public-static-properties>
--<private-static-methods>
-- Returns true if two spellcasts tables refer to the same spellcast.
local function IsSameSpellcast(a, b)
local boolean = (a.spellId == b.spellId and a.queued == b.queued)
if boolean then
if a.channel or b.channel then
if a.channel ~= b.channel then
boolean = false
end
elseif a.lineId ~= b.lineId then
boolean = false
end
end
return boolean
end
--</private-static-methods>
--<public-static-methods>
function OvaleFuture:OnInitialize()
-- Resolve module dependencies.
OvaleAura = Ovale.OvaleAura
OvaleCooldown = Ovale.OvaleCooldown
OvaleData = Ovale.OvaleData
OvaleGUID = Ovale.OvaleGUID
OvalePaperDoll = Ovale.OvalePaperDoll
OvaleScore = Ovale.OvaleScore
OvaleSpellBook = Ovale.OvaleSpellBook
OvaleState = Ovale.OvaleState
end
function OvaleFuture:OnEnable()
self_playerGUID = Ovale.playerGUID
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE")
self:RegisterEvent("UNIT_SPELLCAST_DELAYED")
self:RegisterEvent("UNIT_SPELLCAST_FAILED", "UnitSpellcastEnded")
self:RegisterEvent("UNIT_SPELLCAST_FAILED_QUIET", "UnitSpellcastEnded")
self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED", "UnitSpellcastEnded")
self:RegisterEvent("UNIT_SPELLCAST_SENT")
self:RegisterEvent("UNIT_SPELLCAST_START")
self:RegisterEvent("UNIT_SPELLCAST_STOP", "UnitSpellcastEnded")
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
self:RegisterMessage("Ovale_AuraAdded")
OvaleState:RegisterState(self, self.statePrototype)
end
function OvaleFuture:OnDisable()
OvaleState:UnregisterState(self)
self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
self:UnregisterEvent("PLAYER_REGEN_DISABLED")
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_START")
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
self:UnregisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE")
self:UnregisterEvent("UNIT_SPELLCAST_DELAYED")
self:UnregisterEvent("UNIT_SPELLCAST_FAILED")
self:UnregisterEvent("UNIT_SPELLCAST_FAILED_QUIET")
self:UnregisterEvent("UNIT_SPELLCAST_INTERRUPTED")
self:UnregisterEvent("UNIT_SPELLCAST_SENT")
self:UnregisterEvent("UNIT_SPELLCAST_START")
self:UnregisterEvent("UNIT_SPELLCAST_STOP")
self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
self:UnregisterMessage("Ovale_AuraAdded")
end
--[[--------------
Event handlers
--]]--------------
--[[
CLEU events generally happen in a certain order, but they can arrive out of order.
We ignore SPELL_CAST_SUCCESS since it arrives out of order too often to be reliable.
Cast-time damage spell:
SPELL_CAST_START
SPELL_CAST_FAILED/SPELL_DAMAGE/SPELL_INTERRUPT/SPELL_MISSED
Cast-time heal spell:
SPELL_CAST_START
SPELL_CAST_FAILED/SPELL_HEAL/SPELL_INTERRUPT
Instant-cast damage spell:
SPELL_CAST_SUCCESS
SPELL_CAST_FAILED/SPELL_DAMAGE/SPELL_MISSED
Instant-cast heal spell:
SPELL_CAST_FAILED/SPELL_HEAL
Channel damage spell:
SPELL_CAST_SUCCESS
SPELL_AURA_APPLIED
SPELL_PERIODIC_DAMAGE (per tick)
(interruption does not generate an event)
Channel heal spell:
SPELL_CAST_SUCCESS
SPELL_AURA_APPLIED
SPELL_PERIODIC_HEAL (per tick)
(interruption does not generate an event)
Applying an aura:
SPELL_AURA_APPLIED
SPELL_CAST_SUCCESS
Refreshing an aura:
SPELL_AURA_REFRESH
SPELL_CAST_SUCCESS
Removing an aura:
SPELL_AURA_REMOVED
Casting a damage-over-time spell:
SPELL_CAST_SUCCESS
SPELL_AURA_APPLIED
SPELL_PERIODIC_DAMAGE (per tick)
Casting a heal-over-time spell:
SPELL_CAST_SUCCESS
SPELL_AURA_APPLIED
SPELL_PERIODIC_HEAL (per tick)
--]]
function OvaleFuture: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 = ...
if sourceGUID == self_playerGUID or OvaleGUID:IsPlayerPet(sourceGUID) then
self:StartProfiling("OvaleFuture_COMBAT_LOG_EVENT_UNFILTERED")
if CLEU_SPELLCAST_EVENT[cleuEvent] then
local now = API_GetTime()
local spellId, spellName = arg12, arg13
local eventDebug = false
-- Disambiguate the target GUID of any matching spellcast.
if strsub(cleuEvent, 1, 11) == "SPELL_CAST_" and (destName and destName ~= "") then
if not eventDebug then
self:DebugTimestamp("CLEU", cleuEvent, sourceName, sourceGUID, destName, destGUID, spellId, spellName)
eventDebug = true
end
local spellcast = self:GetSpellcast(spellName, spellId, nil, now)
if spellcast and spellcast.targetName and spellcast.targetName == destName and spellcast.target ~= destGUID then
self:Debug("Disambiguating target of spell %s (%d) to %s (%s).", spellName, spellId, destName, destGUID)
spellcast.target = destGUID
end
end
-- Check for a "finishing" event for active spellcasts.
local finish = CLEU_SPELLCAST_FINISH_EVENT[cleuEvent]
--[[
If this is a SPELL_DAMAGE or SPELL_HEAL event, then only count it as
finishing event if it was the "main" attack, and not an off-hand or
multistrike attack.
--]]
if cleuEvent == "SPELL_DAMAGE" or cleuEvent == "SPELL_HEAL" then
local isOffHand, multistrike = arg24, arg25
if isOffHand or multistrike then
finish = nil
end
end
if finish then
--[[
Check every queued spellcast and see if this "finish" event signals
that the spell has landed. A single event can signal the finish for
more than one spellcast.
--]]
-- Scan backwards since we are removing list elements while traversing the list.
local anyFinished = false
for i = #self.queue, 1, -1 do
local spellcast = self.queue[i]
if spellcast.success and (spellcast.spellId == spellId or spellcast.auraId == spellId) then
if self:FinishSpell(spellcast, cleuEvent, sourceName, sourceGUID, destName, destGUID, spellId, spellName, delta, finish, i) then
anyFinished = true
end
end
end
if not anyFinished then
self:Debug("No spell found for %s (%d)", spellName, spellId)
for i = #self.queue, 1, -1 do
local spellcast = self.queue[i]
if spellcast.success and (spellcast.spellName == spellName) then
if self:FinishSpell(spellcast, cleuEvent, sourceName, sourceGUID, destName, destGUID, spellId, spellName, delta, finish, i) then
anyFinished = true
end
end
end
if not anyFinished then
self:Debug("No spell found for %s", spellName, spellId)
end
end
end
end
self:StopProfiling("OvaleFuture_COMBAT_LOG_EVENT_UNFILTERED")
end
end
function OvaleFuture:FinishSpell(spellcast, cleuEvent, sourceName, sourceGUID, destName, destGUID, spellId, spellName, delta, finish, i)
local finished = false
if not spellcast.auraId then
--[[
There is no aura to detect, so the spell is finished when it lands,
but not if it is a channelled spell.
--]]
if not eventDebug then
self:DebugTimestamp("CLEU", cleuEvent, sourceName, sourceGUID, destName, destGUID, spellId, spellName)
eventDebug = true
end
if not spellcast.channel then
self:Debug("Finished (%s) spell %s (%d) queued at %s due to %s.", finish, spellName, spellId, spellcast.queued, cleuEvent)
finished = true
end
elseif CLEU_AURA_EVENT[cleuEvent] and spellcast.auraGUID and destGUID == spellcast.auraGUID then
-- The spell is finished when the aura update is detected.
if not eventDebug then
self:DebugTimestamp("CLEU", cleuEvent, sourceName, sourceGUID, destName, destGUID, spellId, spellName)
eventDebug = true
end
self:Debug("Finished (%s) spell %s (%d) queued at %s after seeing aura %d on %s.", finish, spellName, spellId, spellcast.queued, spellcast.auraId, spellcast.auraGUID)
finished = true
end
if finished then
local now = API_GetTime()
-- Update snapshots in cached spellcasts.
if self_timeAuraAdded then
if IsSameSpellcast(spellcast, self.lastGCDSpellcast) then
self:UpdateSpellcastSnapshot(self.lastGCDSpellcast, self_timeAuraAdded)
end
if IsSameSpellcast(spellcast, self.lastOffGCDSpellcast) then
self:UpdateSpellcastSnapshot(self.lastOffGCDSpellcast, self_timeAuraAdded)
end
end
local delta = now - spellcast.stop
local targetGUID = spellcast.target
self:Debug("Spell %s (%d) was in flight for %s seconds.", spellName, spellId, delta)
-- Remove the finished spellcast from the spell queue.
tremove(self.queue, i)
self_pool:Release(spellcast)
Ovale.refreshNeeded[self_playerGUID] = true
self:SendMessage("Ovale_SpellFinished", now, spellId, targetGUID, finish)
end
return finished
end
function OvaleFuture:PLAYER_ENTERING_WORLD(event)
self:StartProfiling("OvaleFuture_PLAYER_ENTERING_WORLD")
self:Debug(event)
self:StopProfiling("OvaleFuture_PLAYER_ENTERING_WORLD")
end
function OvaleFuture:PLAYER_REGEN_DISABLED(event)
self:StartProfiling("OvaleFuture_PLAYER_REGEN_DISABLED")
self:Debug(event, "Entering combat.")
local now = API_GetTime()
self.inCombat = true
self.combatStartTime = now
Ovale.refreshNeeded[self_playerGUID] = true
self:SendMessage("Ovale_CombatStarted", now)
self:StopProfiling("OvaleFuture_PLAYER_REGEN_DISABLED")
end
function OvaleFuture:PLAYER_REGEN_ENABLED(event)
self:StartProfiling("OvaleFuture_PLAYER_REGEN_ENABLED")
self:Debug(event, "Leaving combat.")
local now = API_GetTime()
self.inCombat = false
Ovale.refreshNeeded[self_playerGUID] = true
self:SendMessage("Ovale_CombatEnded", now)
self:StopProfiling("OvaleFuture_PLAYER_REGEN_ENABLED")
end
--[[
Cast-time spell:
UNIT_SPELLCAST_SENT
UNIT_SPELLCAST_START
UNIT_SPELLCAST_DELAYED
UNIT_SPELLCAST_INTERRUPTED/UNIT_SPELLCAST_STOP/UNIT_SPELLCAST_SUCCEEDED
Instant-cast spell:
UNIT_SPELLCAST_SENT
UNIT_SPELLCAST_SUCCEEDED
Channel:
UNIT_SPELLCAST_SENT
UNIT_SPELLCAST_CHANNEL_START
UNIT_SPELLCAST_SUCCEEDED
UNIT_SPELLCAST_CHANNEL_UPDATE/UNIT_SPELLCAST_CHANNEL_STOP
--]]
function OvaleFuture:UNIT_SPELLCAST_CHANNEL_START(event, unitId, spell, rank, lineId, spellId)
if (unitId == "player" or unitId == "pet") and not WHITE_ATTACK[spellId] then
self:StartProfiling("OvaleFuture_UNIT_SPELLCAST_CHANNEL_START")
self:DebugTimestamp(event, unitId, spell, rank, lineId, spellId)
--[[
A channelled spell is actually two separate spells: a cast portion to land
the spell, and a channel portion, each with different line IDs. Find the
previous spellcast that landed the channelled spell.
--]]
local now = API_GetTime()
-- Find the matching spellcast by name -- the line ID is always zero for channelled spells.
local spellcast = self:GetSpellcast(spell, spellId, nil, now)
if spellcast then
local name, _, _, _, startTime, endTime = API_UnitChannelInfo(unitId)
if name == spell then
startTime = startTime / 1000
endTime = endTime / 1000
spellcast.channel = true
spellcast.spellId = spellId
-- Channelled spells are successful once they've started casting.
spellcast.success = now
spellcast.start = startTime
spellcast.stop = endTime
local delta = now - spellcast.queued
self:Debug("Channelling spell %s (%d): start = %s (+%s), ending = %s", spell, spellId, startTime, delta, endTime)
-- Update saved information in the spellcast to the current time.
self:SaveSpellcastInfo(spellcast, now)
-- Cache the most recent spellcast information.
self:UpdateLastSpellcast(now, spellcast)
-- Update any counters after this successful spellcast.
self:UpdateCounters(spellId, spellcast.start, spellcast.target)
OvaleScore:ScoreSpell(spellId)
Ovale.refreshNeeded[self_playerGUID] = true
elseif not name then
self:Debug("Warning: not channelling a spell.")
else
self:Debug("Warning: channelling unexpected spell %s", name)
end
else
self:Debug("Warning: channelling spell %s (%d) without previous UNIT_SPELLCAST_SENT.", spell, spellId)
end
self:StopProfiling("OvaleFuture_UNIT_SPELLCAST_CHANNEL_START")
end
end
function OvaleFuture:UNIT_SPELLCAST_CHANNEL_STOP(event, unitId, spell, rank, lineId, spellId)
if (unitId == "player" or unitId == "pet") and not WHITE_ATTACK[spellId] then
self:StartProfiling("OvaleFuture_UNIT_SPELLCAST_CHANNEL_STOP")
self:DebugTimestamp(event, unitId, spell, rank, lineId, spellId)
local now = API_GetTime()
-- Find the matching spellcast by name -- the line ID is always zero for channelled spells.
local spellcast, index = self:GetSpellcast(spell, spellId, nil, now)
if spellcast and spellcast.channel then
self:Debug("Finished channelling spell %s (%d) queued at %s.", spell, spellId, spellcast.queued)
spellcast.stop = now
self:UpdateLastSpellcast(now, spellcast)
-- Remove the finished spellcast from the spell queue.
local targetGUID = spellcast.target
tremove(self.queue, index)
self_pool:Release(spellcast)
Ovale.refreshNeeded[self_playerGUID] = true
self:SendMessage("Ovale_SpellFinished", now, spellId, targetGUID, "hit")
end
self:StopProfiling("OvaleFuture_UNIT_SPELLCAST_CHANNEL_STOP")
end
end
function OvaleFuture:UNIT_SPELLCAST_CHANNEL_UPDATE(event, unitId, spell, rank, lineId, spellId)
if (unitId == "player" or unitId == "pet") and not WHITE_ATTACK[spellId] then
self:StartProfiling("OvaleFuture_UNIT_SPELLCAST_CHANNEL_UPDATE")
self:DebugTimestamp(event, unitId, spell, rank, lineId, spellId)
local now = API_GetTime()
-- Find the matching spellcast by name -- the line ID is always zero for channelled spells.
local spellcast = self:GetSpellcast(spell, spellId, nil, now)
if spellcast and spellcast.channel then
local name, _, _, _, startTime, endTime = API_UnitChannelInfo(unitId)
if name == spell then
startTime = startTime / 1000
endTime = endTime / 1000
local delta = endTime - spellcast.stop
spellcast.start = startTime
spellcast.stop = endTime
self:Debug("Updating channelled spell %s (%d) to ending = %s (+%s).", spell, spellId, endTime, delta)
Ovale.refreshNeeded[self_playerGUID] = true
elseif not name then
self:Debug("Warning: not channelling a spell.")
else
self:Debug("Warning: delaying unexpected channelled spell %s.", name)
end
else
self:Debug("Warning: no queued, channelled spell %s (%d) found to update.", spell, spellId)
end
self:StopProfiling("OvaleFuture_UNIT_SPELLCAST_CHANNEL_UPDATE")
end
end
function OvaleFuture:UNIT_SPELLCAST_DELAYED(event, unitId, spell, rank, lineId, spellId)
if (unitId == "player" or unitId == "pet") and not WHITE_ATTACK[spellId] then
self:StartProfiling("OvaleFuture_UNIT_SPELLCAST_DELAYED")
self:DebugTimestamp(event, unitId, spell, rank, lineId, spellId)
local now = API_GetTime()
local spellcast = self:GetSpellcast(spell, spellId, lineId, now)
if spellcast then
local name, _, _, _, startTime, endTime, _, castId = API_UnitCastingInfo(unitId)
if lineId == castId and name == spell then
startTime = startTime / 1000
endTime = endTime / 1000
local delta = endTime - spellcast.stop
spellcast.start = startTime
spellcast.stop = endTime
self:Debug("Delaying spell %s (%d) to ending = %s (+%s).", spell, spellId, endTime, delta)
Ovale.refreshNeeded[self_playerGUID] = true
elseif not name then
self:Debug("Warning: not casting a spell.")
else
self:Debug("Warning: delaying unexpected spell %s.", name)
end
else
self:Debug("Warning: no queued spell %s (%d) found to delay.", spell, spellId)
end
self:StopProfiling("OvaleFuture_UNIT_SPELLCAST_DELAYED")
end
end
function OvaleFuture:UNIT_SPELLCAST_SENT(event, unitId, spell, rank, targetName, lineId)
if (unitId == "player" or unitId == "pet") and not WHITE_ATTACK_NAME[spell] then
self:StartProfiling("OvaleFuture_UNIT_SPELLCAST_SENT")
self:DebugTimestamp(event, unitId, spell, rank, targetName, lineId)
local now = API_GetTime()
local caster = OvaleGUID:UnitGUID(unitId)
local spellcast = self_pool:Get()
spellcast.lineId = lineId
spellcast.caster = caster
spellcast.spellName = spell
spellcast.queued = now
tinsert(self.queue, spellcast)
if targetName == "" then
self:Debug("Queueing (%d) spell %s with no target.", #self.queue, spell)
else
spellcast.targetName = targetName
local targetGUID, nextGUID = OvaleGUID:NameGUID(targetName)
if nextGUID then
--[[
There is more than one GUID with that name, so check if the target, focus,
or mouseover have that name and set the spellcast target's GUID to that.
--]]
local name = OvaleGUID:UnitName("target")
if name == targetName then
targetGUID = OvaleGUID:UnitGUID("target")
else
name = OvaleGUID:UnitName("focus")
if name == targetName then
targetGUID = OvaleGUID:UnitGUID("focus")
elseif API_UnitExists("mouseover") then
name = API_UnitName("mouseover")
if name == targetName then
targetGUID = API_UnitGUID("mouseover")
end
end
end
spellcast.target = targetGUID
self:Debug("Queueing (%d) spell %s to %s (possibly %s).", #self.queue, spell, targetName, targetGUID)
else
spellcast.target = targetGUID
self:Debug("Queueing (%d) spell %s to %s (%s).", #self.queue, spell, targetName, targetGUID)
end
end
--[[
Save preliminary information into the spellcast.
This will be overwritten for cast-time and channelled spells.
--]]
self:SaveSpellcastInfo(spellcast, now)
self:StopProfiling("OvaleFuture_UNIT_SPELLCAST_SENT")
end
end
function OvaleFuture:UNIT_SPELLCAST_START(event, unitId, spell, rank, lineId, spellId)
if (unitId == "player" or unitId == "pet") and not WHITE_ATTACK[spellId] then
self:StartProfiling("OvaleFuture_UNIT_SPELLCAST_START")
self:DebugTimestamp(event, unitId, spell, rank, lineId, spellId)
local now = API_GetTime()
local spellcast = self:GetSpellcast(spell, spellId, lineId, now)
if spellcast then
local name, _, _, _, startTime, endTime, _, castId = API_UnitCastingInfo(unitId)
if lineId == castId and name == spell then
startTime = startTime / 1000
endTime = endTime / 1000
spellcast.spellId = spellId
spellcast.start = startTime
spellcast.stop = endTime
spellcast.channel = false
local delta = now - spellcast.queued
self:Debug("Casting spell %s (%d): start = %s (+%s), ending = %s.", spell, spellId, startTime, delta, endTime)
local auraId, auraGUID = self:GetAuraFinish(spell, spellId, spellcast.target, now)
if auraId and auraGUID then
spellcast.auraId = auraId
spellcast.auraGUID = auraGUID
self:Debug("Spell %s (%d) will finish after updating aura %d on %s.", spell, spellId, auraId, auraGUID)
end
-- Update saved information in the spellcast to the current time.
self:SaveSpellcastInfo(spellcast, now)
OvaleScore:ScoreSpell(spellId)
Ovale.refreshNeeded[self_playerGUID] = true
elseif not name then
self:Debug("Warning: not casting a spell.")
else
self:Debug("Warning: casting unexpected spell %s.", name)
end
else
self:Debug("Warning: casting spell %s (%d) without previous sent data.", spell, spellId)
end
self:StopProfiling("OvaleFuture_UNIT_SPELLCAST_START")
end
end
function OvaleFuture:UNIT_SPELLCAST_SUCCEEDED(event, unitId, spell, rank, lineId, spellId)
if (unitId == "player" or unitId == "pet") and not WHITE_ATTACK[spellId] then
self:StartProfiling("OvaleFuture_UNIT_SPELLCAST_SUCCEEDED")
self:DebugTimestamp(event, unitId, spell, rank, lineId, spellId)
local now = API_GetTime()
local spellcast, index = self:GetSpellcast(spell, spellId, lineId, now)
if spellcast then
local success = false
if not spellcast.success and spellcast.start and spellcast.stop and not spellcast.channel then
self:Debug("Succeeded casting spell %s (%d) at %s, now in flight.", spell, spellId, spellcast.stop)
spellcast.success = now
-- Take a more recent snapshot of the player stats for this cast-time spell.
self:UpdateSpellcastSnapshot(spellcast, now)
success = true
else
--[[
This spell was an instant-cast spell, but check that it's not also a
channelled spell.
]]--
local name = API_UnitChannelInfo(unitId)
if not name then
local now = API_GetTime()
spellcast.spellId = spellId
spellcast.start = now
spellcast.stop = now
spellcast.channel = false
spellcast.success = now
local delta = now - spellcast.queued
self:Debug("Instant-cast spell %s (%d): start = %s (+%s).", spell, spellId, now, delta)
local auraId, auraGUID = self:GetAuraFinish(spell, spellId, spellcast.target, now)
if auraId and auraGUID then
spellcast.auraId = auraId
spellcast.auraGUID = auraGUID
self:Debug("Spell %s (%d) will finish after updating aura %d on %s.", spell, spellId, auraId, auraGUID)
end
-- Update saved information in the spellcast to the current time.
self:SaveSpellcastInfo(spellcast, now)
OvaleScore:ScoreSpell(spellId)
success = true
else
self:Debug("Succeeded casting spell %s (%d) but it is channelled.", spell, spellId)
end
end
if success then
local targetGUID = spellcast.target
-- Cache the most recent spellcast information.
self:UpdateLastSpellcast(now, spellcast)
-- Update any counters after this successful spellcast.
self:UpdateCounters(spellId, spellcast.stop, targetGUID)
-- Some spells finish upon successful spellcast.
local finished = false
local finish = "miss"
if not spellcast.targetName then
-- If the spell has no target, then it finishes upon cast.
self:Debug("Finished spell %s (%d) with no target queued at %s.", spell, spellId, spellcast.queued)
finished = true
finish = "hit"
elseif targetGUID == self_playerGUID and OvaleSpellBook:IsHelpfulSpell(spellId) then
-- If a helpful spell is cast by the player on the player, then it finishes upon cast.
self:Debug("Finished helpful spell %s (%d) cast on player queued at %s.", spell, spellId, spellcast.queued)
finished = true
finish = "hit"
end
if finished then
-- Remove the finished spellcast from the spell queue.
tremove(self.queue, index)
self_pool:Release(spellcast)
Ovale.refreshNeeded[self_playerGUID] = true
self:SendMessage("Ovale_SpellFinished", now, spellId, targetGUID, finish)
end
end
else
self:Debug("Warning: no queued spell %s (%d) found to successfully complete casting.", spell, spellId)
end
self:StopProfiling("OvaleFuture_UNIT_SPELLCAST_SUCCEEDED")
end
end
function OvaleFuture:Ovale_AuraAdded(event, atTime, guid, auraId, caster)
if guid == self_playerGUID then
self_timeAuraAdded = atTime
-- Update snapshots in cached spellcasts.
self:UpdateSpellcastSnapshot(self.lastGCDSpellcast, atTime)
self:UpdateSpellcastSnapshot(self.lastOffGCDSpellcast, atTime)
end
end
function OvaleFuture:UnitSpellcastEnded(event, unitId, spell, rank, lineId, spellId)
if (unitId == "player" or unitId == "pet") and not WHITE_ATTACK[spellId] then
self:StartProfiling("OvaleFuture_UnitSpellcastEnded")
self:DebugTimestamp(event, unitId, spell, rank, lineId, spellId)
local now = API_GetTime()
local spellcast, index = self:GetSpellcast(spell, spellId, lineId, now)
if spellcast then
self:Debug("End casting spell %s (%d) queued at %s due to %s.", spell, spellId, spellcast.queued, event)
--[[
Remove this spellcast only if it was not successful.
Successful spellcasts wait for CLEU finishing events.
--]]
if not spellcast.success then
tremove(self.queue, index)
self_pool:Release(spellcast)
Ovale.refreshNeeded[self_playerGUID] = true
end
elseif lineId then
-- Suppress the warning spellcasts with a line ID of zero since those are thrown quite a lot.
self:Debug("Warning: no queued spell %s (%d) found to end casting.", spell, spellId)
end
self:StopProfiling("OvaleFuture_UnitSpellcastEnded")
end
end
--[[-------
Methods
--]]-------
--[[
Find the queued spellcast of the given spell.
If the line ID is given, then match the oldest queued spellcast of that spell with the given line ID.
Otherwise, match the the oldest queued spellcast of that spell.
--]]
function OvaleFuture:GetSpellcast(spell, spellId, lineId, atTime)
self:StartProfiling("OvaleFuture_GetSpellcast")
local spellcast, index
if not lineId or lineId ~= "" then
for i, sc in ipairs(self.queue) do
if not lineId or sc.lineId == lineId then
if spellId and sc.spellId == spellId then
spellcast = sc
index = i
break
elseif spell then
local spellName = sc.spellName or OvaleSpellBook:GetSpellName(spellId)
if spell == spellName then
spellcast = sc
index = i
break
end
end
end
end
end
if spellcast then
local spellName = spell or spellcast.spellName or OvaleSpellBook:GetSpellName(spellId)
if spellcast.targetName then
self:Debug("Found spellcast for %s to %s queued at %f.", spellName, spellcast.targetName, spellcast.queued)
else
self:Debug("Found spellcast for %s with no target queued at %f.", spellName, spellcast.queued)
end
end
self:StopProfiling("OvaleFuture_GetSpellcast")
return spellcast, index
end
--[[
Return the aura ID of one of the auras, if any, that are added or refreshed by the spell
and the GUID on which the aura appears.
--]]
function OvaleFuture:GetAuraFinish(spell, spellId, targetGUID, atTime)
self:StartProfiling("OvaleFuture_GetAuraFinish")
local auraId, auraGUID
local si = OvaleData.spellInfo[spellId]
if si and si.aura then
for _, unitId in ipairs(SPELLCAST_AURA_ORDER) do
for filter, auraList in pairs(si.aura[unitId]) do
for id, spellData in pairs(auraList) do
local verified, value, data = OvaleData:CheckSpellAuraData(id, spellData, atTime, targetGUID)
if verified and (SPELLAURALIST_AURA_VALUE[value] or type(value) == "number" and value > 0) then
auraId = id
auraGUID = OvaleGUID:UnitGUID(unitId)
break
end
end
if auraId then break end
end
if auraId then break end
end
end
self:StopProfiling("OvaleFuture_GetAuraFinish")
return auraId, auraGUID
end
-- Register functions for saving and copying module-specific information into and from spellcasts.
function OvaleFuture:RegisterSpellcastInfo(mod)
tinsert(self_modules, mod)
end
-- Unregister functions for saving and copying module-specific information into and from spellcasts.
function OvaleFuture:UnregisterSpellcastInfo(mod)
for i = #self_modules, 1, -1 do
if self_modules[i] == mod then
tremove(self_modules, i)
end
end
end
-- Copy information from the spellcast into the destination table.
function OvaleFuture:CopySpellcastInfo(spellcast, dest)
self:StartProfiling("OvaleFuture_CopySpellcastInfo")
if spellcast.damageMultiplier then
dest.damageMultiplier = spellcast.damageMultiplier
end
-- Copy the module-specific information from the spellcast to the destination.
for _, mod in pairs(self_modules) do
local func = mod.CopySpellcastInfo
if func then
func(mod, spellcast, dest)
end
end
self:StopProfiling("OvaleFuture_CopySpellcastInfo")
end
-- Save information from the given time into the spellcast.
function OvaleFuture:SaveSpellcastInfo(spellcast, atTime)
self:StartProfiling("OvaleFuture_SaveSpellcastInfo")
self:Debug(" Saving information from %s to the spellcast for %s.", atTime, spellcast.spellName)
if spellcast.spellId then
spellcast.damageMultiplier = OvaleFuture:GetDamageMultiplier(spellcast.spellId, spellcast.target, atTime)
end
-- Save the module-specific information into the spellcast.
for _, mod in pairs(self_modules) do
local func = mod.SaveSpellcastInfo
if func then
func(mod, spellcast, atTime)
end
end
self:StopProfiling("OvaleFuture_SaveSpellcastInfo")
end
--[[
Return the spell-specific damage multiplier using the information from
SpellDamage{Buff,Debuff} declarations.
NOTE: Mirrored in statePrototype below.
--]]
function OvaleFuture:GetDamageMultiplier(spellId, targetGUID, atTime)
atTime = atTime or self["currentTime"] or API_GetTime()
local damageMultiplier = 1
local si = OvaleData.spellInfo[spellId]
if si and si.aura and si.aura.damage then
-- Get references to mirrored methods used.
local CheckRequirements
local GetAuraByGUID, IsActiveAura
local auraModule, dataModule
CheckRequirements, dataModule = self:GetMethod("CheckRequirements", OvaleData)
GetAuraByGUID, auraModule = self:GetMethod("GetAuraByGUID", OvaleAura)
IsActiveAura, auraModule = self:GetMethod("IsActiveAura", OvaleAura)
for filter, auraList in pairs(si.aura.damage) do
for auraId, spellData in pairs(auraList) do
local index, multiplier
if type(spellData) == "table" then
-- Comma-separated value.
multiplier = spellData[1]
index = 2
else
multiplier = spellData
end
local verified
if index then
verified = CheckRequirements(dataModule, spellId, atTime, spellData, index, targetGUID)
else
verified = true
end
if verified then
local aura = GetAuraByGUID(auraModule, self_playerGUID, auraId, filter)
local isActiveAura = IsActiveAura(auraModule, aura, atTime)
if isActiveAura then
local siAura = OvaleData.spellInfo[auraId]
-- If an aura does stacking damage, then it needs to set stacking=1.
if siAura and siAura.stacking and siAura.stacking > 0 then
multiplier = 1 + (multiplier - 1) * aura.stacks
end
damageMultiplier = damageMultiplier * multiplier
end
end
end
end
end
return damageMultiplier
end
--[[
Update counters for this spellcast.
NOTE: Mirrored in statePrototype below.
--]]
function OvaleFuture:UpdateCounters(spellId, atTime, targetGUID)
local inccounter = OvaleData:GetSpellInfoProperty(spellId, atTime, "inccounter", targetGUID)
if inccounter then
local value = self.counter[inccounter] and self.counter[inccounter] or 0
self.counter[inccounter] = value + 1
end
local resetcounter = OvaleData:GetSpellInfoProperty(spellId, atTime, "resetcounter", targetGUID)
if resetcounter then
self.counter[resetcounter] = 0
end
end
--[[
Returns true if the spell is active.
An active spell is one that queued and has started casting.
--]]
function OvaleFuture:IsActive(spellId)
for _, spellcast in ipairs(self.queue) do
if spellcast.spellId == spellId and spellcast.start then
return true
end
end
return false
end
-- Deprecated function OvaleFuture:InFlight() aliased to "IsActive".
OvaleFuture.InFlight = OvaleFuture.IsActive
-- Return the most recent successful spellcast.
function OvaleFuture:LastInFlightSpell()
local spellcast
if self.lastGCDSpellcast.success then
spellcast = self.lastGCDSpellcast
end
for i = #self.queue, 1, -1 do
local sc = self.queue[i]
if sc.success then
-- Use the more recently successful spellcast.
if not spellcast or spellcast.success < sc.success then
spellcast = sc
end
break
end
end
return spellcast
end
-- Return the most recent spellcast sent.
-- Required when the UNIT_AURA event fires before the UNIT_SPELLCAST_SUCCEEDED event
function OvaleFuture:LastSpellSent()
local spellcast = nil
if self.lastGCDSpellcast.success then
spellcast = self.lastGCDSpellcast