-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
2186 lines (1818 loc) · 63.6 KB
/
Copy pathCore.lua
File metadata and controls
2186 lines (1818 loc) · 63.6 KB
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
WCM = WCM or {}
-------------------------------------------------
-- Utils
-------------------------------------------------
local function Print(msg)
if DEFAULT_CHAT_FRAME then
DEFAULT_CHAT_FRAME:AddMessage("|cff66ccff[WCM]|r " .. tostring(msg))
end
end
local function Clamp(v, a, b)
if v < a then return a end
if v > b then return b end
return v
end
local function Abs(x)
if x < 0 then return -x end
return x
end
local function Now()
return GetTime()
end
local function Lower(s)
if not s then return "" end
return string.lower(s)
end
local function F1(x)
return string.format("%.1f", x or 0)
end
local function Round2(v)
return math.floor(v * 100 + 0.5) / 100
end
local function InCombat()
if type(InCombatLockdown) == "function" then
return InCombatLockdown() and true or false
end
if type(UnitAffectingCombat) == "function" then
return UnitAffectingCombat("player") and true or false
end
return false
end
local function CopyTableShallow(src)
local dst = {}
if not src then return dst end
for k, v in pairs(src) do
dst[k] = v
end
return dst
end
Print("Core.lua loaded")
-------------------------------------------------
-- DB
-------------------------------------------------
local function InitDB()
WarriorCombatManagerDB = WarriorCombatManagerDB or {}
local db = WarriorCombatManagerDB
db.settings = db.settings or {}
db.history = db.history or {}
if db.settings.left == nil then db.settings.left = nil end
if db.settings.top == nil then db.settings.top = nil end
if db.settings.locked == nil then db.settings.locked = true end
if db.settings.scale == nil then db.settings.scale = 1.0 end
if db.settings.x == nil then db.settings.x = 0 end
if db.settings.y == nil then db.settings.y = 220 end
if db.settings.highlightWindow == nil then db.settings.highlightWindow = 0.7 end
if db.settings.incomingWindow == nil then db.settings.incomingWindow = 4.0 end
if db.settings.dimAlpha == nil then db.settings.dimAlpha = 0.18 end
if db.settings.baseAlpha == nil then db.settings.baseAlpha = 0.35 end
if db.settings.bwEnabled == nil then db.settings.bwEnabled = true end
if db.settings.defaultPredicted == nil then db.settings.defaultPredicted = 120 end
if db.settings.avgN == nil then db.settings.avgN = 3 end
if db.settings.maxHistory == nil then db.settings.maxHistory = 12 end
if db.settings.trinketCD == nil then db.settings.trinketCD = 120 end
if db.settings.loseUseBuffer == nil then db.settings.loseUseBuffer = 2.0 end
if db.settings.executeThreshold == nil then db.settings.executeThreshold = 20 end
if db.settings.livePredict == nil then db.settings.livePredict = true end
if db.settings.livePredictPeriod == nil then db.settings.livePredictPeriod = 5.0 end
if db.settings.livePredictAlpha == nil then db.settings.livePredictAlpha = 0.15 end
if db.settings.livePredictWarmup == nil then db.settings.livePredictWarmup = 8.0 end
if db.settings.livePredictMinDrop == nil then db.settings.livePredictMinDrop = 3.0 end
if db.settings.strictFinalStack == nil then db.settings.strictFinalStack = true end
if db.settings.showPrompt == nil then db.settings.showPrompt = true end
if db.settings.promptOnlyPressNow == nil then db.settings.promptOnlyPressNow = true end
if db.settings.executeBarRed == nil then db.settings.executeBarRed = true end
if db.settings.executeZoom == nil then db.settings.executeZoom = true end
if db.settings.executeZoomByPct == nil then db.settings.executeZoomByPct = true end
if db.settings.executeZoomWindow == nil then db.settings.executeZoomWindow = 30 end
if db.settings.testExecuteSim == nil then db.settings.testExecuteSim = true end
if db.settings.testAutoStop == nil then db.settings.testAutoStop = true end
if db.settings.autoHideOOC == nil then db.settings.autoHideOOC = true end
if db.settings.lockToBoss == nil then db.settings.lockToBoss = true end
if db.settings.preferAlign == nil then db.settings.preferAlign = true end
if db.settings.showAllUses == nil then db.settings.showAllUses = true end
end
local function S()
return WarriorCombatManagerDB.settings
end
local function H()
return WarriorCombatManagerDB.history
end
-------------------------------------------------
-- State
-------------------------------------------------
WCM.state = WCM.state or {
running = false,
startTime = 0,
predicted = 120,
basePredicted = 120,
elapsed = 0,
boss = nil,
source = "manual",
execute = false,
targetPct = nil,
lastPct = nil,
lastPredictAdjust = 0,
firstPct = nil,
bossGUID = nil,
bossNameLock = nil,
}
-------------------------------------------------
-- History
-------------------------------------------------
local function EnsureBossHistory(boss)
if not boss or boss == "" then return nil end
local hist = H()[boss]
if not hist then
hist = { times = {}, last = nil }
H()[boss] = hist
end
if not hist.times then hist.times = {} end
return hist
end
local function PushBossTime(boss, seconds)
seconds = tonumber(seconds)
if not boss or boss == "" then return end
if not seconds or seconds <= 0 then return end
local hist = EnsureBossHistory(boss)
if not hist then return end
table.insert(hist.times, seconds)
hist.last = seconds
local maxH = S().maxHistory or 12
while table.getn(hist.times) > maxH do
table.remove(hist.times, 1)
end
end
local function GetBossPredicted(boss)
local n = S().avgN or 3
local def = S().defaultPredicted or 120
if not boss or boss == "" then return def end
local hist = H()[boss]
if not hist or not hist.times or table.getn(hist.times) == 0 then
return def
end
local count = table.getn(hist.times)
local take = n
if take > count then take = count end
local sum = 0
local i = count - take + 1
while i <= count do
sum = sum + (hist.times[i] or 0)
i = i + 1
end
if take <= 0 then return def end
local avg = sum / take
if avg < 10 then avg = 10 end
return avg
end
function WCM:PrintBossHistory(boss)
if not boss or boss == "" then
Print("usage: /wcm hist <bossname>")
return
end
local hist = H()[boss]
if not hist or not hist.times or table.getn(hist.times) == 0 then
Print("No history for " .. boss)
return
end
local s = ""
local i = 1
while i <= table.getn(hist.times) do
s = s .. string.format("%.1f", hist.times[i])
if i < table.getn(hist.times) then s = s .. ", " end
i = i + 1
end
Print("History " .. boss .. ": [" .. s .. "] last=" .. tostring(hist.last) ..
" predicted=" .. string.format("%.1f", GetBossPredicted(boss)))
end
-------------------------------------------------
-- Boss Locking
-------------------------------------------------
local function ResetBossLock()
WCM.state.bossGUID = nil
WCM.state.bossNameLock = nil
end
local function TryLockBossFromUnit(unit, bossName)
if not unit then return false end
if type(UnitExists) ~= "function" then return false end
if not UnitExists(unit) then return false end
if type(UnitName) == "function" then
local n = UnitName(unit)
if bossName and n and n == bossName then
WCM.state.bossNameLock = bossName
if type(UnitGUID) == "function" then
WCM.state.bossGUID = UnitGUID(unit)
end
return true
end
end
return false
end
local function LockBoss(bossName)
ResetBossLock()
WCM.state.bossNameLock = bossName
if not S().lockToBoss then return end
local locked = false
locked = TryLockBossFromUnit("target", bossName) or locked
locked = TryLockBossFromUnit("focus", bossName) or locked
if locked and WCM.state.bossGUID then
Print("Boss locked: " .. tostring(bossName) .. " guid=" .. tostring(WCM.state.bossGUID))
else
Print("Boss locked by name: " .. tostring(bossName))
end
end
local function MatchLockedBoss(unit)
if not S().lockToBoss then return true end
if not unit then return false end
if type(UnitExists) ~= "function" or not UnitExists(unit) then return false end
local guidLock = WCM.state.bossGUID
if guidLock and type(UnitGUID) == "function" then
local g = UnitGUID(unit)
if g and g == guidLock then return true end
return false
end
local nameLock = WCM.state.bossNameLock
if nameLock and type(UnitName) == "function" then
local n = UnitName(unit)
if n and n == nameLock then return true end
end
return false
end
local function GetLockedBossUnit()
if not S().lockToBoss then
if type(UnitExists) == "function" and UnitExists("target") then return "target" end
return nil
end
if MatchLockedBoss("target") then return "target" end
if MatchLockedBoss("focus") then return "focus" end
return nil
end
local function GetLockedBossHealthPct()
local unit = GetLockedBossUnit()
if not unit then return nil end
if type(UnitHealth) ~= "function" or type(UnitHealthMax) ~= "function" then return nil end
local cur = UnitHealth(unit)
local mx = UnitHealthMax(unit)
if not mx or mx <= 0 then return nil end
if not cur then return nil end
return (cur / mx) * 100
end
local function IsLockedBossAttackable()
local unit = GetLockedBossUnit()
if not unit then return false end
if type(UnitCanAttack) == "function" then
return UnitCanAttack("player", unit) and true or false
end
return true
end
-------------------------------------------------
-- Start/Stop
-------------------------------------------------
function WCM:StartTest(predicted)
predicted = tonumber(predicted) or (S().defaultPredicted or 120)
predicted = Clamp(predicted, 10, 9999)
self.state.running = true
self.state.startTime = Now()
self.state.predicted = predicted
self.state.basePredicted = predicted
self.state.elapsed = 0
self.state.boss = "Test"
self.state.source = "manual"
self.state.execute = false
self.state.targetPct = nil
self.state.lastPct = nil
self.state.lastPredictAdjust = 0
self.state.firstPct = nil
ResetBossLock()
if WCM.UI then WCM.UI:Show(true) end
Print("Test started. predicted=" .. tostring(predicted) .. "s")
end
function WCM:StopTest()
self.state.running = false
self.state.elapsed = 0
self.state.boss = nil
self.state.source = "manual"
self.state.execute = false
self.state.targetPct = nil
self.state.lastPct = nil
self.state.lastPredictAdjust = 0
self.state.firstPct = nil
ResetBossLock()
Print("Test stopped")
end
function WCM:StartEncounter(boss, predicted, source)
predicted = tonumber(predicted) or GetBossPredicted(boss)
predicted = Clamp(predicted, 10, 9999)
self.state.running = true
self.state.startTime = Now()
self.state.predicted = predicted
self.state.basePredicted = predicted
self.state.elapsed = 0
self.state.boss = boss
self.state.source = source or "bigwigs"
self.state.execute = false
self.state.targetPct = nil
self.state.lastPct = nil
self.state.lastPredictAdjust = 0
self.state.firstPct = nil
LockBoss(boss)
if WCM.UI then WCM.UI:Show(true) end
Print("Engaged: " .. tostring(boss) .. " predicted=" .. string.format("%.1f", predicted) .. " src=" .. tostring(self.state.source))
end
function WCM:StopEncounter(durationFromBW, bossName, source)
if not self.state.running then return end
local boss = bossName or self.state.boss
local elapsed = Now() - (self.state.startTime or Now())
local dur = tonumber(durationFromBW)
if not dur or dur <= 0 then dur = elapsed end
self.state.running = false
self.state.elapsed = 0
self.state.execute = false
self.state.targetPct = nil
self.state.lastPct = nil
self.state.lastPredictAdjust = 0
self.state.firstPct = nil
ResetBossLock()
if boss and boss ~= "" and boss ~= "Test" then
PushBossTime(boss, dur)
Print("Victory: " .. tostring(boss) .. " duration=" .. string.format("%.2f", dur) ..
" predicted(now)=" .. string.format("%.1f", GetBossPredicted(boss)) .. " src=" .. tostring(source or self.state.source))
else
Print("Victory: Test duration=" .. string.format("%.2f", dur))
end
if S().autoHideOOC and (not InCombat()) then
if WCM.UI then WCM.UI:Hide() end
end
end
-------------------------------------------------
-- Ability names
-------------------------------------------------
local SPELLS = {
DW = "Death Wish",
RECK = "Recklessness",
BR = "Bloodrage",
BF = "Blood Fury",
}
-------------------------------------------------
-- Spellbook helpers
-------------------------------------------------
local SpellIndexCache = {}
local function ResetSpellCache()
SpellIndexCache = {}
end
local function FindSpellIndexByName(spellName)
if not spellName or spellName == "" then return nil end
if SpellIndexCache[spellName] ~= nil then
if SpellIndexCache[spellName] == false then return nil end
return SpellIndexCache[spellName]
end
if type(GetNumSpellTabs) ~= "function" then
SpellIndexCache[spellName] = false
return nil
end
local numTabs = GetNumSpellTabs()
local t = 1
while t <= numTabs do
local _, _, offset, numSpells = GetSpellTabInfo(t)
local i = offset + 1
local last = offset + numSpells
while i <= last do
local name = GetSpellName(i, BOOKTYPE_SPELL)
if name == spellName then
SpellIndexCache[spellName] = i
return i
end
i = i + 1
end
t = t + 1
end
SpellIndexCache[spellName] = false
return nil
end
local function HasSpell(spellName)
return FindSpellIndexByName(spellName) ~= nil
end
local function IsSpellReady(spellName)
local idx = FindSpellIndexByName(spellName)
if not idx then return false end
local start, dur, enabled = GetSpellCooldown(idx, BOOKTYPE_SPELL)
if enabled == 0 then return false end
if not start or not dur then return false end
if dur == 0 or start == 0 then return true end
return ((start + dur) - Now()) <= 0
end
-------------------------------------------------
-- Trinket helpers
-------------------------------------------------
local function GetInvTexture(slot)
local tex = GetInventoryItemTexture("player", slot)
if tex == "" then tex = nil end
return tex
end
local function GetInvLink(slot)
local link = GetInventoryItemLink("player", slot)
if link == "" then link = nil end
return link
end
local function IsTrinketReady(slot)
local start, dur, enabled = GetInventoryItemCooldown("player", slot)
if enabled == 0 then return false end
if not start or not dur then return false end
if dur == 0 or start == 0 then return true end
return ((start + dur) - Now()) <= 0
end
local WCM_TT = nil
local function EnsureTooltip()
if WCM_TT then return end
WCM_TT = CreateFrame("GameTooltip", "WCM_ScanTooltip", UIParent, "GameTooltipTemplate")
WCM_TT:SetOwner(UIParent, "ANCHOR_NONE")
end
local function TooltipHasUseTextFromInventory(slot)
EnsureTooltip()
WCM_TT:ClearLines()
if type(WCM_TT.SetInventoryItem) ~= "function" then return false end
WCM_TT:SetInventoryItem("player", slot)
local i = 1
while i <= 20 do
local line = getglobal("WCM_ScanTooltipTextLeft" .. i)
if line then
local txt = line:GetText()
if txt then
local l = Lower(txt)
if l and (string.find(l, "use") or string.find(l, "use:")) then
return true
end
end
end
i = i + 1
end
return false
end
local function TrinketHasUse(slot)
local link = GetInvLink(slot)
if not link then return false end
if type(GetItemSpell) == "function" then
local spellName = GetItemSpell(link)
if spellName and spellName ~= "" then
return true
end
end
return TooltipHasUseTextFromInventory(slot)
end
-------------------------------------------------
-- Icons
-------------------------------------------------
local ICONS = {
DW = "Interface\\Icons\\Spell_Shadow_DeathPact",
RECK = "Interface\\Icons\\Ability_CriticalStrike",
BR = "Interface\\Icons\\Ability_Racial_BloodRage",
BF = "Interface\\Icons\\Racial_Orc_BerserkerStrength",
UNKNOWN = "Interface\\Icons\\INV_Misc_QuestionMark",
}
-------------------------------------------------
-- Cooldowns
-------------------------------------------------
local COOLDOWNS = {
{ id="DW", kind="spell", name=SPELLS.DW, icon=ICONS.DW, cd=180, dur=30, anchorRem=30, prio=1 },
{ id="T13", kind="trinket", slot=13, cdKey="trinketCD", dur=20, anchorRem=20, prio=2 },
{ id="T14", kind="trinket", slot=14, cdKey="trinketCD", dur=20, anchorRem=20, prio=2 },
{ id="BF", kind="spell", name=SPELLS.BF, icon=ICONS.BF, cd=120, dur=15, anchorRem=15, prio=3 },
{ id="RECK", kind="spell", name=SPELLS.RECK, icon=ICONS.RECK, cd=1800, dur=15, anchorRem=15, prio=4, oncePerFight=true },
{ id="BR", kind="spell", name=SPELLS.BR, icon=ICONS.BR, cd=60, dur=10, anchorRem=10, prio=5 },
}
local function IsTrinketEligible(slot)
local link = GetInvLink(slot)
if not link then return false end
if not TrinketHasUse(slot) then return false end
return true
end
local function CooldownAvailable(def)
if def.kind == "spell" then
return HasSpell(def.name)
end
if def.kind == "trinket" then
return IsTrinketEligible(def.slot)
end
return false
end
local function CooldownReady(def)
if def.kind == "spell" then
return IsSpellReady(def.name)
end
if def.kind == "trinket" then
return IsTrinketReady(def.slot)
end
return false
end
local function CooldownTexture(def)
if def.kind == "spell" then
return def.icon or ICONS.UNKNOWN
end
if def.kind == "trinket" then
return GetInvTexture(def.slot) or ICONS.UNKNOWN
end
return ICONS.UNKNOWN
end
local function GetDefCooldownSeconds(def)
local cd = def.cd
if def.cdKey == "trinketCD" then
cd = tonumber(S().trinketCD) or 120
end
return cd
end
-------------------------------------------------
-- Schedules
-------------------------------------------------
local function BuildScheduleFromStart(predicted, cd)
local out = {}
predicted = tonumber(predicted) or 0
cd = tonumber(cd) or 0
if predicted <= 0 or cd <= 0 then return out end
local t = 0
while t <= predicted do
table.insert(out, t)
t = t + cd
end
return out
end
local function BuildScheduleFromEnd(predicted, cd, anchorRem)
local out = {}
predicted = tonumber(predicted) or 0
cd = tonumber(cd) or 0
anchorRem = tonumber(anchorRem) or 0
if predicted <= 0 or cd <= 0 then return out end
local last = predicted - anchorRem
if last < 0 then last = 0 end
local t = last
while t >= 0 do
table.insert(out, 1, t)
t = t - cd
end
return out
end
local function BuildSchedule(def, predicted)
local cd = GetDefCooldownSeconds(def)
if def.oncePerFight then
local anchor = def.anchorRem or def.dur or 0
local one = predicted - (anchor or 0)
if one < 0 then one = 0 end
return { one }
end
if S().preferAlign and def.anchorRem then
return BuildScheduleFromEnd(predicted, cd, def.anchorRem)
end
return BuildScheduleFromStart(predicted, cd)
end
local function NextMarkerInSchedule(sched, elapsed)
if not sched or table.getn(sched) == 0 then return nil end
local best = nil
local i = 1
while i <= table.getn(sched) do
local tMark = sched[i]
if tMark >= elapsed then
local dt = tMark - elapsed
if (not best) or dt < best then
best = dt
end
end
i = i + 1
end
return best
end
local function NearestMarkerDelta(sched, elapsed)
if not sched or table.getn(sched) == 0 then return nil end
local bestAbs, bestDt = nil, nil
local i = 1
while i <= table.getn(sched) do
local tMark = sched[i]
local dt = elapsed - tMark
local a = Abs(dt)
if (not bestAbs) or a < bestAbs then
bestAbs = a
bestDt = dt
end
i = i + 1
end
return bestDt
end
local function ScheduleHasZeroMarker(sched)
if not sched then return false end
local i = 1
while i <= table.getn(sched) do
if Abs((sched[i] or 0) - 0) < 0.001 then return true end
i = i + 1
end
return false
end
-------------------------------------------------
-- Execute detection + live prediction adjustment
-------------------------------------------------
local function UpdateExecuteState()
WCM.state.execute = false
WCM.state.targetPct = nil
if not WCM.state.running then return end
local thr = tonumber(S().executeThreshold) or 20
thr = Clamp(thr, 1, 99)
if WCM.state.source == "manual" and S().testExecuteSim then
local predicted = tonumber(WCM.state.predicted) or 0
local elapsed = tonumber(WCM.state.elapsed) or 0
if predicted > 0 then
local execStart = predicted * (1 - (thr / 100))
if elapsed >= execStart then
WCM.state.execute = true
end
end
return
end
if not IsLockedBossAttackable() then return end
local pct = GetLockedBossHealthPct()
if not pct then return end
WCM.state.targetPct = pct
if not WCM.state.firstPct then
WCM.state.firstPct = pct
end
if pct <= thr then
WCM.state.execute = true
end
end
local function LivePredictTick()
if not S().livePredict then return end
if not WCM.state.running then return end
if not IsLockedBossAttackable() then return end
local pct = WCM.state.targetPct
if not pct then return end
if pct >= 99 then return end
if pct <= 1 then return end
local warmup = tonumber(S().livePredictWarmup) or 8.0
warmup = Clamp(warmup, 0, 60)
if (WCM.state.elapsed or 0) < warmup then return end
local minDrop = tonumber(S().livePredictMinDrop) or 3.0
minDrop = Clamp(minDrop, 0, 50)
local first = WCM.state.firstPct
if not first then return end
if (first - pct) < minDrop then return end
local t = Now()
local period = tonumber(S().livePredictPeriod) or 5.0
if (t - (WCM.state.lastPredictAdjust or 0)) < period then return end
local lastPct = WCM.state.lastPct
WCM.state.lastPct = pct
if lastPct and pct > lastPct then return end
local elapsed = WCM.state.elapsed or 0
local fracDone = 1 - (pct / 100)
if fracDone <= 0.01 then return end
local estTotal = elapsed / fracDone
if not estTotal or estTotal < 10 or estTotal > 9999 then return end
local alpha = tonumber(S().livePredictAlpha) or 0.15
alpha = Clamp(alpha, 0.02, 0.50)
local cur = WCM.state.predicted or WCM.state.basePredicted or 120
local newPred = (cur * (1 - alpha)) + (estTotal * alpha)
newPred = Clamp(newPred, 10, 9999)
WCM.state.predicted = newPred
WCM.state.lastPredictAdjust = t
end
-------------------------------------------------
-- Visible range (execute zoom)
-------------------------------------------------
local function GetVisibleRange(elapsed, predicted)
local vStart = 0
local vEnd = predicted
if S().executeZoom and WCM.state.execute then
if S().executeZoomByPct then
local thr = tonumber(S().executeThreshold) or 20
thr = Clamp(thr, 1, 99)
local win = predicted * (thr / 100)
if win < 5 then win = 5 end
vEnd = predicted
vStart = predicted - win
if vStart < 0 then vStart = 0 end
else
local win2 = tonumber(S().executeZoomWindow) or 30
win2 = Clamp(win2, 10, 120)
vEnd = predicted
vStart = predicted - win2
if vStart < 0 then vStart = 0 end
end
end
if vEnd <= vStart then
vStart = 0
vEnd = predicted
end
return vStart, vEnd
end
-------------------------------------------------
-- Eligibility rules
-------------------------------------------------
local function IsDefAllowedNow(def)
if def.oncePerFight then
if not WCM.state.execute then return false end
end
return true
end
-------------------------------------------------
-- Prompt logic
-------------------------------------------------
local function MissedLastMarkerAndNoFuture(elapsed, predicted, cd, sched)
local hw = tonumber(S().highlightWindow) or 0.7
local buffer = tonumber(S().loseUseBuffer) or 2.0
local nextDt = NextMarkerInSchedule(sched, elapsed)
if nextDt ~= nil then return false end
local remaining = predicted - elapsed
if remaining < 0 then remaining = 0 end
if remaining <= (cd + buffer) then
local dtNearest = NearestMarkerDelta(sched, elapsed)
if dtNearest and dtNearest > hw then
return true
end
end
return false
end
local function GetDefPromptState(def, elapsed, predicted)
if (not CooldownAvailable(def)) then return nil end
if (not IsDefAllowedNow(def)) then return nil end
if (not CooldownReady(def)) then return nil end
local hw = tonumber(S().highlightWindow) or 0.7
local soonW = tonumber(S().incomingWindow) or 4.0
local cd = GetDefCooldownSeconds(def)
local sched = BuildSchedule(def, predicted)
if not sched or table.getn(sched) == 0 then return "HOLD", nil end
if elapsed <= hw and ScheduleHasZeroMarker(sched) then
return "PRESS NOW", -elapsed
end
local dtNearest = NearestMarkerDelta(sched, elapsed)
if not dtNearest then return "HOLD", nil end
local absNearest = Abs(dtNearest)
if absNearest <= hw then
return "PRESS NOW", dtNearest
end
if S().preferAlign then
if MissedLastMarkerAndNoFuture(elapsed, predicted, cd, sched) then
return "PRESS NOW", dtNearest
end
else
local remaining = predicted - elapsed
if remaining < 0 then remaining = 0 end
if remaining <= (cd + (tonumber(S().loseUseBuffer) or 2.0)) then
return "PRESS NOW", dtNearest
end
end
if absNearest <= soonW then
return "SOON", dtNearest
end
return "HOLD", dtNearest
end
local function MakeFinalPrimary(elapsed, predicted)
if not S().strictFinalStack then return nil end
local remaining = predicted - elapsed
if remaining < 0 then remaining = 0 end
if remaining > 30 then return nil end
local bestId = nil
local bestScore = nil
local i = 1
while i <= table.getn(COOLDOWNS) do
local def = COOLDOWNS[i]
if def.anchorRem and CooldownAvailable(def) and CooldownReady(def) and IsDefAllowedNow(def) then
local diff = Abs(remaining - def.anchorRem)
local score = diff + (def.prio or 50) * 0.01
if not bestScore or score < bestScore then
bestScore = score
bestId = def.id
end
end
i = i + 1
end
return bestId
end
local function PickBestPrompt(elapsed, predicted, forcePrimaryId)
local bestDef = nil
local bestState = nil
local bestScore = nil
local primaryDef = nil
if forcePrimaryId then
local pi = 1
while pi <= table.getn(COOLDOWNS) do
if COOLDOWNS[pi].id == forcePrimaryId then
primaryDef = COOLDOWNS[pi]
break
end
pi = pi + 1
end
end
local function Consider(def)
local state, dt = GetDefPromptState(def, elapsed, predicted)
if not state then return end
local prio = def.prio or 50
local score = 9999
if state == "PRESS NOW" then
score = 0 + prio * 0.01
elseif state == "SOON" then
score = 10 + prio * 0.01 + (Abs(dt or 0) * 0.05)
else
score = 50 + prio * 0.01 + (Abs(dt or 0) * 0.02)
end
if (not bestScore) or score < bestScore then
bestScore = score
bestDef = def
bestState = state
end
end
if primaryDef and CooldownAvailable(primaryDef) then
Consider(primaryDef)
end
local i = 1
while i <= table.getn(COOLDOWNS) do
Consider(COOLDOWNS[i])
i = i + 1
end
return bestDef, bestState
end
-------------------------------------------------
-- UI
-------------------------------------------------
WCM.UI = WCM.UI or {}