-
-
Notifications
You must be signed in to change notification settings - Fork 220
/
Classes.lua
4023 lines (3227 loc) · 115 KB
/
Classes.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
-- Classes.lua
-- July 2024
local addon, ns = ...
local Hekili = _G[ addon ]
local class = Hekili.Class
local state = Hekili.State
local CommitKey = ns.commitKey
local FindUnitBuffByID, FindUnitDebuffByID = ns.FindUnitBuffByID, ns.FindUnitDebuffByID
local GetItemInfo = ns.CachedGetItemInfo
local GetResourceInfo, GetResourceKey = ns.GetResourceInfo, ns.GetResourceKey
local ResetDisabledGearAndSpells = ns.ResetDisabledGearAndSpells
local RegisterEvent = ns.RegisterEvent
local RegisterUnitEvent = ns.RegisterUnitEvent
local formatKey = ns.formatKey
local getSpecializationKey = ns.getSpecializationKey
local tableCopy = ns.tableCopy
local LSR = LibStub( "SpellRange-1.0" )
local insert, wipe = table.insert, table.wipe
local mt_resource = ns.metatables.mt_resource
local GetActiveLossOfControlData, GetActiveLossOfControlDataCount = C_LossOfControl.GetActiveLossOfControlData, C_LossOfControl.GetActiveLossOfControlDataCount
local GetItemCooldown = C_Item.GetItemCooldown
local GetSpellDescription, GetSpellTexture = C_Spell.GetSpellDescription, C_Spell.GetSpellTexture
local GetSpecialization, GetSpecializationInfo = _G.GetSpecialization, _G.GetSpecializationInfo
local GetItemSpell, GetItemCount, IsUsableItem = C_Item.GetItemSpell, C_Item.GetItemCount, C_Item.IsUsableItem
local GetSpellInfo = C_Spell.GetSpellInfo
local GetSpellLink = C_Spell.GetSpellLink
local UnitBuff, UnitDebuff = ns.UnitBuff, ns.UnitDebuff
local specTemplate = {
enabled = true,
aoe = 2,
cycle = false,
cycle_min = 6,
gcdSync = true,
nameplates = true,
petbased = false,
damage = true,
damageExpiration = 8,
damageDots = false,
damageOnScreen = true,
damageRange = 0,
damagePets = false,
-- Toggles
custom1Name = "Custom 1",
custom2Name = "Custom 2",
noFeignedCooldown = false,
abilities = {
['**'] = {
disabled = false,
toggle = "default",
clash = 0,
targetMin = 0,
targetMax = 0,
boss = false
}
},
items = {
['**'] = {
disabled = false,
toggle = "default",
clash = 0,
targetMin = 0,
targetMax = 0,
boss = false,
criteria = nil
}
},
placeboBar = 3,
ranges = {},
settings = {},
phases = {},
cooldowns = {},
utility = {},
defensives = {},
custom1 = {},
custom2 = {},
}
ns.specTemplate = specTemplate -- for options.
local function Aura_DetectSharedAura( t, type )
if not t then return end
local finder = type == "debuff" and FindUnitDebuffByID or FindUnitBuffByID
local aura = class.auras[ t.key ]
local name, _, count, _, duration, expirationTime, caster = finder( aura.shared, aura.id )
if name then
t.count = count > 0 and count or 1
if expirationTime > 0 then
t.applied = expirationTime - duration
t.expires = expirationTime
else
t.applied = state.query_time
t.expires = state.query_time + t.duration
end
t.caster = caster
return
end
t.count = 0
t.applied = 0
t.expires = 0
t.caster = "nobody"
end
local protectedFunctions = {
-- Channels.
start = true,
tick = true,
finish = true,
-- Casts
handler = true, -- Cast finish.
impact = true, -- Projectile impact.
}
local HekiliSpecMixin = {
RegisterResource = function( self, resourceID, regen, model, meta )
local resource = GetResourceKey( resourceID )
if not resource then
Hekili:Error( "Unable to identify resource with PowerType " .. resourceID .. "." )
return
end
local r = self.resources[ resource ] or {}
r.resource = resource
r.type = resourceID
r.state = model or setmetatable( {
resource = resource,
type = resourceID,
forecast = {},
fcount = 0,
times = {},
values = {},
actual = 0,
max = 1,
active_regen = 0.001,
inactive_regen = 0.001,
last_tick = 0,
swingGen = false,
add = function( amt, overcap )
-- Bypasses forecast, useful in hooks.
if overcap then r.state.amount = r.state.amount + amt
else r.state.amount = max( 0, min( r.state.amount + amt, r.state.max ) ) end
end,
timeTo = function( x )
return state:TimeToResource( r.state, x )
end,
}, mt_resource )
r.state.regenModel = regen
r.state.meta = meta or {}
for _, func in pairs( r.state.meta ) do
setfenv( func, state )
end
if r.state.regenModel then
for _, v in pairs( r.state.regenModel ) do
v.resource = v.resource or resource
self.resourceAuras[ v.resource ] = self.resourceAuras[ v.resource ] or {}
if v.aura then
self.resourceAuras[ v.resource ][ v.aura ] = true
end
if v.channel then
self.resourceAuras[ v.resource ].casting = true
end
if v.swing then
r.state.swingGen = true
end
end
end
self.primaryResource = self.primaryResource or resource
self.resources[ resource ] = r
CommitKey( resource )
end,
RegisterTalents = function( self, talents )
for talent, id in pairs( talents ) do
self.talents[ talent ] = id
CommitKey( talent )
local hero = id[ 4 ]
if hero then
self.talents[ hero ] = id
CommitKey( hero )
id[ 4 ] = nil
end
end
end,
RegisterPvpTalents = function( self, pvp )
for talent, spell in pairs( pvp ) do
self.pvptalents[ talent ] = spell
CommitKey( talent )
end
end,
RegisterAura = function( self, aura, data )
CommitKey( aura )
local a = setmetatable( {
funcs = {}
}, {
__index = function( t, k )
if t.funcs[ k ] then return t.funcs[ k ]() end
local setup = rawget( t, "onLoad" )
if setup then
t.onLoad = nil
setup( t )
return t[ k ]
end
end
} )
a.key = aura
if not data.id then
self.pseudoAuras = self.pseudoAuras + 1
data.id = ( -1000 * self.id ) - self.pseudoAuras
end
-- default values.
data.duration = data.duration or 30
data.max_stack = data.max_stack or 1
-- This is a shared buff that can come from anyone, give it a special generator.
--[[ if data.shared then
a.generate = Aura_DetectSharedAura
end ]]
for element, value in pairs( data ) do
if type( value ) == "function" then
setfenv( value, state )
if element ~= "generate" then a.funcs[ element ] = value
else a[ element ] = value end
else
a[ element ] = value
end
class.knownAuraAttributes[ element ] = true
end
self.auras[ aura ] = a
if a.id then
if a.id > 0 then
-- Hekili:ContinueOnSpellLoad( a.id, function( success )
a.onLoad = function( a )
local d = GetSpellInfo( a.id )
a.name = d and d.name
if not a.name then
for k, v in pairs( class.auraList ) do
if v == a then class.auraList[ k ] = nil end
end
Hekili.InvalidSpellIDs = Hekili.InvalidSpellIDs or {}
Hekili.InvalidSpellIDs[ a.id ] = a.name or a.key
a.id = a.key
a.name = a.name or a.key
return
end
a.desc = GetSpellDescription( a.id )
local texture = a.texture or GetSpellTexture( a.id )
if self.id > 0 then
class.auraList[ a.key ] = "|T" .. texture .. ":0|t " .. a.name
end
self.auras[ a.name ] = a
if GetSpecializationInfo( GetSpecialization() or 0 ) == self.id then
-- Copy to class table as well.
class.auras[ a.name ] = a
end
if self.pendingItemSpells[ a.name ] then
local items = self.pendingItemSpells[ a.name ]
if type( items ) == "table" then
for i, item in ipairs( items ) do
local ability = self.abilities[ item ]
ability.itemSpellKey = a.key .. "_" .. ability.itemSpellID
self.abilities[ ability.itemSpellKey ] = a
class.abilities[ ability.itemSpellKey ] = a
end
else
local ability = self.abilities[ items ]
ability.itemSpellKey = a.key .. "_" .. ability.itemSpellID
self.abilities[ ability.itemSpellKey ] = a
class.abilities[ ability.itemSpellKey ] = a
end
self.pendingItemSpells[ a.name ] = nil
self.itemPended = nil
end
end
end
self.auras[ a.id ] = a
end
if data.meta then
for k, v in pairs( data.meta ) do
if type( v ) == "function" then data.meta[ k ] = setfenv( v, state ) end
class.knownAuraAttributes[ k ] = true
end
end
if data.copy then
if type( data.copy ) ~= "table" then
self.auras[ data.copy ] = a
else
for _, key in ipairs( data.copy ) do
self.auras[ key ] = a
end
end
end
end,
RegisterAuras = function( self, auras )
for aura, data in pairs( auras ) do
self:RegisterAura( aura, data )
end
end,
RegisterPower = function( self, power, id, aura )
self.powers[ power ] = id
CommitKey( power )
if aura and type( aura ) == "table" then
self:RegisterAura( power, aura )
end
end,
RegisterPowers = function( self, powers )
for k, v in pairs( powers ) do
self.powers[ k ] = v.id
self.powers[ v.id ] = k
for token, ids in pairs( v.triggers ) do
if not self.auras[ token ] then
self:RegisterAura( token, {
id = v.id,
copy = ids
} )
end
end
end
end,
RegisterStateExpr = function( self, key, func )
setfenv( func, state )
self.stateExprs[ key ] = func
class.stateExprs[ key ] = func
CommitKey( key )
end,
RegisterStateFunction = function( self, key, func )
setfenv( func, state )
self.stateFuncs[ key ] = func
class.stateFuncs[ key ] = func
CommitKey( key )
end,
RegisterStateTable = function( self, key, data )
for _, f in pairs( data ) do
if type( f ) == "function" then
setfenv( f, state )
end
end
local meta = getmetatable( data )
if meta and meta.__index then
setfenv( meta.__index, state )
end
self.stateTables[ key ] = data
class.stateTables[ key ] = data
CommitKey( key )
end,
-- Phases are for more durable variables that should be recalculated over the course of recommendations.
-- The start/finish conditions are calculated on reset and that state is persistent between sets of recommendations.
-- Within a set of recommendations, the phase conditions are recalculated when the clock advances and/or when ability handlers are fired.
-- Notably, finish is only fired if we are currently in the phase.
RegisterPhase = function( self, key, start, finish, ... )
if start then start = setfenv( start, state ) end
if finish then finish = setfenv( finish, state ) end
self.phases[ key ] = {
activate = start,
deactivate = finish,
virtual = {},
real = {}
}
local phase = self.phases[ key ]
local n = select( "#", ... )
for i = 1, n do
local hook = select( i, ... )
if hook == "reset_precast" then
self:RegisterHook( hook, function()
local d = display or "Primary"
if phase.real[ d ] == nil then
phase.real[ d ] = false
end
local original = phase.real[ d ]
if state.time == 0 and not InCombatLockdown() then
phase.real[ d ] = false
-- Hekili:Print( format( "[ %s ] Phase '%s' set to '%s' (%s) - out of combat.", self.name or "Unspecified", key, tostring( phase.real[ d ] ), hook ) )
-- if Hekili.ActiveDebug then Hekili:Debug( "[ %s ] Phase '%s' set to '%s' (%s) - out of combat.", self.name or "Unspecified", key, tostring( phase.virtual[ display or "Primary" ] ), hook ) end
end
if not phase.real[ d ] and phase.activate() then
phase.real[ d ] = true
end
if phase.real[ d ] and phase.deactivate() then
phase.real[ d ] = false
end
--[[ if phase.real[ d ] ~= original then
if d == "Primary" then Hekili:Print( format( "Phase change for %s [ %s ] (from %s to %s).", key, d, tostring( original ), tostring( phase.real[ d ] ) ) ) end
end ]]
phase.virtual[ d ] = phase.real[ d ]
if Hekili.ActiveDebug then Hekili:Debug( "[ %s ] Phase '%s' set to '%s' (%s).", self.name or "Unspecified", key, tostring( phase.virtual[ d ] ), hook ) end
end )
else
self:RegisterHook( hook, function()
local d = display or "Primary"
local previous = phase.virtual[ d ]
if phase.virtual[ d ] ~= true and phase.activate() then
phase.virtual[ d ] = true
end
if phase.virtual[ d ] == true and phase.deactivate() then
phase.virtual[ d ] = false
end
if Hekili.ActiveDebug and phase.virtual[ d ] ~= previous then Hekili:Debug( "[ %s ] Phase '%s' set to '%s' (%s) - virtual.", self.name or "Unspecified", key, tostring( phase.virtual[ d ] ), hook ) end
end )
end
end
self:RegisterVariable( key, function()
return self.phases[ key ].virtual[ display or "Primary" ]
end )
end,
RegisterPhasedVariable = function( self, key, default, value, ... )
value = setfenv( value, state )
self.phases[ key ] = {
update = value,
virtual = {},
real = {}
}
local phase = self.phases[ key ]
local n = select( "#", ... )
if type( default ) == "function" then
phase.default = setfenv( default, state )
else
phase.default = setfenv( function() return default end, state )
end
for i = 1, n do
local hook = select( i, ... )
if hook == "reset_precast" then
self:RegisterHook( hook, function()
local d = display or "Primary"
if phase.real[ d ] == nil or ( state.time == 0 and not InCombatLockdown() ) then
phase.real[ d ] = phase.default()
end
local original = phase.real[ d ] or "nil"
phase.real[ d ] = phase.update( phase.real[ d ], phase.default() )
phase.virtual[ d ] = phase.real[ d ]
if Hekili.ActiveDebug then
Hekili:Debug( "[ %s ] Phased variable '%s' set to '%s' (%s) - was '%s'.", self.name or "Unspecified", key, tostring( phase.virtual[ display or "Primary" ] ), hook, tostring( original ) )
end
end )
else
self:RegisterHook( hook, function()
local d = display or "Primary"
local previous = phase.virtual[ d ]
phase.virtual[ d ] = phase.update( phase.virtual[ d ], phase.default() )
if Hekili.ActiveDebug and phase.virtual[ d ] ~= previous then Hekili:Debug( "[ %s ] Phased variable '%s' set to '%s' (%s) - virtual.", self.name or "Unspecified", key, tostring( phase.virtual[ display or "Primary" ] ), hook ) end
end )
end
end
self:RegisterVariable( key, function()
return self.phases[ key ].virtual[ display or "Primary" ]
end )
end,
RegisterGear = function( self, key, ... )
local n = select( "#", ... )
local gear = self.gear[ key ] or {}
for i = 1, n do
local item = select( i, ... )
table.insert( gear, item )
gear[ item ] = true
end
self.gear[ key ] = gear
CommitKey( key )
end,
-- Check for the set bonus based on hidden aura instead of counting the number of equipped items.
-- This may be useful for tier set items that are crafted so their item ID doesn't match.
-- The alternative is *probably* to treat sets based on bonusIDs.
RegisterSetBonus = function( self, key, spellID )
self.setBonuses[ key ] = spellID
CommitKey( key )
end,
RegisterSetBonuses = function( self, ... )
local n = select( "#", ... )
for i = 1, n, 2 do
self:RegisterSetBonus( select( i, ... ) )
end
end,
RegisterPotion = function( self, potion, data )
self.potions[ potion ] = data
data.key = potion
if data.items then
if type( data.items ) == "table" then
for _, key in ipairs( data.items ) do
self.potions[ key ] = data
CommitKey( key )
end
else
self.potions[ data.items ] = data
CommitKey( data.items )
end
end
local potionItem = Item:CreateFromItemID( data.item )
if not potionItem:IsItemEmpty() then
potionItem:ContinueOnItemLoad( function()
local name = potionItem:GetItemName() or data.name
local link = potionItem:GetItemLink() or data.link
data.name = name
data.link = link
class.potionList[ potion ] = link
return true
end )
end
CommitKey( potion )
end,
RegisterPotions = function( self, potions )
for k, v in pairs( potions ) do
self:RegisterPotion( k, v )
end
end,
RegisterRecheck = function( self, func )
self.recheck = func
end,
RegisterHook = function( self, hook, func, noState )
if not ( noState == true or hook == "COMBAT_LOG_EVENT_UNFILTERED" and noState == nil ) then
func = setfenv( func, state )
end
self.hooks[ hook ] = self.hooks[ hook ] or {}
insert( self.hooks[ hook ], func )
end,
RegisterAbility = function( self, ability, data )
CommitKey( ability )
local a = setmetatable( {
funcs = {},
}, {
__index = function( t, k )
local setup = rawget( t, "onLoad" )
if setup then
t.onLoad = nil
setup( t )
return t[ k ]
end
if t.funcs[ k ] then return t.funcs[ k ]() end
if k == "lastCast" then return state.history.casts[ t.key ] or t.realCast end
if k == "lastUnit" then return state.history.units[ t.key ] or t.realUnit end
end,
} )
a.key = ability
a.from = self.id
if not data.id then
if data.item then
class.specs[ 0 ].itemAbilities = class.specs[ 0 ].itemAbilities + 1
data.id = -100 - class.specs[ 0 ].itemAbilities
else
self.pseudoAbilities = self.pseudoAbilities + 1
data.id = -1000 * self.id - self.pseudoAbilities
end
a.id = data.id
end
if data.id and type( data.id ) == "function" then
if not data.copy or type( data.copy ) == "table" and #data.copy == 0 then
Hekili:Error( "RegisterAbility for %s (Specialization %d) will fail; ability has an ID function but needs to have 'copy' entries for the abilities table.", ability, self.id )
end
end
local item = data.item
if item and type( item ) == "function" then
setfenv( item, state )
item = item()
end
if data.meta then
for k, v in pairs( data.meta ) do
if type( v ) == "function" then data.meta[ k ] = setfenv( v, state ) end
end
end
-- default values.
if not data.cast then data.cast = 0 end
if not data.cooldown then data.cooldown = 0 end
if not data.recharge then data.recharge = data.cooldown end
if not data.charges then data.charges = 1 end
if data.hasteCD then
if type( data.cooldown ) == "number" and data.cooldown > 0 then data.cooldown = Hekili:Loadstring( "return " .. data.cooldown .. " * haste" ) end
if type( data.recharge ) == "number" and data.recharge > 0 then data.recharge = Hekili:Loadstring( "return " .. data.recharge .. " * haste" ) end
end
if not data.fixedCast and type( data.cast ) == "number" then
data.cast = Hekili:Loadstring( "return " .. data.cast .. " * haste" )
end
if data.toggle == "interrupts" and data.gcd == "off" and data.readyTime == state.timeToInterrupt and data.interrupt == nil then
data.interrupt = true
end
for key, value in pairs( data ) do
if type( value ) == "function" then
setfenv( value, state )
if not protectedFunctions[ key ] then a.funcs[ key ] = value
else a[ key ] = value end
data[ key ] = nil
else
a[ key ] = value
end
end
if ( a.velocity or a.flightTime ) and a.impact then
a.isProjectile = true
end
a.realCast = 0
if item then
--[[ local name, link, _, _, _, _, _, _, _, texture = GetItemInfo( item )
a.name = name or ability
a.link = link or ability ]]
class.itemMap[ item ] = ability
-- Register the item if it doesn't already exist.
class.specs[0]:RegisterGear( ability, item )
local actionItem = Item:CreateFromItemID( item )
if not actionItem:IsItemEmpty() then
actionItem:ContinueOnItemLoad( function( success )
local name = actionItem:GetItemName()
local link = actionItem:GetItemLink()
local texture = actionItem:GetItemIcon()
if name then
if not a.name or a.name == a.key then a.name = name end
if not a.link or a.link == a.key then a.link = link end
if not a.funcs.texture then a.texture = a.texture or texture end
if a.suffix then
a.actualName = name
a.name = a.name .. " " .. a.suffix
end
self.abilities[ ability ] = self.abilities[ ability ] or a
self.abilities[ a.name ] = self.abilities[ a.name ] or a
self.abilities[ a.link ] = self.abilities[ a.link ] or a
self.abilities[ data.id ] = self.abilities[ a.link ] or a
a.itemLoaded = GetTime()
if a.item and a.item ~= 158075 then
a.itemSpellName, a.itemSpellID = GetItemSpell( a.item )
if a.itemSpellID then
a.itemSpellKey = a.key .. "_" .. a.itemSpellID
self.abilities[ a.itemSpellKey ] = a
class.abilities[ a.itemSpellKey ] = a
end
if a.itemSpellName then
local itemAura = self.auras[ a.itemSpellName ]
if itemAura then
a.itemSpellKey = itemAura.key .. "_" .. a.itemSpellID
self.abilities[ a.itemSpellKey ] = a
class.abilities[ a.itemSpellKey ] = a
else
if self.pendingItemSpells[ a.itemSpellName ] then
if type( self.pendingItemSpells[ a.itemSpellName ] ) == "table" then
table.insert( self.pendingItemSpells[ a.itemSpellName ], ability )
else
local first = self.pendingItemSpells[ a.itemSpellName ]
self.pendingItemSpells[ a.itemSpellName ] = {
first,
ability
}
end
else
self.pendingItemSpells[ a.itemSpellName ] = ability
a.itemPended = GetTime()
end
end
end
end
if not a.unlisted then
class.abilityList[ ability ] = a.listName or ( "|T" .. ( a.texture or texture ) .. ":0|t " .. link )
class.itemList[ item ] = a.listName or ( "|T" .. a.texture .. ":0|t " .. link )
class.abilityByName[ a.name ] = a
end
if data.copy then
if type( data.copy ) == "string" or type( data.copy ) == "number" then
self.abilities[ data.copy ] = a
elseif type( data.copy ) == "table" then
for _, key in ipairs( data.copy ) do
self.abilities[ key ] = a
end
end
end
if data.items then
local addedToItemList = false
for _, id in ipairs( data.items ) do
local copyItem = Item:CreateFromItemID( id )
if not copyItem:IsItemEmpty() then
copyItem:ContinueOnItemLoad( function()
local name = copyItem:GetItemName()
local link = copyItem:GetItemLink()
local texture = copyItem:GetItemIcon()
if name then
class.abilities[ name ] = a
self.abilities[ name ] = a
if not class.itemList[ id ] then
class.itemList[ id ] = a.listName or ( "|T" .. ( a.texture or texture ) .. ":0|t " .. link )
addedToItemList = true
end
end
end )
end
end
if addedToItemList then
if ns.ReadKeybindings then ns.ReadKeybindings() end
end
end
if ability then class.abilities[ ability ] = a end
if a.name then class.abilities[ a.name ] = a end
if a.link then class.abilities[ a.link ] = a end
if a.id then class.abilities[ a.id ] = a end
Hekili.OptionsReady = false
return true
end
return false
end )
end
end
if a.id and a.id > 0 then
-- Hekili:ContinueOnSpellLoad( a.id, function( success )
a.onLoad = function()
local spellInfo = GetSpellInfo( a.id )
if spellInfo == nil then
spellInfo = GetItemInfo( a.id )
end
if spellInfo then
a.name = spellInfo.name
else
a.name = nil
end
if not a.name then
for k, v in pairs( class.abilityList ) do
if v == a then class.abilityList[ k ] = nil end
end
Hekili.InvalidSpellIDs = Hekili.InvalidSpellIDs or {}
table.insert( Hekili.InvalidSpellIDs, a.id )
Hekili:Error( "Name info not available for " .. a.id .. "." )
return
end
if not a.name then Hekili:Error( "Name info not available for " .. a.id .. "." ); return false end
a.desc = GetSpellDescription( a.id ) -- was returning raw tooltip data.
if a.suffix then
a.actualName = a.name
a.name = a.name .. " " .. a.suffix
end
local texture = a.texture or GetSpellTexture( a.id )
self.abilities[ a.name ] = self.abilities[ a.name ] or a
class.abilities[ a.name ] = class.abilities[ a.name ] or a
if not a.unlisted then
class.abilityList[ ability ] = a.listName or ( "|T" .. texture .. ":0|t " .. a.name )
class.abilityByName[ a.name ] = class.abilities[ a.name ] or a
end
if a.rangeSpell and type( a.rangeSpell ) == "number" then
Hekili:ContinueOnSpellLoad( a.rangeSpell, function( success )
if success then
local info = GetSpellInfo( a.rangeSpell )
if info then
a.rangeSpell = info.name
else
a.rangeSpell = nil
end
else
a.rangeSpell = nil
end
end )
end
Hekili.OptionsReady = false
end
end
self.abilities[ ability ] = a
self.abilities[ a.id ] = a
if not a.unlisted then class.abilityList[ ability ] = class.abilityList[ ability ] or a.listName or a.name end
if data.copy then
if type( data.copy ) == "string" or type( data.copy ) == "number" then
self.abilities[ data.copy ] = a
elseif type( data.copy ) == "table" then
for _, key in ipairs( data.copy ) do
self.abilities[ key ] = a
end
end
end
if data.items then
for _, itemID in ipairs( data.items ) do
class.itemMap[ itemID ] = ability
end
end
if a.dual_cast or a.funcs.dual_cast then
self.can_dual_cast = true
self.dual_cast[ a.key ] = true
end
if a.empowered or a.funcs.empowered then
self.can_empower = true
end
if a.auras then
self:RegisterAuras( a.auras )
end
end,
RegisterAbilities = function( self, abilities )
for ability, data in pairs( abilities ) do
self:RegisterAbility( ability, data )
end
end,
RegisterPack = function( self, name, version, import )
self.packs[ name ] = {
version = tonumber( version ),
import = import:gsub("([^|])|([^|])", "%1||%2")
}
end,
RegisterPriority = function( self, name, version, notes, priority )
end,
RegisterRanges = function( self, ... )
if type( ... ) == "table" then
self.ranges = ...
return
end
for i = 1, select( "#", ... ) do
insert( self.ranges, ( select( i, ... ) ) )
end
end,
RegisterRangeFilter = function( self, name, func )
self.filterName = name
self.filter = func
end,
RegisterOptions = function( self, options )
self.options = options
end,
RegisterEvent = function( self, event, func )
RegisterEvent( event, function( ... )
if state.spec.id == self.id then func( ... ) end