forked from Hekili/hekili
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Events.lua
2626 lines (2009 loc) · 86.6 KB
/
Events.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
-- Events.lua
-- June 2014
local addon, ns = ...
local Hekili = _G[ addon ]
local class = Hekili.Class
local state = Hekili.State
local PTR = ns.PTR
local TTD = ns.TTD
local formatKey = ns.formatKey
local abs = math.abs
local lower = string.lower
local insert, remove, sort, wipe = table.insert, table.remove, table.sort, table.wipe
local CGetItemInfo = C_Item.GetItemInfo
local IsEquippedItem = C_Item.IsEquippedItem
local UA_GetPlayerAuraBySpellID = C_UnitAuras.GetPlayerAuraBySpellID
local FindStringInInventoryItemTooltip = ns.FindStringInInventoryItemTooltip
local ResetDisabledGearAndSpells = ns.ResetDisabledGearAndSpells
local WipeCovenantCache = ns.WipeCovenantCache
local RC = LibStub( "LibRangeCheck-3.0" )
-- Abandoning AceEvent in favor of darkend's solution from:
-- http://andydote.co.uk/2014/11/23/good-design-in-warcraft-addons.html
-- This should be a bit friendlier for our modules.
local events = CreateFrame( "Frame" )
Hekili:ProfileFrame( "GeneralEvents", events )
local handlers = {}
local unitHandlers = {}
local itemCallbacks = {}
local spellCallbacks = {}
local activeDisplays = {}
function Hekili:GetActiveDisplays()
return activeDisplays
end
local handlerCount = {}
Hekili.ECount = handlerCount
Hekili.IC = itemCallbacks
local eventData = {}
Hekili.EData = eventData
local function GenericOnEvent( self, event, ... )
local eventHandlers = handlers[ event ]
if not eventHandlers then return end
for i, handler in ipairs( eventHandlers ) do
local key = event .. "_" .. i
local start = debugprofilestop()
handler( event, ... )
local finish = debugprofilestop()
handlerCount[ key ] = ( handlerCount[ key ] or 0 ) + 1
eventData[ key ] = eventData[ key ] or {}
eventData[ key ].max = max( eventData[ key ].max or 0, finish - start )
eventData[ key ].total = ( eventData[ key ].total or 0 ) + ( finish - start )
end
end
local function UnitSpecificOnEvent( self, event, unit, ... )
local unitFrame = unitHandlers[ unit ]
if unitFrame then
local eventHandlers = unitFrame.events[ event ]
if not eventHandlers then return end
for i, handler in ipairs( eventHandlers ) do
local key = event .. "_" .. unit .. "_" .. i
local start = debugprofilestop()
handler( event, unit, ... )
local finish = debugprofilestop()
handlerCount[ key ] = ( handlerCount[ key ] or 0 ) + 1
eventData[ key ] = eventData[ key ] or {}
eventData[ key ].max = max( eventData[ key ].max or 0, finish - start )
eventData[ key ].total = ( eventData[ key ].total or 0 ) + ( finish - start )
end
end
end
function ns.StartEventHandler()
events:SetScript( "OnEvent", GenericOnEvent )
for unit, unitFrame in pairs( unitHandlers ) do
unitFrame:SetScript( "OnEvent", UnitSpecificOnEvent )
end
events:SetScript( "OnUpdate", function( self, elapsed )
if Hekili.PendingSpecializationChange then
Hekili:SpecializationChanged()
Hekili.PendingSpecializationChange = false
-- Spec updates are expensive; exit and do other work in the next frame.
return
end
if handlers.FRAME_UPDATE then
for i, handler in pairs( handlers.FRAME_UPDATE ) do
local key = "FRAME_UPDATE_" .. i
local start = debugprofilestop()
handler( event, elapsed )
local finish = debugprofilestop()
handlerCount[ key ] = ( handlerCount[ key ] or 0 ) + 1
eventData[ key ] = eventData[ key ] or {}
eventData[ key ].max = max( eventData[ key ].max or 0, finish - start )
eventData[ key ].total = ( eventData[ key ].total or 0 ) + ( finish - start )
end
end
end )
Hekili:RunSpellCallbacks()
end
function ns.StopEventHandler()
events:SetScript( "OnEvent", nil )
for unit, unitFrame in pairs( unitHandlers ) do
unitFrame:SetScript( "OnEvent", nil )
end
events:SetScript( "OnUpdate", nil )
end
Hekili.EventSources = {}
ns.RegisterEvent = function( event, handler )
handlers[ event ] = handlers[ event ] or {}
insert( handlers[ event ], handler )
if event ~= "FRAME_UPDATE" then events:RegisterEvent( event ) end
local key = event .. "_" .. #handlers[event]
Hekili:ProfileCPU( key, handler )
local stack = debugstack(2)
local file, line = stack:match([[Hekili/(.-)"%]:(%d+)]])
Hekili.EventSources[ key ] = file and ( file .. ":" .. ( line or 0 ) ) or stack:match( "^(.*)\n" )
end
local RegisterEvent = ns.RegisterEvent
ns.UnregisterEvent = function( event, handler )
local hands = handlers[ event ]
if not hands then return end
for i = #hands, 1, -1 do
if hands[i] == handler then
remove( hands, i )
end
end
if #hands == 0 then events:UnregisterEvent( event ) end
end
local UnregisterEvent = ns.UnregisterEvent
-- For our purposes, all UnitEvents are player/target oriented.
ns.RegisterUnitEvent = function( event, unit1, unit2, handler )
if not unit1 then unit1 = "player" end
if not unitHandlers[ unit1 ] then
unitHandlers[ unit1 ] = CreateFrame( "Frame" )
Hekili:ProfileFrame( "UnitEvents:" .. unit1, unitHandlers[ unit1 ] )
unitHandlers[ unit1 ].events = {}
end
local unitFrame = unitHandlers[ unit1 ]
unitFrame.events[ event ] = unitFrame.events[ event ] or {}
insert( unitFrame.events[ event ], handler )
local stack = debugstack(2)
local file, line = stack:match([[Hekili/(.-)"%]:(%d+)]])
Hekili.EventSources[ event .. "_" .. unit1 .. "_" .. #unitFrame.events[ event ] ] = file and ( file .. ":" .. ( line or 0 ) ) or stack:match( "^(.*)\n" )
unitFrame:RegisterUnitEvent( event, unit1 )
Hekili:ProfileCPU( event .. "_" .. unit1 .. "_" .. #unitFrame.events[ event ], handler )
if unit2 then
if not unitHandlers[ unit2 ] then
unitHandlers[ unit2 ] = CreateFrame( "Frame" )
Hekili:ProfileFrame( "UnitEvents:" .. unit2, unitHandlers[ unit2 ] )
unitHandlers[ unit2 ].events = {}
end
unitFrame = unitHandlers[ unit2 ]
unitFrame.events[ event ] = unitFrame.events[ event ] or {}
insert( unitFrame.events[ event ], handler )
Hekili.EventSources[ event .. "_" .. unit2 .. "_" .. #unitFrame.events[ event ] ] = file and ( file .. ":" .. ( line or 0 ) ) or stack:match( "^(.*)\n" )
unitFrame:RegisterUnitEvent( event, unit2 )
Hekili:ProfileCPU( event .. "_" .. unit2 .. "_" .. #unitFrame.events[ event ], handler )
end
end
local RegisterUnitEvent = ns.RegisterUnitEvent
function ns.UnregisterUnitEvent( event, handler )
local hands = unitHandlers[ event ]
if not hands then return end
for i = #hands, 1, -1 do
if hands[i] == handler then
remove( hands, i )
end
end
end
ns.FeignEvent = function( event, ... )
local eventHandlers = handlers[ event ]
if not eventHandlers then return end
for i, handler in pairs( eventHandlers ) do
handler( event, ... )
end
end
Hekili.FeignEvent = ns.FeignEvent
do
local isUnregistered = false
local next = _G.next
local requeued = {}
local HandleSpellData = function( event, spellID, success )
local callbacks = spellCallbacks[ spellID ]
if callbacks then
for i = #callbacks, 1, -1 do
callbacks[i]( event, spellID, success )
remove( callbacks, i )
end
if #callbacks == 0 then
spellCallbacks[ spellID ] = nil
end
end
if spellCallbacks == nil or next( spellCallbacks ) == nil then
UnregisterEvent( "SPELL_DATA_LOAD_RESULT", HandleSpellData )
isUnregistered = true
end
end
function Hekili:ContinueOnSpellLoad( spellID, func )
if C_Spell.IsSpellDataCached( spellID ) then
func( true )
return
end
local callbacks = spellCallbacks[ spellID ] or {}
insert( callbacks, func )
spellCallbacks[ spellID ] = callbacks
if isUnregistered then
RegisterEvent( "SPELL_DATA_LOAD_RESULT", HandleSpellData )
isUnregistered = false
end
C_Spell.RequestLoadSpellData( spellID )
end
function Hekili:RunSpellCallbacks()
for spell, callbacks in pairs( spellCallbacks ) do
for i = #callbacks, 1, -1 do
if not callbacks[ i ]( true ) == false then remove( callbacks, i ) end
end
if #callbacks == 0 then
spellCallbacks[ spell ] = nil
end
end
end
end
RegisterEvent( "DISPLAY_SIZE_CHANGED", function()
Hekili:BuildUI()
end )
RegisterEvent( "PLAYER_ENTERING_WORLD", function( event, login, reload )
if not Hekili.PLAYER_ENTERING_WORLD and ( login or reload ) then
Hekili.PLAYER_ENTERING_WORLD = true
Hekili:SpecializationChanged()
Hekili:RestoreDefaults()
ns.checkImports()
ns.updateGear()
if state.combat == 0 and InCombatLockdown() then
state.combat = GetTime() - 0.01
end
local _, zone = GetInstanceInfo()
state.bg = zone == "pvp"
state.arena = zone == "arena"
state.torghast = IsInJailersTower()
Hekili:BuildUI()
end
end )
do
if Hekili.IsWrath() then
RegisterEvent( "ACTIVE_TALENT_GROUP_CHANGED", function()
Hekili:SpecializationChanged()
end )
else
local specializationEvents = {
ACTIVE_PLAYER_SPECIALIZATION_CHANGED = 1,
ACTIVE_TALENT_GROUP_CHANGED = 1,
CONFIRM_TALENT_WIPE = 1,
PLAYER_TALENT_UPDATE = 1,
SPEC_INVOLUNTARILY_CHANGED = 1,
TALENTS_INVOLUNTARILY_RESET = 1
}
local function CheckForTalentUpdate( event )
local specialization = GetSpecialization()
local specID = specialization and GetSpecializationInfo( specialization )
if specID and specID ~= state.spec.id then
Hekili.PendingSpecializationChange = true
end
end
RegisterUnitEvent( "PLAYER_SPECIALIZATION_CHANGED", "player", nil, CheckForTalentUpdate )
for event in pairs( specializationEvents ) do
RegisterEvent( event, CheckForTalentUpdate )
end
end
end
do
local function UpdateZoneInfo()
local _, zone = GetInstanceInfo()
state.bg = zone == "pvp"
state.arena = zone == "arena"
state.torghast = IsInJailersTower()
end
RegisterEvent( "ZONE_CHANGED", UpdateZoneInfo )
RegisterEvent( "ARENA_PREP_OPPONENT_SPECIALIZATIONS", UpdateZoneInfo )
end
-- Hide when going into the barbershop.
RegisterEvent( "BARBER_SHOP_OPEN", function ()
Hekili.Barber = true
end )
RegisterEvent( "BARBER_SHOP_CLOSE", function ()
Hekili.Barber = false
end )
-- Update visibility when getting on/off a taxi.
RegisterEvent( "PLAYER_CONTROL_LOST", function ()
Hekili:After( 0.1, Hekili.UpdateDisplayVisibility, Hekili )
end )
RegisterEvent( "PLAYER_CONTROL_GAINED", function ()
Hekili:After( 0.1, Hekili.UpdateDisplayVisibility, Hekili )
end )
function ns.updateTalents()
for k, _ in pairs( state.talent ) do
state.talent[ k ].enabled = false
end
-- local specGroup = GetSpecialization()
for k, v in pairs( class.talents ) do
local _, name, _, enabled, _, sID, _, _, _, _, known = GetTalentInfoByID( v, 1 )
if not name then
-- We probably used a spellID.
enabled = IsPlayerSpell( v )
end
enabled = enabled or known
if rawget( state.talent, k ) then
state.talent[ k ].enabled = enabled
else
state.talent[ k ] = { enabled = enabled }
end
end
for k, _ in pairs( state.pvptalent ) do
state.pvptalent[ k ]._enabled = false
end
for k, v in pairs( class.pvptalents ) do
local _, name, _, enabled, _, sID, _, _, _, known = GetPvpTalentInfoByID( v, 1 )
if not name then
enabled = IsPlayerSpell( v )
end
enabled = enabled or known
if rawget( state.pvptalent, k ) then
state.pvptalent[ k ]._enabled = enabled
else
state.pvptalent[ k ] = {
_enabled = enabled
}
end
end
WipeCovenantCache()
ResetDisabledGearAndSpells()
end
-- TBD: Consider making `boss' a check to see whether the current unit is a boss# unit instead.
RegisterEvent( "ENCOUNTER_START", function ( _, id, name, difficulty, groupSize )
state.encounterID = id
state.encounterName = name
state.encounterDifficulty = difficulty
state.encounterSize = groupSize
end )
RegisterEvent( "ENCOUNTER_END", function ()
state.encounterID = 0
state.encounterName = "None"
state.encounterDifficulty = 0
state.encounterSize = 0
end )
do
local loc = ItemLocation:CreateEmpty()
local GetAllTierInfo = C_AzeriteEmpoweredItem.GetAllTierInfo
local GetPowerInfo = C_AzeriteEmpoweredItem.GetPowerInfo
local IsAzeriteEmpoweredItemByID = C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItemByID
local IsPowerSelected = C_AzeriteEmpoweredItem.IsPowerSelected
local MAX_INV_SLOTS = 19
function ns.updatePowers()
local p = state.azerite
for k, v in pairs( p ) do
v.__rank = 0
end
if next( class.powers ) == nil then
C_Timer.After( 3, ns.updatePowers )
return
end
for slot = 1, MAX_INV_SLOTS do
local id = GetInventoryItemID( "player", slot )
if id and IsAzeriteEmpoweredItemByID( id ) then
loc:SetEquipmentSlot( slot )
local tiers = GetAllTierInfo( loc )
for tier, tierInfo in ipairs( tiers ) do
for _, power in ipairs( tierInfo.azeritePowerIDs ) do
local pInfo = GetPowerInfo( power )
if IsPowerSelected( loc, power ) then
local name = class.powers[ pInfo.spellID ]
if not name then
Hekili:Error( "Missing Azerite Power info for #" .. pInfo.spellID .. ": " .. GetSpellInfo( pInfo.spellID ) .. "." )
else
p[ name ] = rawget( p, name ) or { __rank = 0 }
p[ name ].__rank = p[ name ].__rank + 1
end
end
end
end
end
end
loc:Clear()
end
Hekili:ProfileCPU( "updatePowers", ns.updatePowers )
-- Essences
local AE = C_AzeriteEssence
local GetMilestoneEssence, GetEssenceInfo = AE.GetMilestoneEssence, AE.GetEssenceInfo
local milestones = { 115, 116, 117, 119 }
local essenceKeys = {
[2] = "azeroths_undying_gift",
[3] = "sphere_of_suppression",
[4] = "worldvein_resonance",
[5] = "essence_of_the_focusing_iris",
[6] = "purification_protocol",
[7] = "anima_of_life_and_death",
[12] = "the_crucible_of_flame",
[13] = "nullification_dynamo",
[14] = "condensed_lifeforce",
[15] = "ripple_in_space",
[16] = "unwavering_ward",
[17] = "everrising_tide",
[18] = "artifice_of_time",
[19] = "well_of_existence",
[20] = "lifebinders_invocation",
[21] = "vitality_conduit",
[22] = "vision_of_perfection",
[23] = "blood_of_the_enemy",
[24] = "spirit_of_preservation",
[25] = "aegis_of_the_deep",
[27] = "memory_of_lucid_dreams",
[28] = "the_unbound_force",
[32] = "conflict_and_strife",
[33] = "touch_of_the_everlasting",
[34] = "strength_of_the_warden",
[35] = "breath_of_the_dying",
[36] = "spark_of_inspiration",
[37] = "the_formless_void"
}
local essenceMajors = {
-- everrising_tide = "",
-- lifebinders_invocation = "",
-- touch_of_the_everlasting = "",
-- vision_of_perfection = "",
-- vitality_conduit = "",
-- well_of_existence = "",
-- conflict_and_strife = "",
aegis_of_the_deep = "aegis_of_the_deep",
anima_of_life_and_death = "anima_of_death",
artifice_of_time = "standstill",
azeroths_undying_gift = "azeroths_undying_gift",
blood_of_the_enemy = "blood_of_the_enemy",
breath_of_the_dying = "reaping_flames",
condensed_lifeforce = "guardian_of_azeroth",
essence_of_the_focusing_iris = "focused_azerite_beam",
memory_of_lucid_dreams = "memory_of_lucid_dreams",
nullification_dynamo = "empowered_null_barrier",
purification_protocol = "purifying_blast",
ripple_in_space = "ripple_in_space",
spark_of_inspiration = "moment_of_glory",
sphere_of_suppression = "suppressing_pulse",
spirit_of_preservation = "spirit_of_preservation",
strength_of_the_warden = "vigilant_protector",
the_crucible_of_flame = "concentrated_flame",
the_formless_void = "replica_of_knowledge",
the_unbound_force = "the_unbound_force",
unwavering_ward = "guardian_shell",
worldvein_resonance = "worldvein_resonance",
}
for _, key in pairs( essenceKeys ) do
state.essence[ key ] = { __rank = 0, __major = false }
end
function ns.updateEssences()
local e = state.bfa_essence
for k, v in pairs( e ) do
v.__rank = 0
end
class.active_essence = nil
if state.equipped[ 158075 ] then
for i, ms in ipairs( milestones ) do
local essence = GetMilestoneEssence( ms )
if essence then
local info = GetEssenceInfo( essence )
if info then
local key = essenceKeys[ info.ID ]
e[ key ].__rank = info.rank
e[ key ].__minor = true
if i == 1 then
e[ key ].__major = true
class.active_essence = essenceMajors[ key ]
end
end
end
end
end
end
ns.updateEssences()
end
do
local function itemSorter( a, b )
local action1, action2 = class.abilities[ a.action ].cooldown, class.abilities[ b.action ].cooldown
return action1 > action2
end
local function buildUseItemsList()
local itemList = class.itemPack.lists.items
wipe( itemList )
if #state.items > 0 then
for i, item in ipairs( state.items ) do
if not Hekili:IsItemScripted( item ) then
insert( itemList, {
action = item,
enabled = true,
criteria = "( ! settings.boss || boss ) & " ..
"( settings.targetMin = 0 || active_enemies >= settings.targetMin ) & " ..
"( settings.targetMax = 0 || active_enemies <= settings.targetMax )"
} )
end
end
end
sort( itemList, itemSorter )
class.essence_unscripted = ( class.active_essence and not Hekili:IsEssenceScripted( class.active_essence ) ) or false
Hekili:LoadItemScripts()
end
function Hekili:UpdateUseItems()
if not Hekili.PLAYER_ENTERING_WORLD then
C_Timer.After( 1, buildUseItemsList )
return
end
buildUseItemsList()
end
local GearHooks = {}
-- This is a simple way to separate expansion-based gear into separate systems.
function Hekili:RegisterGearHook( r, u )
insert( GearHooks, {
reset = r,
update = u
} )
end
local wasWearing = {}
local maxItemSlot = Hekili.IsWrath() and INVSLOT_LAST_EQUIPPED or Enum.ItemSlotFilterTypeMeta.MaxValue
local timer
local function Update()
ns.updateGear()
end
local function QueueUpdate()
if timer and not timer:IsCancelled() then timer:Cancel() end
timer = C_Timer.NewTimer( 1, Update )
end
function ns.updateGear()
if not Hekili.PLAYER_ENTERING_WORLD then
QueueUpdate()
return
end
lastUpdate = GetTime()
updateIsQueued = false
wipe( state.set_bonus )
for _, hook in ipairs( GearHooks ) do
if hook.reset then hook.reset() end
end
wipe( wasWearing )
for i, item in ipairs( state.items ) do
wasWearing[ i ] = item
end
wipe( state.items )
for set, items in pairs( class.gear ) do
state.set_bonus[ set ] = 0
for item, _ in pairs( items ) do
if item > maxItemSlot and IsEquippedItem( item ) then
state.set_bonus[ set ] = state.set_bonus[ set ] + 1
end
end
end
for bonus, aura in pairs( class.setBonuses ) do
if UA_GetPlayerAuraBySpellID( aura ) then
state.set_bonus[ bonus ] = 1
end
end
-- Trinkets
-- We want to know:
-- 1. Which trinket?
-- 2. Does it have a spell? (GetItemSpell)
-- 3. Does it have an on-use? (IsItemUsable)
-- 4. ???
local T1 = GetInventoryItemID( "player", 13 )
state.trinket.t1.__id = 0
state.trinket.t1.ilvl = 0
state.trinket.t1.__ability = "null_cooldown"
state.trinket.t1.__usable = false
state.trinket.t1.__has_use_buff = false
state.trinket.t1.__use_buff_duration = nil
if T1 then
state.trinket.t1.__id = T1
-- So this isn't *truly* accurate, but it's accurate relatively speaking.
state.trinket.t1.ilvl = GetDetailedItemLevelInfo( T1 )
local isUsable = IsUsableItem( T1 )
local name, spellID = GetItemSpell( T1 )
local tSpell = class.itemMap[ T1 ]
if tSpell then
class.abilities.trinket1 = class.abilities[ tSpell ]
class.specs[ 0 ].abilities.trinket2 = class.abilities[ tSpell ]
state.trinket.t1.__usable = isUsable
state.trinket.t1.__ability = tSpell
local ability = class.abilities[ tSpell ]
local aura = ability and class.auras[ ability.self_buff or spellID ]
if spellID and SpellIsSelfBuff( spellID ) and aura then
state.trinket.t1.__has_use_buff = not aura.ignore_buff and not ( ability and ability.proc and ( ability.proc == "damage" or ability.proc == "healing" or ability.proc == "mana" or ability.proc == "absorb" or ability.proc == "speed" ) )
state.trinket.t1.__use_buff_duration = aura.duration > 0 and aura.duration or 0.01
elseif ability.self_buff then
state.trinket.t1.__has_use_buff = true
state.trinket.t1.__use_buff_duration = aura and aura.duration > 0 and aura.duration or 0.01
end
if not isUsable then
state.trinket.t1.cooldown = state.cooldown.null_cooldown
else
state.cooldown.trinket1 = state.cooldown[ ability.key ]
state.trinket.t1.cooldown = state.cooldown.trinket1
end
else
class.abilities.trinket1 = class.abilities.actual_trinket1
class.specs[ 0 ].abilities.trinket1 = class.abilities.actual_trinket1
state.trinket.t1.cooldown = state.cooldown.null_cooldown
end
state.trinket.t1.__proc = FindStringInInventoryItemTooltip( "^" .. ITEM_SPELL_TRIGGER_ONEQUIP, 13, true, true )
end
local T2 = GetInventoryItemID( "player", 14 )
state.trinket.t2.__id = 0
state.trinket.t2.__ability = "null_cooldown"
state.trinket.t2.__usable = false
state.trinket.t2.__has_use_buff = false
state.trinket.t2.__use_buff_duration = nil
state.trinket.t2.ilvl = 0
if T2 then
state.trinket.t2.__id = T2
-- So this isn't *truly* accurate, but it's accurate relatively speaking.
state.trinket.t2.ilvl = GetDetailedItemLevelInfo( T2 )
local isUsable = IsUsableItem( T2 )
local name, spellID = GetItemSpell( T2 )
local tSpell = class.itemMap[ T2 ]
if tSpell then
class.abilities.trinket2 = class.abilities[ tSpell ]
class.specs[ 0 ].abilities.trinket2 = class.abilities[ tSpell ]
state.trinket.t2.__usable = isUsable
state.trinket.t2.__ability = tSpell
local ability = class.abilities[ tSpell ]
local aura = class.auras[ ability.self_buff or spellID ]
if spellID and SpellIsSelfBuff( spellID ) and aura then
state.trinket.t2.__has_use_buff = not aura.ignore_buff and not ( ability and ability.proc and ( ability.proc == "damage" or ability.proc == "healing" or ability.proc == "mana" or ability.proc == "absorb" or ability.proc == "speed" ) )
state.trinket.t2.__use_buff_duration = aura.duration > 0 and aura.duration or 0.01
elseif ability.self_buff then
state.trinket.t2.__has_use_buff = true
state.trinket.t2.__use_buff_duration = aura and aura.duration > 0 and aura.duration or 0.01
end
if not isUsable then
state.trinket.t2.cooldown = state.cooldown.null_cooldown
else
state.cooldown.trinket2 = state.cooldown[ ability.key ]
state.trinket.t2.cooldown = state.cooldown.trinket2
end
else
class.abilities.trinket2 = class.abilities.actual_trinket2
class.specs[ 0 ].abilities.trinket2 = class.abilities.actual_trinket2
state.trinket.t2.cooldown = state.cooldown.null_cooldown
end
state.trinket.t2.__proc = FindStringInInventoryItemTooltip( "^" .. ITEM_SPELL_TRIGGER_ONEQUIP, 14, true, true )
end
state.main_hand.size = 0
state.off_hand.size = 0
local MH = GetInventoryItemID( "player", 16 )
class.abilities.main_hand = class.abilities.actual_main_hand
if MH then
local isUsable = IsUsableItem( MH )
local name, spellID = GetItemSpell( MH )
local tSpell = class.itemMap[ MH ]
local ability = class.abilities[ tSpell ]
if ability and tSpell then
class.abilities.main_hand = class.abilities[ tSpell ]
class.specs[ 0 ].abilities.main_hand = class.abilities[ tSpell ]
local aura = ability and class.auras[ ability.self_buff or spellID ]
if spellID and SpellIsSelfBuff( spellID ) and aura then
state.trinket.main_hand.__has_use_buff = not aura.ignore_buff and not ( ability and ability.proc and ( ability.proc == "damage" or ability.proc == "healing" or ability.proc == "mana" or ability.proc == "absorb" or ability.proc == "speed" ) )
state.trinket.main_hand.__use_buff_duration = aura.duration > 0 and aura.duration or 0.01
elseif ability.self_buff then
state.trinket.main_hand.__has_use_buff = true
state.trinket.main_hand.__use_buff_duration = aura and aura.duration > 0 and aura.duration or 0.01
end
if not isUsable then
state.trinket.main_hand.cooldown = state.cooldown.null_cooldown
else
state.cooldown.main_hand = state.cooldown[ ability.key ]
state.trinket.main_hand.cooldown = state.cooldown.main_hand
end
else
class.abilities.main_hand = class.abilities.actual_main_hand
class.specs[ 0 ].abilities.main_hand = class.abilities.actual_main_hand
state.trinket.main_hand.cooldown = state.cooldown.null_cooldown
end
state.trinket.main_hand.__proc = FindStringInInventoryItemTooltip( "^" .. ITEM_SPELL_TRIGGER_ONEQUIP, 16, true, true )
end
for i = 1, 19 do
local item = GetInventoryItemID( "player", i )
if item then
state.set_bonus[ item ] = 1
local key, _, _, _, _, _, _, _, equipLoc = CGetItemInfo( item )
if key then
key = formatKey( key )
state.set_bonus[ key ] = 1
end
if i == 16 then
if equipLoc == "INVTYPE_2HWEAPON" then
state.main_hand.size = 2
elseif equipLoc == "INVTYPE_WEAPON" or equipLoc == "INVTYPE_WEAPONMAINHAND" then
state.main_hand.size = 1
elseif equipLoc == "INVTYPE_RANGED" or equipLoc == "INVTYPE_RANGEDRIGHT" then
state.set_bonus.ranged = 1
end
elseif i == 17 then
if equipLoc == "INVTYPE_2HWEAPON" then
state.off_hand.size = 2
elseif equipLoc == "INVTYPE_WEAPON" or equipLoc == "INVTYPE_WEAPONOFFHAND" then
state.off_hand.size = 1
elseif equipLoc == "INVTYPE_RANGED" or equipLoc == "INVTYPE_RANGEDRIGHT" then
state.set_bonus.ranged = 1
elseif equipLoc == "INVTYPE_SHIELD" then
state.set_bonus.shield = 1
end
end
-- Fire any/all GearHooks (may be expansion-driven).
for _, hook in ipairs( GearHooks ) do
if hook.update then hook.update( i, item ) end
end
local usable = class.itemMap[ item ]
if usable then insert( state.items, usable ) end
end
end
-- Improve Pocket-Sized Computronic Device.
if state.equipped.pocketsized_computation_device then
local tName = CGetItemInfo( 167555 )
local redName, redLink = GetItemGem( tName, 1 )
if redName and redLink then
local redID = tonumber( redLink:match("item:(%d+)") )
local action = class.itemMap[ redID ]
if action then
state.set_bonus[ action ] = 1
state.set_bonus[ redID ] = 1
class.abilities.pocketsized_computation_device = class.abilities[ action ]
class.abilities[ tName ] = class.abilities[ action ]
insert( state.items, action )
end
else
class.abilities.pocketsized_computation_device = class.abilities.inactive_red_punchcard
class.abilities[ tName ] = class.abilities.inactive_red_punchcard
end
end
ns.updatePowers()
ns.updateTalents()
ns.updateEssences()
local sameItems = #wasWearing == #state.items
if sameItems then
for i = 1, #state.items do
if wasWearing[i] ~= state.items[i] then
sameItems = false
break
end
end
end
Hekili:UpdateUseItems()
state.swings.mh_speed, state.swings.oh_speed = UnitAttackSpeed( "player" )
end
RegisterEvent( "PLAYER_EQUIPMENT_CHANGED", QueueUpdate )
end
do
local timer
local function Update()
ns.updateTalents()
end
local function QueueUpdate()
if timer and not timer:IsCancelled() then timer:Cancel() end
timer = C_Timer.NewTimer( 0.5, Update )
end
local talentEvents = {
"TRAIT_CONFIG_CREATED",
"ACTIVE_COMBAT_CONFIG_CHANGED",
"STARTER_BUILD_ACTIVATION_FAILED",
"TRAIT_CONFIG_DELETED",
"TRAIT_CONFIG_UPDATED",
"CONFIG_COMMIT_FAILED",
"PLAYER_ALIVE",
"PLAYER_UNGHOST"
}
for _, event in pairs( talentEvents ) do
RegisterEvent( event, QueueUpdate )
end
end
-- Update Azerite Essence Data.
do
local azeriteEvents = {