forked from Hekili/hekili
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.lua
2126 lines (1615 loc) · 101 KB
/
Core.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
-- Hekili.lua
-- April 2014
local addon, ns = ...
local Hekili = _G[ addon ]
local class = Hekili.Class
local state = Hekili.State
local scripts = Hekili.Scripts
local callHook = ns.callHook
local clashOffset = ns.clashOffset
local formatKey = ns.formatKey
local getSpecializationID = ns.getSpecializationID
local getResourceName = ns.getResourceName
local orderedPairs = ns.orderedPairs
local tableCopy = ns.tableCopy
local timeToReady = ns.timeToReady
local GetItemInfo = ns.CachedGetItemInfo
local trim = string.trim
local tcopy = ns.tableCopy
local tinsert, tremove, twipe = table.insert, table.remove, table.wipe
-- checkImports()
-- Remove any displays or action lists that were unsuccessfully imported.
local function checkImports()
end
ns.checkImports = checkImports
local function EmbedBlizOptions()
local panel = CreateFrame( "Frame", "HekiliDummyPanel", UIParent )
panel.name = "Hekili"
local open = CreateFrame( "Button", "HekiliOptionsButton", panel, "UIPanelButtonTemplate" )
open:SetPoint( "CENTER", panel, "CENTER", 0, 0 )
open:SetWidth( 250 )
open:SetHeight( 25 )
open:SetText( "Open Hekili Options Panel" )
open:SetScript( "OnClick", function ()
ns.StartConfiguration()
end )
Hekili:ProfileFrame( "OptionsEmbedFrame", open )
InterfaceOptions_AddCategory( panel )
end
-- OnInitialize()
-- Addon has been loaded by the WoW client (1x).
function Hekili:OnInitialize()
self.DB = LibStub( "AceDB-3.0" ):New( "HekiliDB", self:GetDefaults(), true )
self.Options = self:GetOptions()
self.Options.args.profiles = LibStub( "AceDBOptions-3.0" ):GetOptionsTable( self.DB )
-- Reimplement LibDualSpec; some folks want different layouts w/ specs of the same class.
local LDS = LibStub( "LibDualSpec-1.0" )
LDS:EnhanceDatabase( self.DB, "Hekili" )
LDS:EnhanceOptions( self.Options.args.profiles, self.DB )
self.DB.RegisterCallback( self, "OnProfileChanged", "TotalRefresh" )
self.DB.RegisterCallback( self, "OnProfileCopied", "TotalRefresh" )
self.DB.RegisterCallback( self, "OnProfileReset", "TotalRefresh" )
local AceConfig = LibStub( "AceConfig-3.0" )
AceConfig:RegisterOptionsTable( "Hekili", self.Options )
local AceConfigDialog = LibStub( "AceConfigDialog-3.0" )
-- EmbedBlizOptions()
self:RegisterChatCommand( "hekili", "CmdLine" )
self:RegisterChatCommand( "hek", "CmdLine" )
local LDB = LibStub( "LibDataBroker-1.1", true )
local LDBIcon = LDB and LibStub( "LibDBIcon-1.0", true )
Hekili_OnAddonCompartmentClick = function( btn, arg1, arg2, checked, button )
button = button or arg1
if button == "RightButton" then ns.StartConfiguration()
else
ToggleDropDownMenu( 1, nil, ns.UI.Menu, "cursor", 8, 5 )
end
GameTooltip:Hide()
end
local function GetDataText()
local p = Hekili.DB.profile
local m = p.toggles.mode.value
local color = "FFFFD100"
if p.toggles.essences.override then
-- Don't show Essences here if it's overridden by CDs anyway?
return format( "|c%s%s|r %sCD|r %sInt|r %sDef|r", color,
m == "single" and "ST" or ( m == "aoe" and "AOE" or ( m == "dual" and "Dual" or ( m == "reactive" and "React" or "Auto" ) ) ),
p.toggles.cooldowns.value and "|cFF00FF00" or "|cFFFF0000",
p.toggles.interrupts.value and "|cFF00FF00" or "|cFFFF0000",
p.toggles.defensives.value and "|cFF00FF00" or "|cFFFF0000" )
else
return format( "|c%s%s|r %sCD|r %smCD|r %sInt|r",
color,
m == "single" and "ST" or ( m == "aoe" and "AOE" or ( m == "dual" and "Dual" or ( m == "reactive" and "React" or "Auto" ) ) ),
p.toggles.cooldowns.value and "|cFF00FF00" or "|cFFFF0000",
p.toggles.essences.value and "|cFF00FF00" or "|cFFFF0000",
p.toggles.interrupts.value and "|cFF00FF00" or "|cFFFF0000" )
end
end
Hekili_OnAddonCompartmentEnter = function( addonName, button )
GameTooltip:SetOwner( AddonCompartmentFrame )
GameTooltip:AddDoubleLine( "Hekili", GetDataText() )
GameTooltip:AddLine( "|cFFFFFFFFLeft-click to make quick adjustments.|r" )
GameTooltip:AddLine( "|cFFFFFFFFRight-click to open the options interface.|r" )
GameTooltip:Show()
end
Hekili_OnAddonCompartmentLeave = function( addonName, button )
GameTooltip:Hide()
end
AddonCompartmentFrame:RegisterAddon({
text = "Hekili",
icon = "Interface\\AddOns\\Hekili\\Textures\\LOGO-ORANGE.blp",
registerForAnyClick = true,
notCheckable = true,
func = Hekili_OnAddonCompartmentClick,
funcOnEnter = Hekili_OnAddonCompartmentEnter,
funcOnLeave = Hekili_OnAddonCompartmentLeave
} )
if LDB then
ns.UI.Minimap = ns.UI.Minimap or LDB:NewDataObject( "Hekili", {
type = "data source",
text = "Hekili",
icon = "Interface\\ICONS\\spell_nature_bloodlust",
OnClick = Hekili_OnAddonCompartmentClick,
OnEnter = function( self )
GameTooltip:SetOwner( self )
GameTooltip:AddDoubleLine( "Hekili", ns.UI.Minimap.text )
GameTooltip:AddLine( "|cFFFFFFFFLeft-click to make quick adjustments.|r" )
GameTooltip:AddLine( "|cFFFFFFFFRight-click to open the options interface.|r" )
GameTooltip:Show()
end,
OnLeave = Hekili_OnAddonCompartmentLeave
} )
function ns.UI.Minimap:RefreshDataText()
self.text = GetDataText()
end
ns.UI.Minimap:RefreshDataText()
if LDBIcon then
LDBIcon:Register( "Hekili", ns.UI.Minimap, self.DB.profile.iconStore )
end
end
self:RestoreDefaults()
self:RunOneTimeFixes()
checkImports()
ns.primeTooltipColors()
self.PendingSpecializationChange = true
callHook( "onInitialize" )
end
function Hekili:ReInitialize()
self:OverrideBinds()
self:RestoreDefaults()
checkImports()
self:RunOneTimeFixes()
self.PendingSpecializationChange = true
callHook( "onInitialize" )
if self.DB.profile.enabled == false and self.DB.profile.AutoDisabled then
self.DB.profile.AutoDisabled = nil
self.DB.profile.enabled = true
self:Enable()
end
end
function Hekili:OnEnable()
ns.StartEventHandler()
self:TotalRefresh( true )
ns.ReadKeybindings()
self.PendingSpecializationChange = true
self:ForceUpdate( "ADDON_ENABLED" )
if self.BuiltFor > self.CurrentBuild then
self:Notify( "|cFFFF0000WARNING|r: This version of Hekili is for a future version of WoW; you should reinstall for " .. self.GameBuild .. "." )
end
end
Hekili:ProfileCPU( "StartEventHandler", ns.StartEventHandler )
Hekili:ProfileCPU( "BuildUI", Hekili.BuildUI )
Hekili:ProfileCPU( "SpecializationChanged", Hekili.SpecializationChanged )
Hekili:ProfileCPU( "OverrideBinds", Hekili.OverrideBinds )
Hekili:ProfileCPU( "TotalRefresh", Hekili.TotalRefresh )
function Hekili:OnDisable()
self:UpdateDisplayVisibility()
self:BuildUI()
ns.StopEventHandler()
end
function Hekili:Toggle()
self.DB.profile.enabled = not self.DB.profile.enabled
if self.DB.profile.enabled then
self:Enable()
else
self:Disable()
end
self:UpdateDisplayVisibility()
end
local z_PVP = {
arena = true,
pvp = true
}
local listStack = {} -- listStack for a given index returns the scriptID of its caller (or 0 if called by a display).
local listCache = {} -- listCache is a table of return values for a given scriptID at various times.
local listValue = {} -- listValue shows the cached values from the listCache.
local lcPool = {}
local lvPool = {}
local Stack = {}
local Block = {}
local InUse = {}
local StackPool = {}
function Hekili:AddToStack( script, list, parent, run )
local entry = tremove( StackPool ) or {}
entry.script = script
entry.list = list
entry.parent = parent
entry.run = run
entry.priorMin = nil
tinsert( Stack, entry )
if self.ActiveDebug then
local path = "+"
for n, entry in ipairs( Stack ) do
if entry.run then
path = format( "%s%s [%s]", path, ( n > 1 and "," or "" ), entry.list )
else
path = format( "%s%s %s", path,( n > 1 and "," or "" ), entry.list )
end
end
self:Debug( path )
end
-- if self.ActiveDebug then self:Debug( "Adding " .. list .. " to stack, parent is " .. ( parent or "(none)" ) .. " (RAL = " .. tostring( run ) .. ".") end
InUse[ list ] = true
end
local blockValues = {}
local inTable = {}
local function blockHelper( ... )
local n = select( "#", ... )
twipe( inTable )
for i = 1, n do
local val = select( i, ... )
if val > 0 and val >= state.delayMin and not inTable[ val ] then
blockValues[ #blockValues + 1 ] = val
inTable[ val ] = true
end
end
table.sort( blockValues )
end
function Hekili:PopStack()
local x = tremove( Stack, #Stack )
if not x then return end
if self.ActiveDebug then
if x.run then
self:Debug( "- [%s]", x.list )
else
self:Debug( "- %s", x.list )
end
end
-- if self.ActiveDebug then self:Debug( "Removed " .. x.list .. " from stack." ) end
if x.priorMin then
if self.ActiveDebug then Hekili:Debug( "Resetting delayMin to %.2f from %.2f.", x.priorMin, state.delayMin ) end
state.delayMin = x.priorMin
end
for i = #Block, 1, -1 do
if Block[ i ].parent == x.script then
if self.ActiveDebug then self:Debug( "Removed " .. Block[ i ].list .. " from blocklist as " .. x.list .. " was its parent." ) end
tinsert( StackPool, tremove( Block, i ) )
end
end
if x.run then
-- This was called via Run Action List; we have to make sure it DOESN'T PASS until we exit this list.
if self.ActiveDebug then self:Debug( "Added " .. x.list .. " to blocklist as it was called via RAL." ) end
state:PurgeListVariables( x.list )
tinsert( Block, x )
-- Set up new delayMin.
x.priorMin = state.delayMin
local actualDelay = state.delay
-- If the script would block at the present time, find when it wouldn't block.
if scripts:CheckScript( x.script ) then
local script = scripts:GetScript( x.script )
if script.Recheck then
if #blockValues > 0 then twipe( blockValues ) end
blockHelper( script.Recheck() )
local firstFail
if Hekili.ActiveDebug then Hekili:Debug( " - blocking script did not immediately block; will attempt to tune it." ) end
for i, check in ipairs( blockValues ) do
state.delay = actualDelay + check
if not scripts:CheckScript( x.script ) then
firstFail = check
break
end
end
if firstFail and firstFail > 0 then
state.delayMin = actualDelay + firstFail
local subFail
-- May want to try to tune even better?
for i = 1, 10 do
if subFail then subFail = firstFail - ( firstFail - subFail ) / 2
else subFail = firstFail / 2 end
state.delay = actualDelay + subFail
if not scripts:CheckScript( x.script ) then
firstFail = subFail
subFail = nil
end
end
state.delayMin = actualDelay + firstFail
if Hekili.ActiveDebug then Hekili:Debug( " - setting delayMin to " .. state.delayMin .. " based on recheck and brute force." ) end
else
state.delayMin = x.priorMin
-- Leave it alone.
if Hekili.ActiveDebug then Hekili:Debug( " - leaving delayMin at " .. state.delayMin .. "." ) end
end
end
end
state.delay = actualDelay
end
InUse[ x.list ] = nil
end
function Hekili:CheckStack()
local t = state.query_time
for i, b in ipairs( Block ) do
listCache[ b.script ] = listCache[ b.script ] or tremove( lcPool ) or {}
local cache = listCache[ b.script ]
if cache[ t ] == nil then cache[ t ] = scripts:CheckScript( b.script ) end
if self.ActiveDebug then
listValue[ b.script ] = listValue[ b.script ] or tremove( lvPool ) or {}
local values = listValue[ b.script ]
values[ t ] = values[ t ] or scripts:GetConditionsAndValues( b.script )
self:Debug( "Blocking list ( %s ) called from ( %s ) would %s at %.2f.", b.list, b.script, cache[ t ] and "BLOCK" or "NOT BLOCK", state.delay )
self:Debug( values[ t ] )
end
if cache[ t ] then
return false
end
end
for i, s in ipairs( Stack ) do
listCache[ s.script ] = listCache[ s.script ] or tremove( lcPool ) or {}
local cache = listCache[ s.script ]
if cache[ t ] == nil then cache[ t ] = scripts:CheckScript( s.script ) end
if self.ActiveDebug then
listValue[ s.script ] = listValue[ s.script ] or tremove( lvPool ) or {}
local values = listValue[ s.script ]
values[ t ] = values[ t ] or scripts:GetConditionsAndValues( s.script )
self:Debug( "List ( %s ) called from ( %s ) would %s at %.2f.", s.list, s.script, cache[ t ] and "PASS" or "FAIL", state.delay )
self:Debug( values[ t ]:gsub( "%%", "%%%%" ) )
end
if not cache[ t ] then
return false
end
end
return true
end
local function return_false() return false end
local default_modifiers = {
early_chain_if = return_false,
chain = return_false,
interrupt_if = return_false,
interrupt = return_false
}
function Hekili:CheckChannel( ability, prio )
if not state.channeling then
if self.ActiveDebug then self:Debug( "CC: We aren't channeling; CheckChannel is false." ) end
return false
end
local channel = state.buff.casting.up and ( state.buff.casting.v3 == 1 ) and state.buff.casting.v1 or nil
if not channel then
if self.ActiveDebug then self:Debug( "CC: We are not channeling per buff.casting.v3; CheckChannel is false." ) end
return false
end
local a = class.abilities[ channel ]
if not a then
if self.ActiveDebug then self:Debug( "CC: We don't recognize the channeled spell; CheckChannel is false." ) end
return false
end
channel = a.key
local aura = class.auras[ a.aura or channel ]
if a.break_any and channel ~= ability then
if self.ActiveDebug then self:Debug( "CC: %s.break_any is true; break it.", channel ) end
return true
end
if not a.tick_time and ( not aura or not aura.tick_time ) then
if self.ActiveDebug then self:Debug( "CC: No aura / no aura.tick_time to forecast channel breaktimes; don't break it." ) end
return false
end
local modifiers = scripts.Channels[ state.system.packName ]
modifiers = modifiers and modifiers[ channel ] or default_modifiers
--[[ if self.ActiveDebug then
if default_modifiers == modifiers then
self:Debug( "Using default modifiers." )
else
local vals = ""
for k, v in pairs( modifiers ) do
vals = format( "%s%s = %s - ", vals, tostring( k ), tostring( type(v) == "function" and v() or v ) )
end
self:Debug( "Channel modifiers: %s", vals )
end
end ]]
local tick_time = a.tick_time or aura.tick_time
local remains = state.channel_remains
if channel == ability then
if prio <= remains + 0.01 then
if self.ActiveDebug then self:Debug( "CC: ...looks like chaining, not breaking channel.", ability ) end
return false
end
if modifiers.early_chain_if then
local eci = state.cooldown.global_cooldown.ready and ( remains < tick_time or ( ( remains - state.delay ) / tick_time ) % 1 <= 0.5 ) and modifiers.early_chain_if()
if self.ActiveDebug then self:Debug( "CC: early_chain_if returns %s...", tostring( eci ) ) end
return eci
end
if modifiers.chain then
local chain = state.cooldown.global_cooldown.ready and ( remains < tick_time ) and modifiers.chain()
if self.ActiveDebug then self:Debug( "CC: chain returns %s...", tostring( chain ) ) end
return chain
end
if self.ActiveDebug then self:Debug( "CC: channel == ability, not breaking." ) end
return false
else
-- If interrupt_global is flagged, we interrupt for any potential cast. Don't bother with additional testing.
-- REVISIT THIS: Interrupt Global allows entries from any action list rather than just the current (sub) list.
-- That means interrupt / interrupt_if should narrow their scope to the current APL (at some point, anyway).
--[[ if modifiers.interrupt_global and modifiers.interrupt_global() then
if self.ActiveDebug then self:Debug( "CC: Interrupt Global is true." ) end
return true
end ]]
local act = state.this_action
state.this_action = channel
-- We are concerned with chain and early_chain_if.
if modifiers.interrupt_if and modifiers.interrupt_if() then
local imm = modifiers.interrupt_immediate and modifiers.interrupt_immediate() or nil
local val = state.cooldown.global_cooldown.ready and ( imm or remains < tick_time or ( state.query_time - state.buff.casting.applied ) % tick_time < 0.25 )
if self.ActiveDebug then
self:Debug( "CC: Interrupt_If is %s.", tostring( val ) )
end
state.this_action = act
return val
end
if modifiers.interrupt and modifiers.interrupt() then
local val = state.cooldown.global_cooldown.ready and ( remains < tick_time or ( ( remains - state.delay ) / tick_time ) % 1 <= 0.5 )
if self.ActiveDebug then self:Debug( "CC: Interrupt is %s.", tostring( val ) ) end
state.this_action = act
return val
end
state.this_action = act
end
if self.ActiveDebug then self:Debug( "CC: No result; defaulting to false." ) end
return false
end
do
local knownCache = {}
local reasonCache = {}
function Hekili:IsSpellKnown( spell )
return state:IsKnown( spell )
--[[ local id = class.abilities[ spell ] and class.abilities[ spell ].id or spell
if knownCache[ id ] ~= nil then return knownCache[ id ], reasonCache[ id ] end
knownCache[ id ], reasonCache[ id ] = state:IsKnown( spell )
return knownCache[ id ], reasonCache[ id ] ]]
end
local disabledCache = {}
local disabledReasonCache = {}
function Hekili:IsSpellEnabled( spell )
local disabled, reason = state:IsDisabled( spell )
return not disabled, reason
end
function Hekili:ResetSpellCaches()
twipe( knownCache )
twipe( reasonCache )
twipe( disabledCache )
twipe( disabledReasonCache )
end
end
local Timer = {
start = 0,
n = {},
v = {},
Reset = function( self )
if not Hekili.ActiveDebug then return end
twipe( self.n )
twipe( self.v )
self.start = debugprofilestop()
self.n[1] = "Start"
self.v[1] = self.start
end,
Track = function( self, key )
if not Hekili.ActiveDebug then return end
tinsert( self.n, key )
tinsert( self.v, debugprofilestop() )
end,
Output = function( self )
if not Hekili.ActiveDebug then return "" end
local o = ""
for i = 2, #self.n do
o = string.format( "%s:%s(%.2f)", o, self.n[i], ( self.v[i] - self.v[i-1] ) )
end
return o
end,
Total = function( self )
if not Hekili.ActiveDebug then return "" end
return string.format("%.2f", self.v[#self.v] - self.start )
end,
}
do
local function DoYield( self, msg, time, force )
if not coroutine.running() then return end
time = time or debugprofilestop()
if msg then
self.Engine.lastYieldReason = msg
end
if force or self.maxFrameTime > 0 and time - self.activeFrameStart > self.maxFrameTime then
coroutine.yield()
end
end
local function FirstYield( self, msg, time )
if Hekili.PLAYER_ENTERING_WORLD and not Hekili.LoadingScripts then
self.Yield = DoYield
end
end
Hekili.Yield = FirstYield
end
local invalidActionWarnings = {}
function Hekili:GetPredictionFromAPL( dispName, packName, listName, slot, action, wait, depth, caller )
local specID = state.spec.id
local spec = rawget( self.DB.profile.specs, specID )
local module = class.specs[ specID ]
packName = packName or spec and spec.package
if not packName then return end
local pack
if ( packName == "UseItems" ) then pack = class.itemPack
else pack = self.DB.profile.packs[ packName ] end
local packInfo = scripts.PackInfo[ spec.package ]
local list = pack.lists[ listName ]
local debug = self.ActiveDebug
if debug then self:Debug( "Current recommendation was %s at +%.2fs.", action or "NO ACTION", wait or state.delayMax ) end
-- if debug then self:Debug( "ListCheck: Success(%s-%s)", packName, listName ) end
local precombatFilter = listName == "precombat" and state.time > 0
local rAction = action
local rWait = wait or 15
local rDepth = depth or 0
local strict = false -- disabled for now.
local force_channel = false
local stop = false
if self:IsListActive( packName, listName ) then
local actID = 1
while actID <= #list do
self:Yield( "GetPrediction... " .. dispName .. "-" .. packName .. ":" .. actID )
if rWait < state.delayMax then state.delayMax = rWait end
--[[ Watch this section, may impact usage of off-GCD abilities.
if rWait <= state.cooldown.global_cooldown.remains and not state.spec.can_dual_cast then
if debug then self:Debug( "The recommended action (%s) would be ready before the next GCD (%.2f < %.2f); exiting list (%s).", rAction, rWait, state.cooldown.global_cooldown.remains, listName ) end
break
else ]]
if rWait <= 0.2 then
if debug then self:Debug( "The recommended action (%s) is ready in less than 0.2s; exiting list (%s).", rAction, listName ) end
break
elseif state.delayMin > state.delayMax then
if debug then self:Debug( "The current minimum delay (%.2f) is greater than the current maximum delay (%.2f). Exiting list (%s).", state.delayMin, state.delayMax, listName ) end
break
elseif rAction and not packInfo.hasOffGCD and rWait <= state.cooldown.global_cooldown.remains then -- and state.settings.gcdSync then
if debug then self:Debug( "The recommended action (%s) is ready within the active GCD; exiting list (%s).", rAction, listName ) end
break
elseif rAction and state.empowering[ rAction ] then
if debug then self:Debug( "The recommended action (%s) is currently empowering; exiting list (%s).", rAction, listName ) end
break
elseif stop then
if debug then self:Debug( "The action list reached a stopping point; exiting list (%s).", listName ) end
break
end
Timer:Reset()
local entry = list[ actID ]
if self:IsActionActive( packName, listName, actID ) then
-- Check for commands before checking actual actions.
local scriptID = packName .. ":" .. listName .. ":" .. actID
local action = entry.action
state.this_action = action
state.delay = nil
local ability = class.abilities[ action ]
if not ability then
if not invalidActionWarnings[ scriptID ] then
Hekili:Error( "Priority '%s' uses action '%s' ( %s - %d ) that is not found in the abilities table.", packName, action or "unknown", listName, actID )
invalidActionWarnings[ scriptID ] = true
end
elseif state.whitelist and not state.whitelist[ action ] and ( ability.id < -99 or ability.id > 0 ) then
-- if debug then self:Debug( "[---] %s ( %s - %d) not castable while casting a spell; skipping...", action, listName, actID ) end
elseif rWait <= state.cooldown.global_cooldown.remains and not state.spec.can_dual_cast and ability.gcd ~= "off" then
-- if debug then self:Debug( "Only off-GCD abilities would be usable before the currently selected ability; skipping..." ) end
else
local entryReplaced = false
if action == "heart_essence" and class.essence_unscripted and class.active_essence then
action = class.active_essence
ability = class.abilities[ action ]
state.this_action = action
entryReplaced = true
elseif action == "trinket1" then
if state.trinket.t1.usable and state.trinket.t1.ability and not Hekili:IsItemScripted( state.trinket.t1.ability, true ) then
action = state.trinket.t1.ability
ability = class.abilities[ action ]
state.this_action = action
entryReplaced = true
else
if debug then
self:Debug( "\nBypassing 'trinket1' action because %s.", state.trinket.t1.usable and state.trinket.t1.ability and ( state.trinket.t1.ability .. " is used elsewhere in this priority" ) or "the equipped trinket #1 is not usable" )
end
ability = nil
end
elseif action == "trinket2" then
if state.trinket.t2.usable and state.trinket.t2.ability and not Hekili:IsItemScripted( state.trinket.t2.ability, true ) then
action = state.trinket.t2.ability
ability = class.abilities[ action ]
state.this_action = action
entryReplaced = true
else
if debug then
self:Debug( "\nBypassing 'trinket2' action because %s.", state.trinket.t2.usable and state.trinket.t2.ability and ( state.trinket.t2.ability .. " is used elsewhere in this priority" ) or "the equipped trinket #2 is not usable" )
end
ability = nil
end
elseif action == "main_hand" and class.abilities[ action ].key ~= action and not Hekili:IsItemScripted( action, true ) then
action = class.abilities[ action ].key
state.this_action = action
entryReplaced = true
end
rDepth = rDepth + 1
-- if debug then self:Debug( "[%03d] %s ( %s - %d )", rDepth, action, listName, actID ) end
local wait_time = state.delayMax or 15
local clash = 0
local known, reason = self:IsSpellKnown( action )
local enabled, enReason = self:IsSpellEnabled( action )
local scriptID = packName .. ":" .. listName .. ":" .. actID
state.scriptID = scriptID
if debug then
local d = ""
if entryReplaced then d = format( "\nSubstituting %s for %s action; it is otherwise not included in the priority.", action, class.abilities[ entry.action ].name ) end
if action == "call_action_list" or action == "run_action_list" then
d = d .. format( "\n%-4s %s ( %s - %d )", rDepth .. ".", ( action .. ":" .. ( state.args.list_name or "unknown" ) ), listName, actID )
elseif action == "cancel_buff" then
d = d .. format( "\n%-4s %s ( %s - %d )", rDepth .. ".", ( action .. ":" .. ( state.args.buff_name or "unknown" ) ), listName, actID )
elseif action == "cancel_action" then
d = d .. format( "\n%-4s %s ( %s - %d )", rDepth .. ".", ( action .. ":" .. ( state.args.action_name or "unknown" ) ), listName, actID )
else
d = d .. format( "\n%-4s %s ( %s - %d )", rDepth .. ".", action, listName, actID )
end
if not known then d = d .. " - " .. ( reason or "ability unknown" )
elseif not enabled then d = d .. " - ability disabled ( " .. ( enReason or "unknown" ) .. " )" end
self:Debug( d )
end
Timer:Track( "Ability Known, Enabled" )
if ability and known and enabled then
local script = scripts:GetScript( scriptID )
wait_time = state:TimeToReady()
clash = state.ClashOffset()
state.delay = wait_time
if not script then
if debug then self:Debug( "There is no script ( " .. scriptID .. " ). Skipping." ) end
elseif script.Error then
if debug then self:Debug( "The conditions for this entry contain an error. Skipping." ) end
elseif wait_time > state.delayMax then
if debug then self:Debug( "The action is not ready ( %.2f ) before our maximum delay window ( %.2f ) for this query.", wait_time, state.delayMax ) end
elseif ( rWait - state.ClashOffset( rAction ) ) - ( wait_time - clash ) <= 0.05 then
if debug then self:Debug( "The action is not ready in time ( %.2f vs. %.2f ) [ Clash: %.2f vs. %.2f ] - padded by 0.05s.", wait_time, rWait, clash, state.ClashOffset( rAction ) ) end
else
-- APL checks.
if precombatFilter and not ability.essential then
if debug then self:Debug( "We are already in-combat and this pre-combat action is not essential. Skipping." ) end
else
Timer:Track("Post-TTR and Essential")
if action == "call_action_list" or action == "run_action_list" or action == "use_items" then
-- We handle these here to avoid early forking between starkly different APLs.
local aScriptPass = true
local ts = not strict and entry.strict ~= 1 and scripts:IsTimeSensitive( scriptID )
if not entry.criteria or entry.criteria == "" then
if debug then self:Debug( "There is no criteria for %s.", action == "use_items" and "Use Items" or state.args.list_name or "this action list" ) end
-- aScriptPass = ts or self:CheckStack()
else
aScriptPass = scripts:CheckScript( scriptID ) -- and self:CheckStack() -- we'll check the stack with the list's entries.
if not aScriptPass and ts then
-- Time-sensitive criteria, let's see if we have rechecks that would pass.
state.recheck( action, script, Stack, Block )
if #state.recheckTimes == 0 then
if debug then self:Debug( "Time-sensitive Criteria FAIL at +%.2f with no valid rechecks - %s", state.offset, scripts:GetConditionsAndValues( scriptID ) ) end
ts = false
elseif state.delayMax and state.recheckTimes[ 1 ] > state.delayMax then
if debug then self:Debug( "Time-sensitive Criteria FAIL at +%.2f with rechecks outside of max delay ( %.2f > %.2f ) - %s", state.offset, state.recheckTimes[ 1 ], state.delayMax, scripts:GetConditionsAndValues( scriptID ) ) end
ts = false
elseif state.recheckTimes[ 1 ] > rWait then
if debug then self:Debug( "Time-sensitive Criteria FAIL at +%.2f with rechecks greater than wait time ( %.2f > %.2f ) - %s", state.offset, state.recheckTimes[ 1 ], rWait, scripts:GetConditionsAndValues( scriptID ) ) end
ts = false
end
else
if debug then
self:Debug( "%sCriteria for %s %s at +%.2f - %s", ts and "Time-sensitive " or "", state.args.list_name or "???", ts and "deferred" or ( aScriptPass and "PASS" or "FAIL" ), state.offset, scripts:GetConditionsAndValues( scriptID ) )
end
end
aScriptPass = ts or aScriptPass
end
if aScriptPass then
if action == "use_items" then
self:AddToStack( scriptID, "items", caller )
rAction, rWait, rDepth = self:GetPredictionFromAPL( dispName, "UseItems", "items", slot, rAction, rWait, rDepth, scriptID )
if debug then self:Debug( "Returned from Use Items; current recommendation is %s (+%.2f).", rAction or "NO ACTION", rWait ) end
self:PopStack()
else
local name = state.args.list_name
if InUse[ name ] then
if debug then self:Debug( "Action list (%s) was found, but would cause a loop.", name ) end
elseif name and pack.lists[ name ] then
if debug then self:Debug( "Action list (%s) was found.", name ) end
self:AddToStack( scriptID, name, caller, action == "run_action_list" )
rAction, rWait, rDepth = self:GetPredictionFromAPL( dispName, packName, name, slot, rAction, rWait, rDepth, scriptID )
if debug then self:Debug( "Returned from list (%s), current recommendation is %s (+%.2f).", name, rAction or "NO ACTION", rWait ) end
self:PopStack()
-- REVISIT THIS: IF A RUN_ACTION_LIST CALLER IS NOT TIME SENSITIVE, DON'T BOTHER LOOPING THROUGH IT IF ITS CONDITIONS DON'T PASS.
-- if action == "run_action_list" and not ts then
-- if debug then self:Debug( "This entry was not time-sensitive; exiting loop." ) end
-- break
-- end
else
if debug then self:Debug( "Action list (%s) not found. Skipping.", name or "no name" ) end
end
end
end
elseif action == "variable" then
local name = state.args.var_name
if class.variables[ name ] then
if debug then self:Debug( " - variable.%s references a hardcoded variable and this entry will be ignored.", name ) end
elseif name ~= nil then
state:RegisterVariable( name, scriptID, listName, Stack )
if debug then self:Debug( " - variable.%s[%s] will check this script entry ( %s )", name, tostring( state.variable[ name ] ), scriptID ) end
else
if debug then self:Debug( " - variable name not provided, skipping." ) end
end
else
-- Target Cycling.
-- We have to determine *here* whether the ability would be used on the current target or a different target.
if state.args.cycle_targets == 1 and state.settings.cycle and state.active_enemies > 1 then
state.SetupCycle( ability )
if state.cycle_enemies == 1 then
if debug then Hekili:Debug( "There is only 1 valid enemy for target cycling; canceling cycle." ) end
state.ClearCycle()
end
else
state.ClearCycle()
end
Timer:Track("Post Cycle")
local usable, why = state:IsUsable()
Timer:Track("Post Usable")
if debug then
if usable then
local cost = state.action[ action ].cost
local costType = state.action[ action ].cost_type
if cost and cost > 0 then
self:Debug( "The action (%s) is usable at (%.2f + %.2f) with cost of %d %s (have %d).", action, state.offset, state.delay, cost or 0, costType or "unknown", costType and state[ costType ] and state[ costType ].current or -1 )
else
self:Debug( "The action (%s) is usable at (%.2f + %.2f).", action, state.offset, state.delay )
end
else
self:Debug( "The action (%s) is unusable at (%.2f + %.2f) because %s.", action, state.offset, state.delay, why or "IsUsable returned false" )
end
end
if usable then
local waitValue = max( 0, rWait - state:ClashOffset( rAction ) )
local readyFirst = state.delay - clash < waitValue
if debug then self:Debug( " - the action is %sready before the current recommendation (at +%.2f vs. +%.2f).", readyFirst and "" or "NOT ", state.delay, waitValue ) end
if readyFirst then
local hasResources = true
Timer:Track("Post Ready/Clash")
if hasResources then
local channelPass = not state.channeling or ( action ~= state.channel ) or self:CheckChannel( action, rWait )
local aScriptPass = channelPass and self:CheckStack()
Timer:Track("Post Stack")
if not channelPass then
if debug then self:Debug( " - this entry cannot break the channeled spell." ) end
if action == state.channel then
stop = scripts:CheckScript( scriptID )
end
elseif not aScriptPass then
if debug then self:Debug( " - this entry would not be reached at the current time via the current action list path (%.2f).", state.delay ) end
else
if not entry.criteria or entry.criteria == '' then
if debug then
self:Debug( " - this entry has no criteria to test." )
if not channelPass then self:Debug( " - however, criteria not met to break current channeled spell." ) end
end