-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPriorityHelper.lua
More file actions
857 lines (741 loc) · 26.5 KB
/
PriorityHelper.lua
File metadata and controls
857 lines (741 loc) · 26.5 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
-- PriorityHelper.lua
-- Rotation helper framework for WotLK 3.3.5a
-- Class modules register their data via the registration API
-- Create addon namespace
PriorityHelper = {}
local DH = PriorityHelper
DH.Version = "1.1.7"
-- Namespace for internal data
local ns = {}
DH.ns = ns
ns.debug = {}
ns.inCombat = false
-- Aura tracking cache
ns.auras = {
target = { buff = {}, debuff = {} },
player = { buff = {}, debuff = {} }
}
-- Player class (detected at load time)
DH.playerClass = select(2, UnitClass("player"))
-- Class data structure
DH.Class = {
file = DH.playerClass,
resources = {},
talents = {},
glyphs = {},
auras = {},
abilities = {},
abilityByName = {},
meleeAbilities = {}, -- Keys of abilities that are melee range
range = 5,
settings = {},
}
-- State will be initialized in State.lua
DH.State = {}
-- Recommendation queue
ns.queue = {}
ns.recommendations = {}
-- Recommendation stability: prevent flickering by keeping recommendations
-- stable for at least one GCD. If the new recommendations differ from the
-- previous ones, only update if enough time has passed.
ns.lastRecTime = 0
ns.lastRecAbilities = {}
local REC_STABLE_DURATION = 0.5 -- Minimum time a recommendation stays visible
-- UI elements
ns.UI = {
MainFrame = nil,
Buttons = {}
}
-- ============================================================================
-- COOLDOWN SNOOZE SYSTEM
-- When the addon recommends a major cooldown but the player uses a different
-- ability instead, the CD recommendation is snoozed for a duration. If the
-- player manually uses the CD, the snooze clears immediately.
-- ============================================================================
ns.snooze = {} -- { [abilityKey] = expireTime }
ns.lastRecommended = nil -- The first recommended ability key from last update
-- Check if an ability is currently snoozed
function DH:IsSnoozed(key)
local expires = ns.snooze[key]
if expires and GetTime() < expires then
return true
end
ns.snooze[key] = nil
return false
end
-- Snooze an ability for a duration (default 60s)
function DH:Snooze(key, duration)
ns.snooze[key] = GetTime() + (duration or 60)
end
-- Clear snooze for an ability (player used it)
function DH:ClearSnooze(key)
ns.snooze[key] = nil
end
-- Register an ability as snoozeable with a duration
-- When recommended but skipped, it won't be recommended again for `duration` seconds
ns.snoozeable = {}
function DH:RegisterSnoozeable(key, duration)
ns.snoozeable[key] = duration or 60
end
-- ============================================================================
-- SIMULATION FRAMEWORK
-- Core simulation utilities used by all class rotation modules.
-- All sim functions operate on a sim table (not real state).
-- ============================================================================
-- ---- Registered Data ----
ns.manaCosts = {} -- { [abilityKey] = costAsPctOfBaseMana }
ns.abilityCDs = {} -- { [abilityKey] = baseCooldownSeconds }
-- ---- Registration ----
-- Register mana costs for abilities (as % of base mana, e.g. 0.05 = 5%)
function DH:RegisterManaCosts(costs)
for key, cost in pairs(costs) do
ns.manaCosts[key] = cost
end
end
-- Register base cooldown durations for abilities
function DH:RegisterAbilityCooldowns(cds)
for key, cd in pairs(cds) do
ns.abilityCDs[key] = cd
end
end
-- ---- GCD / Haste ----
-- Initialize GCD in a sim table from state (haste-adjusted)
-- resourceType: "melee" or "spell" (determines which haste to use)
function DH:SimInitGCD(simState, s, resourceType)
local hasteBonus
if resourceType == "spell" then
hasteBonus = (s.stat.spell_haste or 1) -- Already a multiplier
else
hasteBonus = 1 + (s.stat.haste or 0) / 100 -- Melee haste rating %
end
simState.haste = hasteBonus
simState.gcd = math.max(1.0, 1.5 / hasteBonus)
simState.gcd_remains = s.gcd_remains or 0
end
-- Get a haste-adjusted cast time
function DH:SimCastTime(simState, baseCastTime)
local haste = simState.haste or 1
return baseCastTime / haste
end
-- ---- Mana ----
-- Initialize mana fields in a sim table from state
function DH:SimInitMana(simState, s)
simState.mana = s.mana.current
simState.mana_max = s.mana.max
simState.mana_pct = s.mana.pct
simState.replenishment_remains = 0
simState.mp5 = 0
end
local function UpdateManaPct(simState)
simState.mana_pct = simState.mana_max > 0 and (simState.mana / simState.mana_max * 100) or 0
end
-- Spend mana for an ability (by key or override %)
function DH:SimSpendMana(simState, abilityKey, overrideCost)
local cost_pct = overrideCost or ns.manaCosts[abilityKey]
if not cost_pct then return end
simState.mana = math.max(0, simState.mana - simState.mana_max * cost_pct)
UpdateManaPct(simState)
end
-- Gain flat mana
function DH:SimGainMana(simState, amount)
simState.mana = math.min(simState.mana_max, simState.mana + amount)
UpdateManaPct(simState)
end
-- Gain mana as % of max
function DH:SimGainManaPct(simState, pct)
DH:SimGainMana(simState, simState.mana_max * pct)
end
-- Tick mana regen over time (Replenishment + MP5)
function DH:SimTickMana(simState, seconds)
if simState.replenishment_remains and simState.replenishment_remains > 0 then
simState.replenishment_remains = simState.replenishment_remains - seconds
if simState.replenishment_remains < 0 then simState.replenishment_remains = 0 end
DH:SimGainMana(simState, simState.mana_max * 0.002 * seconds)
end
if simState.mp5 and simState.mp5 > 0 then
DH:SimGainMana(simState, simState.mp5 / 5 * seconds)
end
end
-- Check if sim can afford an ability
function DH:SimCanAfford(simState, abilityKey)
local cost_pct = ns.manaCosts[abilityKey]
if not cost_pct then return true end
return simState.mana >= (simState.mana_max * cost_pct)
end
-- ---- Energy ----
-- Initialize energy fields in a sim table from state
function DH:SimInitEnergy(simState, s)
simState.energy = s.energy.current
simState.energy_max = s.energy.max or 100
simState.energy_regen = 10 -- Base 10 energy/sec
end
-- Tick energy regen over time
function DH:SimTickEnergy(simState, seconds)
simState.energy = math.min(simState.energy_max, simState.energy + simState.energy_regen * seconds)
end
-- ---- Rage ----
-- Initialize rage fields in a sim table from state
function DH:SimInitRage(simState, s)
simState.rage = s.rage.current
simState.rage_max = s.rage.max or 100
end
-- ---- Cooldown Tracking ----
-- Initialize a cooldown in sim from state
-- Returns: ready (bool), remains (seconds)
function DH:SimInitCD(s, cdKey)
local cd = s.cooldown[cdKey]
if cd then
return cd.ready, cd.remains
end
return true, 0
end
-- Tick down a cooldown field in sim, returns new ready state
function DH:SimTickCD(simState, cdField, readyField, seconds)
if simState[cdField] > 0 then
simState[cdField] = simState[cdField] - seconds
if simState[cdField] <= 0 then
simState[readyField] = true
simState[cdField] = 0
end
end
end
-- ---- Wait / Advance Time ----
-- Calculate how long to wait until the next action is available.
-- Takes a list of CD remaining values and the sim's GCD.
-- Returns the wait time (at least one GCD, so close CDs both resolve).
-- Usage: local wait = DH:SimWaitTime(sim, {sim.cs_cd, sim.judge_cd, sim.ds_cd})
function DH:SimWaitTime(simState, cdList)
local shortest = 999
for _, cd in ipairs(cdList) do
if cd > 0 and cd < shortest then
shortest = cd
end
end
return shortest
end
-- ---- Target ----
-- Initialize target fields in a sim table from state
function DH:SimInitTarget(simState, s)
simState.ttd = s.target.time_to_die
simState.target_pct = s.target.health.pct
simState.in_execute = s.target.health.pct < 20
end
-- ============================================================================
-- REGISTRATION API
-- Class modules use these to register their data into the framework.
-- ============================================================================
-- Registered class data (populated by class modules)
ns.registered = {
buffs = {}, -- List of buff keys to track
debuffs = {}, -- List of debuff keys to track
cooldowns = {}, -- { key = spellId } for cooldown tracking
talents = {}, -- { { tab, index, key }, ... }
glyphs = {}, -- { [glyphSpellId] = key, ... }
buffMap = {}, -- { [spellId] = buffKey, ... }
debuffMap = {}, -- { [spellId] = debuffKey, ... }
externalDebuffMap = {}, -- { [spellId] = debuffKey, ... }
debuffNamePatterns = {}, -- { { pattern, key }, ... } for name-based fallback
externalDebuffNamePatterns = {}, -- same for external debuffs
combatLogHandlers = {}, -- Functions called on COMBAT_LOG_EVENT_UNFILTERED
formHandlers = {}, -- { formId = { update = fn, spec = fn }, ... }
specDetector = nil, -- Function that returns current spec string
rotations = {}, -- { specKey = fn(addon), ... } returns recommendations
modes = {}, -- Rotation modes for minimap dropdown
gcdSpellId = nil, -- Spell ID used to check GCD
defaults = {}, -- Class-specific default settings
}
-- Register buff keys to track
function DH:RegisterBuffs(buffs)
for _, buff in ipairs(buffs) do
table.insert(ns.registered.buffs, buff)
end
end
-- Register debuff keys to track
function DH:RegisterDebuffs(debuffs)
for _, debuff in ipairs(debuffs) do
table.insert(ns.registered.debuffs, debuff)
end
end
-- Register cooldowns: { key = spellId, ... }
function DH:RegisterCooldowns(cooldowns)
for key, spellId in pairs(cooldowns) do
ns.registered.cooldowns[key] = spellId
end
end
-- Register talents: { { tab, index, key }, ... }
function DH:RegisterTalents(talents)
for _, data in ipairs(talents) do
table.insert(ns.registered.talents, data)
end
end
-- Register glyphs: { [glyphSpellId] = key, ... }
function DH:RegisterGlyphs(glyphs)
for spellId, key in pairs(glyphs) do
ns.registered.glyphs[spellId] = key
end
end
-- Register buff spell ID mapping: { [spellId] = buffKey, ... }
function DH:RegisterBuffMap(map)
for spellId, key in pairs(map) do
ns.registered.buffMap[spellId] = key
end
end
-- Register debuff spell ID mapping: { [spellId] = debuffKey, ... }
function DH:RegisterDebuffMap(map)
for spellId, key in pairs(map) do
ns.registered.debuffMap[spellId] = key
end
end
-- Register external debuff mapping (from other players)
function DH:RegisterExternalDebuffMap(map)
for spellId, key in pairs(map) do
ns.registered.externalDebuffMap[spellId] = key
end
end
-- Register debuff name patterns for fallback matching
function DH:RegisterDebuffNamePatterns(patterns)
for _, data in ipairs(patterns) do
table.insert(ns.registered.debuffNamePatterns, data)
end
end
-- Register external debuff name patterns
function DH:RegisterExternalDebuffNamePatterns(patterns)
for _, data in ipairs(patterns) do
table.insert(ns.registered.externalDebuffNamePatterns, data)
end
end
-- Register combat log handler function
function DH:RegisterCombatLogHandler(fn)
table.insert(ns.registered.combatLogHandlers, fn)
end
-- Register spec detector function
function DH:RegisterSpecDetector(fn)
ns.registered.specDetector = fn
end
-- Register rotation function for a spec key
function DH:RegisterRotation(specKey, fn)
ns.registered.rotations[specKey] = fn
end
-- Register a rotation mode for the minimap dropdown
-- key: unique string, data: { name, icon, rotation = fn(addon) }
function DH:RegisterMode(key, data)
ns.registered.modes = ns.registered.modes or {}
data.key = key
table.insert(ns.registered.modes, data)
end
-- Register GCD reference spell
function DH:RegisterGCDSpell(spellId)
ns.registered.gcdSpellId = spellId
end
-- Register abilities that are melee range (for UI range overlay)
function DH:RegisterMeleeAbilities(keys)
for _, key in ipairs(keys) do
DH.Class.meleeAbilities[key] = true
end
end
-- Register class-specific default settings (merged into defaults)
function DH:RegisterDefaults(classDefaults)
ns.registered.defaults = classDefaults
end
-- Register form update handler
function DH:RegisterFormHandler(formId, handler)
ns.registered.formHandlers[formId] = handler
end
-- ============================================================================
-- SETTINGS
-- ============================================================================
-- Core default settings (class-agnostic)
local coreDefaults = {
enabled = true,
debug = false,
showDebugFrame = false,
locked = false,
display = {
scale = 1.0,
alpha = 1.0,
x = 0,
y = -200,
iconSize = 50,
showGCD = true,
showRange = true,
numIcons = 3,
},
}
-- Deep copy function for defaults
local function DeepCopy(orig)
local copy
if type(orig) == 'table' then
copy = {}
for k, v in pairs(orig) do
copy[k] = DeepCopy(v)
end
else
copy = orig
end
return copy
end
-- Merge saved vars with defaults
local function MergeDefaults(saved, default)
if type(default) ~= "table" then return saved or default end
if type(saved) ~= "table" then saved = {} end
for k, v in pairs(default) do
if saved[k] == nil then
saved[k] = DeepCopy(v)
elseif type(v) == "table" then
saved[k] = MergeDefaults(saved[k], v)
end
end
return saved
end
-- Build full defaults by merging core + class-specific
local function BuildDefaults()
local defaults = DeepCopy(coreDefaults)
for k, v in pairs(ns.registered.defaults) do
defaults[k] = DeepCopy(v)
end
return defaults
end
-- Debug print
function DH:Debug(msg, ...)
if self.db and self.db.debug then
print("|cFF00FF00PriorityHelper:|r " .. string.format(msg, ...))
end
end
-- Print message
function DH:Print(msg)
print("|cFF00FF00PriorityHelper:|r " .. msg)
end
-- ============================================================================
-- EVENT HANDLING
-- ============================================================================
-- Main event frame
local eventFrame = CreateFrame("Frame", "PriorityHelperEventFrame", UIParent)
eventFrame:Hide()
-- Update timer (200 updates/sec = 5ms)
local updateElapsed = 0
local UPDATE_INTERVAL = 0.005
eventFrame:SetScript("OnUpdate", function(self, elapsed)
updateElapsed = updateElapsed + elapsed
if updateElapsed >= UPDATE_INTERVAL then
updateElapsed = 0
DH:UpdateRecommendations()
end
end)
-- Event handler
local function OnEvent(self, event, ...)
if event == "ADDON_LOADED" then
local name = ...
if name == "PriorityHelper" then
DH:OnInitialize()
DH:OnEnable()
end
elseif event == "PLAYER_REGEN_DISABLED" then
ns.inCombat = true
ns.combatStart = GetTime()
DH:ShowUI()
elseif event == "PLAYER_REGEN_ENABLED" then
ns.inCombat = false
if not UnitExists("target") then
DH:HideUI()
end
elseif event == "UNIT_AURA" then
local unit = ...
if unit == "player" or unit == "target" then
DH:UpdateRecommendations()
end
elseif event == "UNIT_POWER" then
local unit = ...
if unit == "player" then
DH:UpdateRecommendations()
end
elseif event == "SPELL_UPDATE_COOLDOWN" then
DH:UpdateRecommendations()
elseif event == "PLAYER_TARGET_CHANGED" then
DH:UpdateRecommendations()
if UnitExists("target") and UnitCanAttack("player", "target") then
DH:ShowUI()
elseif not ns.inCombat then
DH:HideUI()
end
elseif event == "UPDATE_SHAPESHIFT_FORM" then
DH:UpdateRecommendations()
elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then
DH:OnCombatLogEvent(...)
end
end
eventFrame:SetScript("OnEvent", OnEvent)
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("PLAYER_LOGIN")
-- Initialize addon
function DH:OnInitialize()
if self._initialized then return end
self._initialized = true
-- Load saved variables with merged defaults
PriorityHelperDB = PriorityHelperDB or {}
local defaults = BuildDefaults()
self.db = MergeDefaults(PriorityHelperDB, defaults)
PriorityHelperDB = self.db
-- Register slash commands
SLASH_PRIORITYHELPER1 = "/ph"
SLASH_PRIORITYHELPER2 = "/priorityhelper"
SlashCmdList["PRIORITYHELPER"] = function(msg)
DH:SlashCommand(msg)
end
self:Print("v" .. self.Version .. " loaded. Type /ph for options.")
end
-- Enable addon
function DH:OnEnable()
if self._enabled then return end
self._enabled = true
-- Register events
eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
eventFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
eventFrame:RegisterEvent("UNIT_AURA")
eventFrame:RegisterEvent("UNIT_POWER")
eventFrame:RegisterEvent("SPELL_UPDATE_COOLDOWN")
eventFrame:RegisterEvent("PLAYER_TARGET_CHANGED")
eventFrame:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
eventFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
eventFrame:RegisterEvent("COMBAT_LOG_EVENT")
-- Initialize state
if self.State and self.State.Init then
self.State:Init()
end
-- Create UI
self:InitializeUI()
-- Start update loop
eventFrame:Show()
end
-- ============================================================================
-- SLASH COMMANDS
-- ============================================================================
-- Registered slash command handlers from class modules
ns.slashCommands = {}
function DH:RegisterSlashCommand(cmd, handler, helpText)
ns.slashCommands[cmd] = { handler = handler, help = helpText }
end
function DH:SlashCommand(input)
local cmd = string.lower(input or "")
if cmd == "debug" then
self.db.debug = not self.db.debug
self:Print("Debug mode: " .. (self.db.debug and "ON" or "OFF"))
elseif cmd == "lock" then
self.db.locked = not self.db.locked
self:Print("Display " .. (self.db.locked and "locked" or "unlocked"))
if ns.UI.MainFrame then
ns.UI.MainFrame:EnableMouse(not self.db.locked)
end
elseif cmd == "reset" then
if ns.UI.MainFrame then
ns.UI.MainFrame:ClearAllPoints()
ns.UI.MainFrame:SetPoint("CENTER", UIParent, "CENTER", 0, -200)
self.db.display.x = 0
self.db.display.y = -200
end
self:Print("Display position reset")
elseif cmd == "toggle" then
self.db.enabled = not self.db.enabled
self:Print("PriorityHelper " .. (self.db.enabled and "enabled" or "disabled"))
if self.db.enabled then
eventFrame:Show()
else
eventFrame:Hide()
self:HideUI()
end
elseif cmd == "show" then
self:InitializeUI()
self:UpdateState()
self:UpdateRecommendations()
self:ShowUI()
self:Print("Forced UI show")
elseif cmd == "force" then
self:InitializeUI()
if ns.UI.MainFrame then
ns.UI.MainFrame:Show()
ns.UI.MainFrame:SetAlpha(1)
self:Print("MainFrame forced visible")
end
local _, _, questionIcon = GetSpellInfo(1) -- fallback
for i, button in ipairs(ns.UI.Buttons) do
button.icon:SetTexture(questionIcon or "Interface\\Icons\\INV_Misc_QuestionMark")
button:Show()
self:Print("Button " .. i .. " forced visible")
end
elseif cmd == "test" then
self:InitializeUI()
-- Test with first 4 registered abilities
local testRecs = {}
local count = 0
for key, ability in pairs(self.Class.abilities) do
if count < 4 then
table.insert(testRecs, { ability = key, texture = ability.texture, name = ability.name })
count = count + 1
end
end
ns.recommendations = testRecs
self:UpdateUI()
self:ShowUI()
self:Print("Test icons displayed")
elseif cmd == "status" then
self:Print("--- Status ---")
self:Print("Class: " .. tostring(self.playerClass))
self:Print("Spec: " .. tostring(self:GetActiveSpec()))
self:Print("Target: " .. tostring(UnitExists("target")) .. ", CanAttack: " .. tostring(UnitCanAttack("player", "target")))
self:Print("Recommendations: " .. #ns.recommendations)
elseif cmd == "live" then
self.db.showDebugFrame = not self.db.showDebugFrame
self:Print("Live debug: " .. (self.db.showDebugFrame and "ON" or "OFF"))
if ns.DebugFrame then
if self.db.showDebugFrame then
ns.DebugFrame:Show()
else
ns.DebugFrame:Hide()
end
end
elseif cmd == "scale" then
self:Print("Current scale: " .. self.db.display.scale)
self:Print("Use /ph scale <0.5-2.0> to change")
elseif string.match(cmd, "^scale ") then
local val = tonumber(string.match(cmd, "^scale (.+)"))
if val and val >= 0.5 and val <= 2.0 then
self.db.display.scale = val
if ns.UI.MainFrame then
ns.UI.MainFrame:SetScale(val)
end
self:Print("Scale set to " .. val)
else
self:Print("Invalid scale. Use 0.5 to 2.0")
end
elseif string.match(cmd, "^icons ") then
local val = tonumber(string.match(cmd, "^icons (.+)"))
if val and val >= 1 and val <= 4 then
self.db.display.numIcons = val
self:Print("Icons set to " .. val .. " - /reload to apply")
else
self:Print("Invalid. Use 1 to 4")
end
else
-- Try class-registered slash commands
local handled = false
for pattern, data in pairs(ns.slashCommands) do
if cmd == pattern or string.match(cmd, "^" .. pattern .. " ") or string.match(cmd, "^" .. pattern .. "$") then
data.handler(cmd)
handled = true
break
end
end
if not handled then
self:Print("Commands:")
self:Print(" /ph toggle - Enable/disable addon")
self:Print(" /ph show - Force show UI")
self:Print(" /ph status - Show debug status")
self:Print(" /ph lock - Lock/unlock display position")
self:Print(" /ph reset - Reset display position")
self:Print(" /ph scale <0.5-2.0> - Set display scale")
self:Print(" /ph icons <1-4> - Set icon count")
self:Print(" /ph debug - Toggle debug mode")
self:Print(" /ph live - Toggle live debug frame")
-- Show class-registered commands
for pattern, data in pairs(ns.slashCommands) do
if data.help then
self:Print(" /ph " .. data.help)
end
end
end
end
end
-- ============================================================================
-- COMBAT LOG
-- ============================================================================
function DH:OnCombatLogEvent(timestamp, subevent, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags, spellId, spellName, spellSchool, ...)
if sourceGUID ~= UnitGUID("player") then return end
-- Snooze detection: when player uses any ability, check if they skipped a snoozeable recommendation
if subevent == "SPELL_CAST_SUCCESS" or subevent == "SPELL_DAMAGE" or subevent == "SPELL_AURA_APPLIED" then
local topRec = ns.recommendations[1]
if topRec and spellId then
local topAbility = topRec.ability
-- Find the ability key that matches the spell just used
local castKey = nil
local numericId = tonumber(spellId)
for key, ability in pairs(self.Class.abilities) do
if ability.id == numericId or ability.id == spellId then
castKey = key
break
end
end
if castKey then
-- Player used the snoozed ability — clear its snooze
if ns.snooze[castKey] then
self:ClearSnooze(castKey)
end
-- Player used a different ability than recommended — snooze the recommended one
if castKey ~= topAbility and ns.snoozeable and ns.snoozeable[topAbility] then
self:Snooze(topAbility, ns.snoozeable[topAbility])
end
end
end
end
-- Dispatch to registered handlers
for _, handler in ipairs(ns.registered.combatLogHandlers) do
handler(subevent, sourceGUID, destGUID, spellId, spellName, ...)
end
end
-- ============================================================================
-- CORE LOGIC
-- ============================================================================
-- Update state
function DH:UpdateState()
if not self.db or not self.db.enabled then return end
if self.State and self.State.Reset then
self.State:Reset()
end
end
-- Get active spec using registered detector
function DH:GetActiveSpec()
if ns.registered.specDetector then
return ns.registered.specDetector()
end
return "unknown"
end
-- Update recommendations using registered rotations
function DH:UpdateRecommendations()
if not self.db or not self.db.enabled then return end
if not UnitExists("target") and not ns.inCombat then return end
-- Ensure state is updated
self:UpdateState()
local spec = self:GetActiveSpec()
local recommendations = {}
-- Try registered rotation for current spec
local rotationFn = ns.registered.rotations[spec]
if rotationFn then
recommendations = rotationFn(self)
end
ns.recommendations = recommendations
self:UpdateUI()
if #recommendations > 0 then
self:ShowUI()
end
end
-- ============================================================================
-- UI FUNCTIONS (implemented in UI.lua)
-- ============================================================================
function DH:InitializeUI()
if ns.InitializeUI then
ns.InitializeUI(self)
end
end
function DH:UpdateUI()
if ns.UpdateUI then
ns.UpdateUI(self)
end
end
function DH:ShowUI()
if ns.UI.MainFrame then
ns.UI.MainFrame:Show()
end
end
function DH:HideUI()
if ns.UI.MainFrame then
ns.UI.MainFrame:Hide()
end
end