-
-
Notifications
You must be signed in to change notification settings - Fork 222
/
Targets.lua
1512 lines (1160 loc) · 45.8 KB
/
Targets.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
-- Targets.lua
-- July 2024
local addon, ns = ...
local Hekili = _G[addon]
local class = Hekili.Class
local state = Hekili.State
local FindUnitBuffByID = ns.FindUnitBuffByID
local FindUnitDebuffByID = ns.FindUnitDebuffByID
local FindExclusionAuraByID
local targetCount = 0
local targets = {}
local myTargetCount = 0
local myTargets = {}
local addMissingTargets = true
local counted = {}
local formatKey = ns.formatKey
local orderedPairs = ns.orderedPairs
local FeignEvent, RegisterEvent = ns.FeignEvent, ns.RegisterEvent
local format = string.format
local insert, remove, wipe = table.insert, table.remove, table.wipe
local unitIDs = { "target", "targettarget", "focus", "focustarget", "boss1", "boss2", "boss3", "boss4", "boss5", "arena1", "arena2", "arena3", "arena4", "arena5" }
local npGUIDs = {}
local npUnits = {}
Hekili.unitIDs = unitIDs
Hekili.npGUIDs = npGUIDs
Hekili.npUnits = npUnits
function Hekili:GetNameplateUnitForGUID( id )
return npUnits[ id ]
end
function Hekili:GetGUIDForNameplateUnit( unit )
return npGUIDs[ unit ]
end
function Hekili:GetUnitByGUID( id )
for _, unit in ipairs( unitIDs ) do
if UnitGUID( unit ) == id then return unit end
end
end
function Hekili:GetUnitByName( name )
for _, unit in ipairs( unitIDs ) do
if UnitName( unit ) == name then return unit end
end
for unit in pairs( npUnits ) do
if UnitName( unit ) == name then return unit end
end
end
do
-- Pet-Based Target Detection
-- Requires a class-appropriate pet ability on the player's action bars.
-- ** Not the pet's action bar. **
local petAction = 0
local petSlot = 0
local myClass = UnitClassBase( "player" )
local petSpells = {
HUNTER = {
[288962] = 10,
[17253] = 5,
[16827] = 5,
[159953] = 5,
[49966] = 5,
[263863] = 7,
[50433] = 7,
[24423] = 7,
[160060] = 7,
[50285] = 7,
[263840] = 7,
[263856] = 7,
[263861] = 7,
[279362] = 7,
[160018] = 7,
[263853] = 7,
[263423] = 7,
[54680] = 7,
[344352] = 7,
[50245] = 7,
[263857] = 7,
[263854] = 7,
[263852] = 7,
[160065] = 7,
[263858] = 7,
[341118] = 7,
[35346] = 7,
[160067] = 7,
best = 288962,
count = 28
},
WARLOCK = {
[6360] = 10,
[7814] = 7,
[30213] = 7,
[115625] = 7,
[54049] = 7,
[115778] = 7,
best = 6360,
count = 6
}
}
function Hekili:GetPetBasedTargetSpells()
return petSpells[ myClass ]
end
function Hekili:CanUsePetBasedTargetDetection()
return petSpells[ myClass ] ~= nil
end
function Hekili:HasPetBasedTargetSpell()
return petSlot > 0
end
function Hekili:GetPetBasedTargetSpell()
return petAction > 0 and petAction or nil
end
function Hekili:PetBasedTargetDetectionIsReady( skipRange )
if petSlot == 0 then return false, "Pet action not found in player action bars." end
if not UnitExists( "pet" ) then return false, "No active pet." end
if UnitIsDead( "pet" ) then return false, "Pet is dead." end
-- If we have a target and the target is out of our pet's range, don't use pet detection.
if not skipRange and UnitExists( "target" ) and not IsActionInRange( petSlot ) then return false, "Player has target and player's target not in range of pet." end
return true
end
function Hekili:SetupPetBasedTargetDetection()
petAction = 0
petSlot = 0
if not self:CanUsePetBasedTargetDetection() then return end
local spells = petSpells[ myClass ]
local success = false
for i = 1, 180 do
local slotType, spell = GetActionInfo( i )
if slotType and spell and spells[ spell ] then
petAction = spell
petSlot = i
return true
end
end
return success
end
function Hekili:TargetIsNearPet( unit )
return IsActionInRange( petSlot, unit )
end
function Hekili:DumpPetBasedTargetInfo()
self:Print( petAction, petSlot )
end
end
-- Excluding enemy by NPC ID (as string). This keeps the enemy from being counted if they are not your target.
-- = true Always Exclude
-- = number < 0 Exclude if debuff ID abs( number ) is active on unit.
-- = number > 0 Exclude if buff ID number is active on unit.
local enemyExclusions = {
[23775] = true, -- Head of the Horseman
[120651] = true, -- Explosives
[156227] = true, -- Neferset Denizen
[160966] = true, -- Thing from Beyond?
[161895] = true, -- Thing from Beyond?
[157452] = true, -- Nightmare Antigen in Carapace
[158041] = 310126, -- N'Zoth with Psychic Shell
[164698] = true, -- Tor'ghast Junk
[177117] = 355790, -- Ner'zhul: Orb of Torment (Protected by Eternal Torment)
[176581] = true, -- Painsmith: Spiked Ball
[186150] = true, -- Soul Fragment (Gavel of the First Arbiter)
[185685] = true, -- Season 3 Relics
[185680] = true, -- Season 3 Relics
[185683] = true, -- Season 3 Relics
[183501] = 367573, -- Xy'mox: Genesis Bulwark
[166969] = true, -- Frieda
[166970] = true, -- Stavros
[166971] = true, -- Niklaus
[168113] = 329606, -- Grashaal (when shielded)
[168112] = 329636, -- Kaal (when shielded)
[193760] = true, -- Surging Ruiner (Raszageth) -- gives bad range information.
[204560] = true, -- Incorporeal Being
[229296] = true -- Orb of Ascendance (TWW S1 Affix)
}
local requiredForInclusion = {
[131825] = 260805, -- Focusing Iris (damage on others is wasted)
[131823] = 260805, -- Same
[131824] = 206805, -- Same
}
if Hekili.IsDev then
-- Add these exclusions only in development copies, until a solution is built for funnelers vs. non-funnelers.
enemyExclusions[202971] = 404705 -- Null Glimmer
enemyExclusions[202969] = 404705 -- Empty Recollection
end
RegisterEvent( "NAME_PLATE_UNIT_ADDED", function( event, unit )
local id = UnitGUID( unit )
if UnitIsFriend( "player", unit ) then
npGUIDs[ unit ] = nil
npUnits[ id ] = nil
return
end
npGUIDs[ unit ] = id
npUnits[ id ] = unit
end )
RegisterEvent( "NAME_PLATE_UNIT_REMOVED", function( event, unit )
local storedGUID = npGUIDs[ unit ]
local id = UnitGUID( unit )
npGUIDs[ unit ] = nil
if npUnits[ id ] and npUnits[ id ] == unit then npUnits[ id ] = nil end
if npUnits[ storedGUID ] and npUnits[ storedGUID ] == unit then npUnits[ storedGUID ] = nil end
end )
RegisterEvent( "UNIT_FLAGS", function( event, unit )
if unit == "player" or UnitIsUnit( unit, "player" ) then return end
if UnitIsFriend( "player", unit ) then
local id = UnitGUID( unit )
ns.eliminateUnit( id )
npGUIDs[ unit ] = nil
npUnits[ id ] = nil
end
end )
local RC = LibStub( "LibRangeCheck-3.0" )
local LSR = LibStub( "SpellRange-1.0" )
local lastCount = 1
local lastStationary = 1
-- Chromie Time impacts phasing as well.
local chromieTime = false
do
local IsPlayerInChromieTime = C_PlayerInfo.IsPlayerInChromieTime
local function UpdateChromieTime()
chromieTime = IsPlayerInChromieTime()
end
local function ChromieCheck( self, event, login, reload )
if event ~= "PLAYER_ENTERING_WORLD" or login or reload then
chromieTime = IsPlayerInChromieTime()
C_Timer.After( 2, UpdateChromieTime )
end
end
if not Hekili.IsDragonflight() then
RegisterEvent( "CHROMIE_TIME_OPEN", ChromieCheck )
RegisterEvent( "CHROMIE_TIME_CLOSE", ChromieCheck )
end
RegisterEvent( "PLAYER_ENTERING_WORLD", ChromieCheck )
end
-- War Mode
local warmode = false
do
local function CheckWarMode( event, login, reload )
if event ~= "PLAYER_ENTERING_WORLD" or login or reload then
warmode = C_PvP.IsWarModeDesired()
end
end
RegisterEvent( "UI_INFO_MESSAGE", CheckWarMode )
RegisterEvent( "PLAYER_ENTERING_WORLD", CheckWarMode )
end
local function UnitInPhase( unit )
local reason = UnitPhaseReason( unit )
local wm = not IsInInstance() and warmode
if reason == 3 and chromieTime then return true end
if reason == 2 and wm then return true end
if reason == nil then return true end
return false
end
--[[
For targeting, let's keep more of the settings static to reduce overhead with target counting.
We have:
1. Count Nameplates
- Spell
- Filter UnitAffectingCombat
-
]]--
do
function ns.iterateTargets()
return next, counted, nil
end
FindExclusionAuraByID = function( unit, spellID )
if spellID < 0 then
return FindUnitDebuffByID( unit, -1 * spellID ) ~= nil
end
return FindUnitBuffByID( unit, spellID ) ~= nil
end
-- New Nameplate Proximity System
function ns.getNumberTargets( forceUpdate )
if not forceUpdate then
return lastCount, lastStationary
end
local debugging = true
local details = nil
local showNPs = GetCVar( "nameplateShowEnemies" ) == "1" and GetCVar( "nameplateShowAll" ) == "1"
wipe( counted )
local count, stationary = 0, 0
if debugging then details = format( "Nameplates are %s.", showNPs and "enabled" or "disabled" ) end
local spec = state.spec.id
spec = spec and rawget( Hekili.DB.profile.specs, spec )
local inRaid = IsInRaid()
local inGroup = GetNumGroupMembers() > 0
local FriendCheck = inRaid and UnitInRaid or UnitInParty
local checkPets = showNPs and spec and spec.petbased and Hekili:PetBasedTargetDetectionIsReady()
-- local filterPlates = showNPs and spec and spec.rangeFilter and class.specs[ state.spec.id ].rangeFilter
local checkPlates = showNPs and spec and spec.nameplates and ( spec.nameplateRange or class.specs[ state.spec.id ].nameplateRange or 10 )
--[[ if rangeCheck == "Auto" then
rangeChecker = spec.ranges.Auto[2]
rangeCheck = true
else
rangeChecker = spec.ranges[ rangeCheck ][ 1 ]
end ]]
if spec then
if checkPets or checkPlates then
for unit, guid in pairs( npGUIDs ) do
if UnitExists( unit ) and not UnitIsDead( unit ) and UnitCanAttack( "player", unit ) and UnitInPhase( unit ) and UnitHealth( unit ) > 1 and ( not inGroup or not FriendCheck( unit ) ) and ( UnitIsPVP( "player" ) or not UnitIsPlayer( unit ) ) then
local excluded = not UnitIsUnit( unit, "target" )
local npcid = guid:match( "(%d+)-%x-$" )
npcid = tonumber( npcid )
local _, range = nil, -1
if debugging then details = format( "%s\n - Checking nameplate list for %s [ %s ] %s.", details, unit, guid, UnitName( unit ) ) end
if excluded then
if requiredForInclusion[ npcid ] then
excluded = not FindExclusionAuraByID( unit, requiredForInclusion[ npcid ] )
else
excluded = enemyExclusions[ npcid ]
end
-- If our table has a number, unit is ruled out only if the buff is present.
if excluded and type( excluded ) == "number" then
excluded = FindExclusionAuraByID( unit, excluded )
if debugging and excluded then
details = format( "%s\n - Excluded by aura.", details )
end
end
if not excluded and checkPets then
excluded = not Hekili:TargetIsNearPet( unit )
if debugging and excluded then
details = format( "%s\n - Excluded by pet range.", details )
end
end
if not excluded and checkPlates then
local _, maxR = RC:GetRange( unit )
excluded = maxR ~= nil and maxR > checkPlates
if debugging and excluded then
details = format( "%s\n - Excluded by range (%d > %d).", details, maxR, checkPlates )
end
end
if not excluded and showNPs and spec.damageOnScreen and not npUnits[ guid ] then
excluded = true
if debugging then details = format( "%s\n - Excluded by on-screen nameplate requirement.", details ) end
end
end
if not excluded then
local rate, n = Hekili:GetTTD( unit )
count = count + 1
counted[ guid ] = true
local moving = GetUnitSpeed( unit ) > 0
if not moving then
stationary = stationary + 1
end
if debugging then details = format( "%s\n %-12s - %2d - %s - %.2f - %d - %s %s\n", details, unit, range or -1, guid, rate or -1, n or -1, unit and UnitName( unit ) or "Unknown", ( moving and "(moving)" or "" ) ) end
end
end
counted[ guid ] = counted[ guid ] or false
end
for _, unit in ipairs( unitIDs ) do
local guid = UnitGUID( unit )
if guid and counted[ guid ] == nil then
if UnitExists( unit ) and not UnitIsDead( unit ) and UnitCanAttack( "player", unit ) and UnitAffectingCombat( unit ) and UnitInPhase( unit ) and UnitHealth( unit ) > 1 and ( not inGroup or not FriendCheck( unit ) ) and ( UnitIsPVP( "player" ) or not UnitIsPlayer( unit ) ) then
local excluded = not UnitIsUnit( unit, "target" )
local npcid = guid:match( "(%d+)-%x-$" )
npcid = tonumber(npcid)
local _, range = nil, -1
if debugging then details = format( "%s\n - Checking %s [ %s ] %s.", details, unit, guid, UnitName( unit ) ) end
if excluded then
excluded = enemyExclusions[ npcid ]
-- If our table has a number, unit is ruled out only if the buff is present.
if excluded and type( excluded ) == "number" then
excluded = FindExclusionAuraByID( unit, excluded )
if debugging and excluded then
details = format( "%s\n - Excluded by aura.", details )
end
end
if not excluded and checkPets then
excluded = not Hekili:TargetIsNearPet( unit )
if debugging and excluded then
details = format( "%s\n - Excluded by pet range.", details )
end
end
if not excluded and checkPlates then
local _, maxR = RC:GetRange( unit )
excluded = maxR ~= nil and maxR > checkPlates
if debugging and excluded then
details = format( "%s\n - Excluded by range (%d > %d).", details, maxR, checkPlates )
end
end
if not excluded and spec.damageOnScreen and showNPs and not npUnits[ guid ] then
excluded = true
if debugging then details = format( "%s\n - Excluded by on-screen nameplate requirement.", details ) end
end
end
if not excluded then
local rate, n = Hekili:GetTTD(unit)
count = count + 1
counted[ guid ] = true
local moving = GetUnitSpeed( unit ) > 0
if not moving then
stationary = stationary + 1
end
if debugging then details = format( "%s\n %-12s - %2d - %s - %.2f - %d - %s %s\n", details, unit, range or -1, guid, rate or -1, n or -1, unit and UnitName( unit ) or "Unknown", ( moving and "(moving)" or "" ) ) end
end
counted[ guid ] = counted[ guid ] or false
end
end
end
end
end
if not spec or spec.damage or not checkPets and not checkPlates then
local db = spec and (spec.myTargetsOnly and myTargets or targets) or targets
for guid, seen in pairs(db) do
if counted[ guid ] == nil then
local npcid = guid:match("(%d+)-%x-$")
npcid = tonumber(npcid)
local range
local unit = Hekili:GetUnitByGUID( guid ) or UnitTokenFromGUID( guid )
local excluded = false
if unit and not UnitIsUnit( unit, "target" ) then
excluded = enemyExclusions[ npcid ]
if debugging then details = format( "%s\n - Checking %s [ %s ] #%s.", details, unit, guid, UnitName( unit ) ) end
-- If our table has a number, unit is ruled out only if the buff is present.
if excluded and type( excluded ) == "number" then
excluded = FindExclusionAuraByID( unit, excluded )
if debugging and excluded then
details = format( "%s\n - Excluded by aura.", details )
end
end
if not excluded and inGroup and FriendCheck( unit ) then
excluded = true
if debugging then details = format( "%s\n - Excluded by friend check.", details ) end
end
if not excluded and checkPets then
excluded = not Hekili:TargetIsNearPet( unit )
if debugging and excluded then
details = format( "%s\n - Excluded by pet range.", details )
end
end
end
if not excluded and spec.damageOnScreen and showNPs and not npUnits[ guid ] then
excluded = true
if debugging then details = format( "%s\n - Excluded by on-screen nameplate requirement.", details ) end
end
if not excluded then
count = count + 1
counted[ guid ] = true
local moving = unit and GetUnitSpeed( unit ) > 0
if not moving then
stationary = stationary + 1
end
if debugging then details = format("%s\n %-12s - %s %s\n", details, "dmg", guid, ( moving and "(moving)" or "" ) ) end
else
counted[ guid ] = false
end
end
end
end
local targetGUID = UnitGUID( "target" )
if targetGUID then
if counted[ targetGUID ] == nil and UnitExists( "target" ) and not UnitIsDead( "target" ) and UnitCanAttack( "player", "target" ) and UnitInPhase( "target" ) and ( UnitIsPVP( "player" ) or not UnitIsPlayer( "target" ) ) then
count = count + 1
counted[ targetGUID ] = true
local moving = GetUnitSpeed( "target" ) > 0
if not moving then
stationary = stationary + 1
end
if debugging then details = format("%s\n %-12s - %2d - %s %s\n", details, "target", 0, targetGUID, ( moving and "(moving)" or "" ) ) end
else
counted[ targetGUID ] = false
end
end
count = max( 1, count )
if count ~= lastCount or stationary ~= lastStationary then
lastCount = count
lastStationary = stationary
if Hekili:GetToggleState( "mode" ) == "reactive" then HekiliDisplayAOE:UpdateAlpha() end
end
if details then
Hekili.TargetDebug = details
end
return count, stationary
end
end
function Hekili:GetNumTargets( forceUpdate )
return ns.getNumberTargets( forceUpdate )
end
function ns.dumpNameplateInfo()
return counted
end
function ns.updateTarget( id, time, mine )
local spec = rawget( Hekili.DB.profile.specs, state.spec.id )
if not spec or not spec.damage then return end
if id == state.GUID then
return
end
if time then
if not targets[id] then
targetCount = targetCount + 1
targets[id] = time
ns.updatedTargetCount = true
else
targets[id] = time
end
if mine then
if not myTargets[id] then
myTargetCount = myTargetCount + 1
myTargets[id] = time
ns.updatedTargetCount = true
else
myTargets[id] = time
end
end
else
if state.empowerment.start > 0 and state.empowerment.finish > GetTime() then
-- Don't expire targets mid-empowerment cast.
return
end
if targets[id] then
targetCount = max( 0, targetCount - 1 )
targets[id] = nil
end
if myTargets[id] then
myTargetCount = max( 0, myTargetCount - 1 )
myTargets[id] = nil
end
ns.updatedTargetCount = true
end
end
ns.reportTargets = function()
for k, v in pairs(targets) do
Hekili:Print("Saw " .. k .. " exactly " .. GetTime() - v .. " seconds ago.")
end
end
ns.numTargets = function()
return targetCount > 0 and targetCount or 1
end
ns.numMyTargets = function()
return myTargetCount > 0 and myTargetCount or 1
end
ns.isTarget = function(id)
return targets[id] ~= nil
end
ns.isMyTarget = function(id)
return myTargets[id] ~= nil
end
-- MINIONS
local minions = {}
ns.updateMinion = function(id, time)
minions[id] = time
end
ns.isMinion = function(id)
return minions[id] ~= nil or UnitGUID("pet") == id
end
function Hekili:HasMinionID(id)
for k, v in pairs(minions) do
local npcID = tonumber(k:match("%-(%d+)%-[0-9A-F]+$"))
if npcID == id and v > state.now then
return true, v
end
end
end
function Hekili:DumpMinions()
local o = ""
for k, v in orderedPairs(minions) do
o = o .. k .. " " .. tostring(v) .. "\n"
end
return o
end
local debuffs = {}
local debuffCount = {}
local debuffMods = {}
function ns.saveDebuffModifier( id, val )
debuffMods[ id ] = val
end
ns.wipeDebuffs = function()
for k, _ in pairs(debuffs) do
table.wipe(debuffs[k])
debuffCount[k] = 0
end
end
ns.actorHasDebuff = function( target, spell )
return ( debuffs[ spell ] and debuffs[ spell ][ target ] ~= nil ) or false
end
ns.trackDebuff = function(spell, target, time, application)
debuffs[spell] = debuffs[spell] or {}
debuffCount[spell] = debuffCount[spell] or 0
if not time then
if debuffs[spell][target] then
-- Remove it.
debuffs[spell][target] = nil
debuffCount[spell] = max( 0, debuffCount[spell] - 1 )
end
else
if not debuffs[spell][target] then
debuffs[spell][target] = {}
debuffCount[spell] = debuffCount[spell] + 1
end
local debuff = debuffs[spell][target]
debuff.last_seen = time
debuff.applied = debuff.applied or time
if application then
debuff.pmod = debuffMods[spell]
else
debuff.pmod = debuff.pmod or 1
end
end
end
ns.GetDebuffApplicationTime = function( spell, target )
if not debuffCount[ spell ] or debuffCount[ spell ] == 0 then return 0 end
return debuffs[ spell ] and debuffs[ spell ][ target ] and ( debuffs[ spell ][ target ].applied or debuffs[ spell ][ target ].last_seen ) or 0
end
function ns.getModifier( id, target )
local debuff = debuffs[ id ]
if not debuff then
return 1
end
local app = debuff[target]
if not app then
return 1
end
return app.pmod or 1
end
ns.numDebuffs = function(spell)
return debuffCount[spell] or 0
end
ns.compositeDebuffCount = function( ... )
local n = 0
for i = 1, select("#", ...) do
local debuff = select( i, ... )
debuff = class.auras[ debuff ] and class.auras[ debuff ].id
debuff = debuff and debuffs[ debuff ]
if debuff then
for unit in pairs(debuff) do
n = n + 1
end
end
end
return n
end
ns.conditionalDebuffCount = function(req1, req2, req3, ...)
local n = 0
req1 = class.auras[req1] and class.auras[req1].id
req2 = class.auras[req2] and class.auras[req2].id
req3 = class.auras[req3] and class.auras[req3].id
for i = 1, select("#", ...) do
local debuff = select(i, ...)
debuff = class.auras[debuff] and class.auras[debuff].id
debuff = debuff and debuffs[debuff]
if debuff then
for unit in pairs(debuff) do
if (req1 and debuffs[req1] and debuffs[req1][unit]) or (req2 and debuffs[req2] and debuffs[req2][unit]) or (req3 and debuffs[req3] and debuffs[req3][unit]) then
n = n + 1
end
end
end
end
return n
end
do
local counted = {}
-- Useful for "count number of enemies with at least one of these debuffs applied".
-- i.e., poisoned_enemies for Assassination Rogue.
ns.countUnitsWithDebuffs = function( ... )
wipe( counted )
local n = 0
for i = 1, select("#", ...) do
local debuff = select( i, ... )
debuff = class.auras[ debuff ] and class.auras[ debuff ].id
debuff = debuff and debuffs[ debuff ]
if debuff then
for unit in pairs( debuff ) do
if not counted[ unit ] then
n = n + 1
counted[ unit ] = true
end
end
end
end
return n
end
end
ns.isWatchedDebuff = function(spell)
return debuffs[spell] ~= nil
end
ns.eliminateUnit = function( id, force )
ns.updateMinion(id)
ns.updateTarget(id)
if force then
for k, v in pairs( debuffs ) do
if v[ id ] then
ns.trackDebuff( k, id )
end
end
end
ns.callHook( "UNIT_ELIMINATED", id )
end
do
local damage = {
[1] = 0,
[5] = 0,
[10] = 0,
}
local physical = {
[1] = 0,
[5] = 0,
[10] = 0
}
local magical = {
[1] = 0,
[5] = 0,
[10] = 0
}
local healing = {
[1] = 0,
[5] = 0,
[10] = 0
}
ns.storeDamage = function( _, dam, isPhysical )
if dam and dam > 0 then
local db = isPhysical and physical or magical
db[ 1 ] = db[ 1 ] + dam
damage[ 1 ] = damage[ 1 ] + dam
C_Timer.After( 1, function()
db[ 1 ] = db[ 1 ] - dam
damage[ 1 ] = damage[ 1 ] - dam
end )
db[ 5 ] = db[ 5 ] + dam
damage[ 5 ] = damage[ 5 ] + dam
C_Timer.After( 5, function()
db[ 5 ] = db[ 5 ] - dam
damage[ 5 ] = damage[ 5 ] - dam
end )
db[ 10 ] = db[ 10 ] + dam
damage[ 10 ] = damage[ 10 ] + dam
C_Timer.After( 10, function()
db[ 10 ] = db[ 10 ] - dam
damage[ 10 ] = damage[ 10 ] - dam
end )
end
end
ns.damageInLast = function( seconds, isPhysical )
local db
if isPhysical == nil then db = damage
elseif isPhysical == true then db = physical
else db = magical end
if db[ seconds ] then return db[ seconds ] end
if seconds < 1 then
return db[ 1 ] * ( seconds / 1 )
end
if seconds < 5 then
return db[ 1 ] + ( db[ 5 ] - db[ 1 ] ) * ( seconds - 1 ) / 5
end
if seconds < 10 then
return db[ 5 ] + ( db[ 10 ] - db[ 5 ] ) * ( seconds - 5 ) / 10
end
return db[ 10 ] * seconds / 10
end
ns.storeHealing = function( _, amount )
if amount and amount > 0 then
healing[ 1 ] = healing[ 1 ] + amount
C_Timer.After( 1, function() healing[ 1 ] = healing[ 1 ] - amount end )
healing[ 5 ] = healing[ 5 ] + amount
C_Timer.After( 5, function() healing[ 5 ] = healing[ 5 ] - amount end )
healing[ 10 ] = healing[ 10 ] + amount
C_Timer.After( 10, function() healing[ 10 ] = healing[ 10 ] - amount end )
end
end
ns.healingInLast = function( seconds )
if healing[ seconds ] then return healing[ seconds ] end
if seconds < 1 then
return healing[ 1 ] * ( seconds / 1 )
end
if seconds < 5 then
return healing[ 1 ] + ( healing[ 5 ] - healing[ 1 ] ) * ( seconds - 1 ) / 5
end
if seconds < 10 then
return healing[ 5 ] + ( healing[ 10 ] - healing[ 5 ] ) * ( seconds - 5 ) / 10
end
return healing[ 10 ] * seconds / 10
end
ns.sanitizeDamageAndHealing = function()
physical[ 1 ] = max( 0, physical[ 1 ] )
physical[ 5 ] = max( 0, physical[ 5 ] )
physical[ 10 ] = max( 0, physical[ 10 ] )
magical[ 1 ] = max( 0, magical[ 1 ] )