forked from Hekili/hekili
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Classes.lua
6217 lines (4892 loc) · 153 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 2014
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 RegisterEvent = ns.RegisterEvent
local RegisterUnitEvent = ns.RegisterUnitEvent
local formatKey = ns.formatKey
local getSpecializationKey = ns.getSpecializationKey
local tableCopy = ns.tableCopy
local insert, wipe = table.insert, table.wipe
local mt_resource = ns.metatables.mt_resource
local GetItemCooldown = _G.GetItemCooldown
local GetSpellDescription, GetSpellTexture = _G.GetSpellDescription, _G.GetSpellTexture
local GetSpecialization, GetSpecializationInfo = _G.GetSpecialization, _G.GetSpecializationInfo
local Casting = _G.SPELL_CASTING or "Casting"
local specTemplate = {
enabled = true,
potion = "prolonged_power",
aoe = 2,
cycle = false,
cycle_min = 6,
gcdSync = true,
enhancedRecheck = false,
buffPadding = 0,
debuffPadding = 0,
nameplates = true,
nameplateRange = 8,
petbased = false,
damage = true,
damageExpiration = 8,
damageDots = false,
damageRange = 0,
damagePets = false,
throttleRefresh = false,
regularRefresh = 0.5,
combatRefresh = 0.1,
throttleTime = false,
maxTime = 10,
-- 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
}
},
settings = {},
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 = {},
active_regen = 0,
inactive_regen = 0,
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 model and not model.timeTo then
model.timeTo = function( x )
return state:TimeToResource( r.state, x )
end
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 )
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 )
a.name = GetSpellInfo( a.id )
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 type( data.copy ) == 'string' then
self.auras[ data.copy ] = a
elseif type( data.copy ) == 'table' then
for _, key in ipairs( data.copy ) do
self.auras[ key ] = a
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,
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.copy then
if type( data.copy ) == "table" then
for _, key in ipairs( data.copy ) do
self.potions[ key ] = data
CommitKey( key )
end
else
self.potions[ data.copy ] = data
CommitKey( data.copy )
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,
SetPotion = function( self, potion )
-- if not class.potions[ potion ] then return end
self.potion = potion
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
self.itemAbilities = self.itemAbilities + 1
data.id = -100 - self.itemAbilities
else
self.pseudoAbilities = self.pseudoAbilities + 1
data.id = -1000 * self.id - self.pseudoAbilities
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.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 )
--[[ if not success then
Hekili:Error( "Unable to load " .. item .. " (" .. ability .. ")." )
-- Assume the item is not presently in-game.
for key, entry in pairs( class.abilities ) do
if a == entry then
class.abilities[ key ] = nil
class.abilityList[ key ] = nil
class.abilityByName[ key ] = nil
class.itemList[ key ] = nil
self.abilities[ key ] = nil
end
end
return
end ]]
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
a.texture = a.texture or texture
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 ] = "|T" .. ( a.texture or texture ) .. ":0|t " .. link
class.itemList[ item ] = "|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 ] = "|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()
a.name = GetSpellInfo( a.id )
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
a.rangeSpell = GetSpellInfo( a.rangeSpell )
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.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,
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
end )
end,
RegisterUnitEvent = function( self, event, unit1, unit2, func )
RegisterUnitEvent( event, unit1, unit2, function( ... )
if state.spec.id == self.id then func( ... ) end
end )
end,
RegisterCombatLogEvent = function( self, func )
self:RegisterHook( "COMBAT_LOG_EVENT_UNFILTERED", func )
end,
RegisterCycle = function( self, func )
self.cycle = setfenv( func, state )
end,
RegisterPet = function( self, token, id, spell, duration, ... )
CommitKey( token )
self.pets[ token ] = {
id = type( id ) == 'function' and setfenv( id, state ) or id,
token = token,
spell = spell,
duration = type( duration ) == 'function' and setfenv( duration, state ) or duration
}
local n = select( "#", ... )
if n and n > 0 then
for i = 1, n do
local copy = select( i, ... )
self.pets[ copy ] = self.pets[ token ]
end
end
end,
RegisterTotem = function( self, token, id )
self.totems[ token ] = id
self.totems[ id ] = token
CommitKey( token )
end,
GetSetting = function( self, info )
local setting = info[ #info ]
return Hekili.DB.profile.specs[ self.id ].settings[ setting ]
end,
SetSetting = function( self, info, val )
local setting = info[ #info ]
Hekili.DB.profile.specs[ self.id ].settings[ setting ] = val
end,
-- option should be an AceOption table.
RegisterSetting = function( self, key, value, option )
CommitKey( key )
table.insert( self.settings, {
name = key,
default = value,
info = option
} )
option.order = 100 + #self.settings
option.get = option.get or function( info )
local setting = info[ #info ]
local val = Hekili.DB.profile.specs[ self.id ].settings[ setting ]
if val ~= nil then return val end
return value
end
option.set = option.set or function( info, val )
local setting = info[ #info ]
Hekili.DB.profile.specs[ self.id ].settings[ setting ] = val
end
end,
-- For faster variables.
RegisterVariable = function( self, key, func )
CommitKey( key )
self.variables[ key ] = setfenv( func, state )
end,
}
function Hekili:RestoreDefaults()
local p = self.DB.profile
local changed = {}
for k, v in pairs( class.packs ) do
local existing = rawget( p.packs, k )
if not existing or not existing.version or existing.version < v.version then
local data = self:DeserializeActionPack( v.import )
if data and type( data ) == 'table' then
p.packs[ k ] = data.payload
data.payload.version = v.version
data.payload.date = v.version
data.payload.builtIn = true
insert( changed, k )
local specID = data.payload.spec
if specID then
local spec = rawget( p.specs, specID )
if spec then
if spec.package then
local currPack = p.packs[ spec.package ]
if not currPack or currPack.spec ~= specID then
spec.package = k
end
else
spec.package = k
end
end
end
end
end
end
if #changed > 0 then
self:LoadScripts()
-- self:RefreshOptions()
local msg
if #changed == 1 then
msg = "The |cFFFFD100" .. changed[1] .. "|r priority was updated."
elseif #changed == 2 then
msg = "The |cFFFFD100" .. changed[1] .. "|r and |cFFFFD100" .. changed[2] .. "|r priorities were updated."
else
msg = "|cFFFFD100" .. changed[1] .. "|r"
for i = 2, #changed - 1 do
msg = msg .. ", |cFFFFD100" .. changed[i] .. "|r"
end
msg = "The " .. msg .. ", and |cFFFFD100" .. changed[ #changed ] .. "|r priorities were updated."
end
if msg then C_Timer.After( 5, function()
if Hekili.DB.profile.notifications.enabled then Hekili:Notify( msg, 6 ) end
Hekili:Print( msg )
end ) end
end
end
function Hekili:RestoreDefault( name )
local p = self.DB.profile
local default = class.packs[ name ]
if default then