Repository navigation
Expand file tree
/
Copy pathEngine.lua
More file actions
1078 lines (946 loc) · 38.6 KB
/
Copy pathEngine.lua
File metadata and controls
1078 lines (946 loc) · 38.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
-- HealIQ Engine.lua
-- Priority logic engine that determines the suggested spell
local addonName, HealIQ = ...
HealIQ.Engine = {}
local Engine = HealIQ.Engine
-- Targeting types and their associated icons
-- Icon path constants
local ICON_SELF = "Interface\\Icons\\Ability_Warrior_BattleShout"
local ICON_TANK = "Interface\\Icons\\Ability_Warrior_DefensiveStance"
local ICON_CURRENT_TARGET = "Interface\\Icons\\Ability_Hunter_MarkedForDeath"
local ICON_FOCUS = "Interface\\Icons\\Spell_Shadow_Teleport"
local ICON_PARTY_MEMBER = "Interface\\Icons\\Achievement_Guildperk_EverybodysFriend"
local ICON_LOWEST_HEALTH = "Interface\\Icons\\Spell_ChargeNegative"
local ICON_TARGET_OF_TARGET = "Interface\\Icons\\Ability_Hunter_SniperShot"
local ICON_GROUND_TARGET = "Interface\\Icons\\Spell_Arcane_TeleportBoralus"
local TARGET_TYPES = {
SELF = {
name = "Self",
icon = ICON_SELF,
description = "Cast on yourself"
},
TANK = {
name = "Tank",
icon = ICON_TANK,
description = "Cast on main tank"
},
CURRENT_TARGET = {
name = "Current Target",
icon = ICON_CURRENT_TARGET,
description = "Cast on current target"
},
FOCUS = {
name = "Focus",
icon = ICON_FOCUS,
description = "Cast on focus target"
},
PARTY_MEMBER = {
name = "Party Member",
icon = ICON_PARTY_MEMBER,
description = "Cast on any party member"
},
LOWEST_HEALTH = {
name = "Lowest Health",
icon = ICON_LOWEST_HEALTH,
description = "Target with lowest health"
},
TARGET_OF_TARGET = {
name = "Target's Target",
icon = ICON_TARGET_OF_TARGET,
description = "Cast on target's target"
},
GROUND_TARGET = {
name = "Ground Target",
icon = ICON_GROUND_TARGET,
description = "Place on ground"
},
TANK_RELATIONSHIP = {
name = "Tank Relationship",
icon = ICON_TANK,
description = "Establish beneficial relationship with tank"
}
}
-- Spell information for suggestions with targeting recommendations
-- Updated priorities based on Wowhead Restoration Druid guide
local SPELLS = {
-- Emergency/Major Cooldowns (Highest Priority)
TRANQUILITY = {
id = HealIQ.SpellData.TRANQUILITY,
name = "Tranquility",
icon = "Interface\\Icons\\Spell_Nature_Tranquility",
priority = 1,
targets = {TARGET_TYPES.SELF}, -- Channel on self, affects all nearby allies
targetingDescription = "Channel while positioned near injured allies"
},
INCARNATION_TREE = {
id = HealIQ.SpellData.INCARNATION_TREE,
name = "Incarnation",
icon = "Interface\\Icons\\Spell_Druid_Incarnation",
priority = 2,
targets = {TARGET_TYPES.SELF}, -- Self-buff
targetingDescription = "Activate when group healing is needed"
},
NATURES_SWIFTNESS = {
id = HealIQ.SpellData.NATURES_SWIFTNESS,
name = "Nature's Swiftness",
icon = "Interface\\Icons\\Spell_Nature_RavenForm",
priority = 3,
targets = {TARGET_TYPES.SELF}, -- Self-buff for next spell
targetingDescription = "Use before emergency heal cast"
},
-- Core Maintenance (High Priority - keep these active)
EFFLORESCENCE = {
id = HealIQ.SpellData.EFFLORESCENCE,
name = "Efflorescence",
icon = "Interface\\Icons\\Ability_Druid_Efflorescence",
priority = 4, -- Higher priority per guide: "keep active as frequently as possible"
targets = {TARGET_TYPES.GROUND_TARGET}, -- Ground-targeted spell
targetingDescription = "Place where group will be standing"
},
LIFEBLOOM = {
id = HealIQ.SpellData.LIFEBLOOM,
name = "Lifebloom",
icon = "Interface\\Icons\\INV_Misc_Herb_Felblossom",
priority = 5, -- Higher priority per guide: "keep active on tank"
targets = {TARGET_TYPES.TANK, TARGET_TYPES.FOCUS, TARGET_TYPES.CURRENT_TARGET}, -- Tank maintenance
targetingDescription = "Keep active on main tank or focus target"
},
-- Proc-based spells (High Priority when available)
REGROWTH = {
id = HealIQ.SpellData.REGROWTH,
name = "Regrowth",
icon = "Interface\\Icons\\Spell_Nature_ResistNature",
priority = 6, -- Higher priority when used with Clearcasting
targets = {TARGET_TYPES.LOWEST_HEALTH, TARGET_TYPES.CURRENT_TARGET, TARGET_TYPES.TANK}, -- Direct heal
targetingDescription = "Target needs immediate healing"
},
-- AoE Healing Combo
SWIFTMEND = {
id = HealIQ.SpellData.SWIFTMEND,
name = "Swiftmend",
icon = "Interface\\Icons\\INV_Relics_IdolofRejuvenation",
priority = 7, -- Higher priority as setup for Wild Growth
targets = {TARGET_TYPES.CURRENT_TARGET, TARGET_TYPES.LOWEST_HEALTH}, -- Target with HoTs
targetingDescription = "Target must have Rejuvenation or Regrowth"
},
WILD_GROWTH = {
id = HealIQ.SpellData.WILD_GROWTH,
name = "Wild Growth",
icon = "Interface\\Icons\\Ability_Druid_WildGrowth",
priority = 8, -- Often paired with Swiftmend
targets = {TARGET_TYPES.PARTY_MEMBER, TARGET_TYPES.CURRENT_TARGET}, -- Smart heal around target
targetingDescription = "Target near damaged party members"
},
-- Cooldown Management
FLOURISH = {
id = HealIQ.SpellData.FLOURISH,
name = "Flourish",
icon = "Interface\\Icons\\Spell_Druid_WildGrowth",
priority = 10,
targets = {TARGET_TYPES.SELF}, -- Affects all your HoTs
targetingDescription = "Use when multiple HoTs are active"
},
-- Defensive/Utility
IRONBARK = {
id = HealIQ.SpellData.IRONBARK,
name = "Ironbark",
icon = "Interface\\Icons\\Spell_Druid_IronBark",
priority = 11,
targets = {TARGET_TYPES.TANK, TARGET_TYPES.CURRENT_TARGET, TARGET_TYPES.FOCUS}, -- Damage reduction
targetingDescription = "Prioritize tanks or targets taking heavy damage"
},
BARKSKIN = {
id = HealIQ.SpellData.BARKSKIN,
name = "Barkskin",
icon = "Interface\\Icons\\Spell_Nature_StoneSkinTotem",
priority = 12,
targets = {TARGET_TYPES.SELF}, -- Self-defensive
targetingDescription = "Use when taking damage"
},
-- Ramping HoTs (Lower priority during maintenance, higher during damage phases)
REJUVENATION = {
id = HealIQ.SpellData.REJUVENATION,
name = "Rejuvenation",
icon = "Interface\\Icons\\Spell_Nature_Rejuvenation",
priority = 13,
targets = {TARGET_TYPES.PARTY_MEMBER, TARGET_TYPES.CURRENT_TARGET, TARGET_TYPES.TANK}, -- Basic HoT
targetingDescription = "Apply to targets without HoT coverage"
},
-- Filler/Mana Management
WRATH = {
id = HealIQ.SpellData.WRATH,
name = "Wrath",
icon = "Interface\\Icons\\Spell_Nature_AbolishMagic",
priority = 14,
targets = {TARGET_TYPES.CURRENT_TARGET}, -- Enemy target
targetingDescription = "Use on enemies during downtime for mana restoration"
},
}
-- Current suggestion state
local currentSuggestion = nil
local currentQueue = {}
local lastUpdate = 0
local updateInterval = 0.1 -- Update every 100ms
function Engine:Initialize()
HealIQ:SafeCall(function()
self:StartUpdateLoop()
HealIQ:Print("Engine initialized")
end)
end
function Engine:StartUpdateLoop()
local frame = CreateFrame("Frame", "HealIQUpdateFrame")
frame:SetScript("OnUpdate", function(self, elapsed)
Engine:OnUpdate(elapsed)
end)
self.updateFrame = frame
end
function Engine:StopUpdateLoop()
if self.updateFrame then
self.updateFrame:SetScript("OnUpdate", nil)
self.updateFrame = nil
end
end
function Engine:OnUpdate(elapsed)
HealIQ:SafeCall(function()
local currentTime = GetTime()
-- Throttle updates
if currentTime - lastUpdate < updateInterval then
return
end
lastUpdate = currentTime
-- Only suggest spells if addon is enabled and database is initialized
local profileData = HealIQ:GetCurrentProfile()
if not profileData or not profileData.enabled then
self:SetSuggestion(nil)
self:SetQueue({})
return
end
-- Check if we should be suggesting anything
if not self:ShouldSuggest() then
self:SetSuggestion(nil)
self:SetQueue({})
return
end
-- Evaluate priority rules once; the top of the queue is the primary suggestion
local queue = self:EvaluateRulesQueue()
local suggestion = queue[1]
if suggestion then
HealIQ:LogSuggestionMade()
end
self:SetSuggestion(suggestion)
self:SetQueue(queue)
end)
end
function Engine:ShouldSuggest()
-- Check if auto-detect is enabled
local profileData = HealIQ:GetCurrentProfile()
if profileData and profileData.specialization ~= "auto" then
-- Manual specialization override
local manualSpec = profileData.specialization
if manualSpec ~= "restoration" then
return false -- Only suggest for restoration spec
end
else
-- Auto-detection mode
local _, class = UnitClass("player")
if class ~= "DRUID" then
return false
end
local specIndex = GetSpecialization()
if specIndex ~= 4 then -- Not Restoration
return false
end
end
-- Suggest in combat, when having a friendly target, or when in a group
-- This allows single-target spells to be suggested even without a target selected
-- for click-casting workflows, with targeting recommendations provided
local inCombat = InCombatLockdown()
local hasTarget = UnitExists("target")
local targetIsFriendly = hasTarget and UnitIsFriend("player", "target")
local inGroup = IsInGroup() or IsInRaid()
return inCombat or (hasTarget and targetIsFriendly) or inGroup
end
-- Update rules based on specialization
function Engine:UpdateRulesForSpecialization(spec)
local profileData = HealIQ:GetCurrentProfile()
if not profileData or not profileData.rules then
return
end
HealIQ:Print("Updating rules for specialization: " .. spec)
if spec == "restoration" then
-- Enable all healing rules for restoration
for ruleName in pairs(profileData.rules) do
profileData.rules[ruleName] = true
end
elseif spec == "guardian" then
-- For guardian, focus on defensive rules
for ruleName in pairs(profileData.rules) do
if ruleName:match("defensive") or ruleName:match("bark") or ruleName:match("iron") then
profileData.rules[ruleName] = true
else
profileData.rules[ruleName] = false
end
end
elseif spec == "feral" then
-- For feral, minimal healing suggestions
for ruleName in pairs(profileData.rules) do
if ruleName == "rejuvenation" or ruleName == "swiftmend" then
profileData.rules[ruleName] = true
else
profileData.rules[ruleName] = false
end
end
elseif spec == "balance" then
-- For balance, basic healing only
for ruleName in pairs(profileData.rules) do
if ruleName == "rejuvenation" or ruleName == "regrowth" then
profileData.rules[ruleName] = true
else
profileData.rules[ruleName] = false
end
end
end
end
-- Talent validation and detection system
function Engine:GetOptimalTalents()
-- Define optimal Restoration Druid talents for the healing strategy
-- These are key talents that support the implemented healing strategy
local optimalTalents = {
-- Class Talents (essential for the strategy)
{
name = "Wild Growth",
spellId = 48438,
description = "Essential AoE healing spell used in priority system",
category = "Core Healing",
required = true
},
{
name = "Efflorescence",
spellId = 145205,
description = "Ground AoE healing - high priority in strategy",
category = "Core Healing",
required = true
},
{
name = "Lifebloom",
spellId = 33763,
description = "Tank maintenance HoT with refresh timing logic",
category = "Core Healing",
required = true
},
{
name = "Swiftmend",
spellId = 18562,
description = "Instant heal used for Wild Growth combo setup",
category = "Core Healing",
required = true
},
{
name = "Nature's Swiftness",
spellId = 132158,
description = "Emergency instant cast enabler",
category = "Emergency",
required = true
},
-- Spec Talents (highly recommended for optimal performance)
{
name = "Flourish",
spellId = 197721,
description = "Extends multiple HoTs - part of priority system",
category = "HoT Management",
required = false
},
{
name = "Incarnation: Tree of Life",
spellId = 33891,
description = "Major healing cooldown in priority system",
category = "Major Cooldowns",
required = false
},
{
name = "Tranquility",
spellId = 740,
description = "Raid healing cooldown - highest priority spell",
category = "Major Cooldowns",
required = false
}
}
return optimalTalents
end
function Engine:CheckTalentAvailability(spellId)
-- Check if a talent/spell is known by the player
if not spellId then
return false
end
-- Use IsSpellKnown for passive talents and active abilities
local isKnown = IsSpellKnown(spellId)
if isKnown then
return true
end
-- For some talents, check if they're learned via C_Spell.GetSpellName
local spellName = C_Spell.GetSpellName(spellId)
if spellName then
return IsSpellKnown(spellId) or IsPlayerSpell(spellId)
end
return false
end
function Engine:GetTalentStatus()
local talentStatus = {
missing = {},
present = {},
categories = {}
}
local optimalTalents = self:GetOptimalTalents()
for _, talent in ipairs(optimalTalents) do
local isAvailable = self:CheckTalentAvailability(talent.spellId)
if isAvailable then
table.insert(talentStatus.present, talent)
else
table.insert(talentStatus.missing, talent)
end
-- Organize by category
if not talentStatus.categories[talent.category] then
talentStatus.categories[talent.category] = {missing = {}, present = {}}
end
if isAvailable then
table.insert(talentStatus.categories[talent.category].present, talent)
else
table.insert(talentStatus.categories[talent.category].missing, talent)
end
end
return talentStatus
end
function Engine:GetTalentRecommendations()
local talentStatus = self:GetTalentStatus()
local recommendations = {
critical = {},
suggested = {},
summary = ""
}
-- Separate critical missing talents from suggested ones
for _, talent in ipairs(talentStatus.missing) do
if talent.required then
table.insert(recommendations.critical, talent)
else
table.insert(recommendations.suggested, talent)
end
end
-- Generate summary text
local criticalCount = #recommendations.critical
local suggestedCount = #recommendations.suggested
if criticalCount > 0 then
recommendations.summary = string.format("Missing %d critical talents for optimal healing", criticalCount)
elseif suggestedCount > 0 then
recommendations.summary = string.format("Missing %d recommended talents for enhanced healing", suggestedCount)
else
recommendations.summary = "All optimal talents are available!"
end
return recommendations
end
-- Helper method for emergency/major cooldown evaluation
function Engine:EvaluateEmergencyCooldowns(suggestions, tracker, strategy)
-- Rule 1: Emergency/Major Cooldowns (Highest Priority)
-- Tranquility if off cooldown and enough allies recently damaged
if HealIQ.db.rules.tranquility and tracker:ShouldUseTranquility() then
table.insert(suggestions, SPELLS.TRANQUILITY)
HealIQ:DebugLog("Rule triggered: Tranquility")
HealIQ:LogRuleTrigger("Tranquility")
end
-- Incarnation: Tree of Life for high damage phases
if HealIQ.db.rules.incarnationTree and tracker:ShouldUseIncarnation() then
table.insert(suggestions, SPELLS.INCARNATION_TREE)
HealIQ:DebugLog("Rule triggered: Incarnation Tree")
HealIQ:LogRuleTrigger("Incarnation Tree")
end
-- Nature's Swiftness for emergency situations (low health targets)
if HealIQ.db.rules.naturesSwiftness and tracker:ShouldUseNaturesSwiftness() then
table.insert(suggestions, SPELLS.NATURES_SWIFTNESS)
HealIQ:DebugLog("Rule triggered: Nature's Swiftness")
HealIQ:LogRuleTrigger("Nature's Swiftness")
end
end
-- Helper method for core maintenance rules
function Engine:EvaluateCoreMaintenanceRules(suggestions, tracker, strategy)
-- Rule 2: Core Maintenance (High Priority - keep these active)
-- Efflorescence - "keep active as frequently as possible"
if HealIQ.db.rules.efflorescence and strategy.prioritizeEfflorescence and tracker:ShouldUseEfflorescence() then
table.insert(suggestions, SPELLS.EFFLORESCENCE)
HealIQ:DebugLog("Rule triggered: Efflorescence (prioritized)")
HealIQ:LogRuleTrigger("Efflorescence")
end
-- Lifebloom maintenance on tank - higher priority
if HealIQ.db.rules.lifebloom and strategy.maintainLifebloomOnTank then
local shouldSuggestLifebloom = false
local suggestReason = ""
if UnitExists("target") and UnitIsFriend("player", "target") then
local lifeboomInfo = tracker:GetTargetHotInfo("lifebloom")
local hasLifebloom = lifeboomInfo and lifeboomInfo.active
local refreshWindow = strategy.lifebloomRefreshWindow or 4.5
-- Check if target is a tank or important target
local isTank = UnitGroupRolesAssigned("target") == "TANK"
local isFocus = UnitIsUnit("target", "focus")
if isTank or isFocus then
-- Suggest if no Lifebloom or needs refresh
if not hasLifebloom then
shouldSuggestLifebloom = true
suggestReason = "missing on tank"
elseif hasLifebloom and lifeboomInfo.remaining < refreshWindow then
shouldSuggestLifebloom = true
suggestReason = "refresh for bloom"
end
end
elseif InCombatLockdown() or (IsInGroup() or IsInRaid()) then
-- Suggest Lifebloom even without target as a reminder for tank maintenance
shouldSuggestLifebloom = true
suggestReason = "tank maintenance needed"
end
if shouldSuggestLifebloom then
table.insert(suggestions, SPELLS.LIFEBLOOM)
HealIQ:DebugLog("Rule triggered: Lifebloom (" .. suggestReason .. ")")
HealIQ:LogRuleTrigger("Lifebloom")
end
end
end
-- Helper method for symbiotic tank relationship rules
function Engine:EvaluateSymbioticTankRules(suggestions, tracker, strategy)
-- Rule 2b: Symbiotic Tank Relationships - Suggest establishing beneficial relationships
if strategy.suggestTankRelationships ~= false then -- Default enabled, can be disabled
local inGroup = IsInGroup() or IsInRaid()
local inCombat = InCombatLockdown()
if (inGroup or inCombat) and not UnitExists("target") then
-- When no target is selected in group/combat, suggest tank relationship
table.insert(suggestions, {
spellId = SPELLS.LIFEBLOOM.spellId,
name = SPELLS.LIFEBLOOM.name,
icon = SPELLS.LIFEBLOOM.icon,
priority = 8,
targetType = "TANK_RELATIONSHIP",
reason = "No target selected - consider targeting tank for beneficial relationship"
})
HealIQ:DebugLog("Rule triggered: Symbiotic Tank Relationship (no target in group)")
HealIQ:LogRuleTrigger("SymbioticTankRelationship")
elseif inGroup and UnitExists("target") and not UnitIsFriend("player", "target") then
-- When targeting enemy in group, suggest switching to tank for support
table.insert(suggestions, {
spellId = SPELLS.LIFEBLOOM.spellId,
name = SPELLS.LIFEBLOOM.name,
icon = SPELLS.LIFEBLOOM.icon,
priority = 6,
targetType = "TANK_RELATIONSHIP",
reason = "Consider targeting friendly tank for beneficial relationship"
})
HealIQ:DebugLog("Rule triggered: Symbiotic Tank Relationship (enemy target)")
HealIQ:LogRuleTrigger("SymbioticTankRelationship")
end
end
end
-- Helper method for proc-based spell evaluation
function Engine:EvaluateProcBasedRules(suggestions, tracker, strategy)
-- Rule 3: Proc-based spells (High Priority when available)
-- Clearcasting active → Prioritize Regrowth
if HealIQ.db.rules.clearcasting and strategy.preferClearcastingRegrowth and tracker:HasClearcasting() then
table.insert(suggestions, SPELLS.REGROWTH)
HealIQ:DebugLog("Rule triggered: Regrowth (Clearcasting proc)")
HealIQ:LogRuleTrigger("Regrowth")
end
end
-- Helper method for AoE healing combo evaluation
function Engine:EvaluateAoEHealingRules(suggestions, tracker, strategy)
-- Rule 4: AoE Healing Combo (Swiftmend → Wild Growth)
-- Swiftmend for immediate healing (enhanced logic)
if HealIQ.db.rules.swiftmend and tracker:CanSwiftmend() then
local recentDamageCount = tracker:GetRecentDamageCount()
local wildGrowthReady = tracker:IsSpellReady("wildGrowth")
local minTargets = strategy.wildGrowthMinTargets or 1
-- Suggest Swiftmend if:
-- 1. Part of Wild Growth combo (when enabled), OR
-- 2. Target needs immediate healing, OR
-- 3. Recent damage to group, OR
-- 4. In combat/group without target as a reminder
local comboCondition = strategy.swiftmendWildGrowthCombo and wildGrowthReady and recentDamageCount >= minTargets
local healingCondition = UnitExists("target") and UnitIsFriend("player", "target")
local emergencyCondition = recentDamageCount >= 1
local reminderCondition = not UnitExists("target") and (InCombatLockdown() or (IsInGroup() or IsInRaid()))
if comboCondition or healingCondition or emergencyCondition or reminderCondition then
table.insert(suggestions, SPELLS.SWIFTMEND)
HealIQ:DebugLog("Rule triggered: Swiftmend (immediate healing)")
HealIQ:LogRuleTrigger("Swiftmend")
end
end
-- Wild Growth if off cooldown and targets need healing
if HealIQ.db.rules.wildGrowth and tracker:IsSpellReady("wildGrowth") then
local recentDamageCount = tracker:GetRecentDamageCount()
local minTargets = strategy.wildGrowthMinTargets or 1
if recentDamageCount >= minTargets then
table.insert(suggestions, SPELLS.WILD_GROWTH)
HealIQ:DebugLog("Rule triggered: Wild Growth (recent damage: " .. recentDamageCount .. ")")
HealIQ:LogRuleTrigger("Wild Growth")
end
end
end
-- Helper method for cooldown management evaluation
function Engine:EvaluateCooldownManagement(suggestions, tracker, strategy)
-- Rule 5: Cooldown Management
-- Flourish if available and multiple HoTs are expiring
if HealIQ.db.rules.flourish and tracker:ShouldUseFlourish() then
table.insert(suggestions, SPELLS.FLOURISH)
HealIQ:DebugLog("Rule triggered: Flourish")
HealIQ:LogRuleTrigger("Flourish")
end
end
-- Helper method for defensive/utility rules
function Engine:EvaluateDefensiveUtilityRules(suggestions, tracker, strategy)
-- Rule 6: Defensive/Utility
-- Ironbark for damage reduction on target
if HealIQ.db.rules.ironbark and tracker:ShouldUseIronbark() then
table.insert(suggestions, SPELLS.IRONBARK)
HealIQ:DebugLog("Rule triggered: Ironbark")
HealIQ:LogRuleTrigger("Ironbark")
end
-- Barkskin for self-defense
if HealIQ.db.rules.barkskin and tracker:ShouldUseBarkskin() then
table.insert(suggestions, SPELLS.BARKSKIN)
HealIQ:DebugLog("Rule triggered: Barkskin")
HealIQ:LogRuleTrigger("Barkskin")
end
end
-- Helper method for ramping HoT evaluation
function Engine:EvaluateRampingHotRules(suggestions, tracker, strategy)
-- Rule 7: Ramping HoTs (Context-dependent priority)
-- Rejuvenation logic - avoid random casts during downtime
local shouldSuggestRejuvenation = false
local rejuvReason = ""
if UnitExists("target") and UnitIsFriend("player", "target") then
local rejuvInfo = tracker:GetTargetHotInfo("rejuvenation")
local hasRejuv = rejuvInfo and rejuvInfo.active
if HealIQ.db.rules.rejuvenation and not hasRejuv then
local inCombat = InCombatLockdown()
local recentDamageCount = tracker:GetRecentDamageCount()
-- Only suggest Rejuvenation if in combat or damage is expected
if inCombat or recentDamageCount > 0 or not strategy.avoidRandomRejuvenationDowntime then
shouldSuggestRejuvenation = true
rejuvReason = "target missing"
end
end
elseif HealIQ.db.rules.rejuvenation then
local inCombat = InCombatLockdown()
local recentDamageCount = tracker:GetRecentDamageCount()
local inGroup = IsInGroup() or IsInRaid()
-- Suggest Rejuvenation without target as reminder when in combat or damage occurring
if (inCombat and inGroup) or recentDamageCount > 0 then
shouldSuggestRejuvenation = true
rejuvReason = "group needs HoT coverage"
end
end
if shouldSuggestRejuvenation then
table.insert(suggestions, SPELLS.REJUVENATION)
HealIQ:DebugLog("Rule triggered: Rejuvenation (" .. rejuvReason .. ")")
HealIQ:LogRuleTrigger("Rejuvenation")
end
end
-- Helper method for filler/mana management evaluation
function Engine:EvaluateFillerManaRules(suggestions, tracker, strategy)
-- Rule 8: Filler/Mana Management
-- Wrath for mana restoration during downtime
if HealIQ.db.rules.wrath and strategy.useWrathForMana and tracker:ShouldUseWrath() then
table.insert(suggestions, SPELLS.WRATH)
HealIQ:DebugLog("Rule triggered: Wrath (mana filler)")
HealIQ:LogRuleTrigger("Wrath")
end
end
-- Build the full ordered suggestion list from every rule category.
-- Single source of truth: both the primary suggestion and the queue derive
-- from this, so they can never drift out of sync.
function Engine:BuildSuggestions()
local tracker = HealIQ.Tracker
if not tracker then
return {}
end
if not HealIQ.db or not HealIQ.db.rules then
return {}
end
local suggestions = {}
local strategy = HealIQ.db.strategy or {}
HealIQ:DebugLog("Starting rule evaluation with enhanced strategy")
self:EvaluateEmergencyCooldowns(suggestions, tracker, strategy)
self:EvaluateCoreMaintenanceRules(suggestions, tracker, strategy)
self:EvaluateSymbioticTankRules(suggestions, tracker, strategy)
self:EvaluateProcBasedRules(suggestions, tracker, strategy)
self:EvaluateAoEHealingRules(suggestions, tracker, strategy)
self:EvaluateCooldownManagement(suggestions, tracker, strategy)
self:EvaluateDefensiveUtilityRules(suggestions, tracker, strategy)
self:EvaluateRampingHotRules(suggestions, tracker, strategy)
self:EvaluateFillerManaRules(suggestions, tracker, strategy)
HealIQ:DebugLog("Rule evaluation completed, " .. #suggestions .. " suggestions found")
return suggestions
end
-- Suggestion queue, capped to the configured queue size.
function Engine:EvaluateRulesQueue()
local suggestions = self:BuildSuggestions()
local queueSize = (HealIQ.db and HealIQ.db.ui and HealIQ.db.ui.queueSize) or 3
local queue = {}
for i = 1, math.min(queueSize, #suggestions) do
queue[i] = suggestions[i]
end
return queue
end
-- Targeting evaluation functions
function Engine:EvaluateTargetingSuggestion(spell)
if not spell or not spell.targets then
return nil
end
local bestTarget = nil
local targetingContext = {
hasTarget = UnitExists("target"),
targetIsFriendly = UnitExists("target") and UnitIsFriend("player", "target"),
hasFocus = UnitExists("focus"),
focusIsFriendly = UnitExists("focus") and UnitIsFriend("player", "focus"),
inParty = IsInGroup(),
inRaid = IsInRaid(),
inCombat = InCombatLockdown()
}
-- Evaluate each potential target type for this spell
for _, targetType in ipairs(spell.targets) do
local targetPriority = self:EvaluateTargetPriority(targetType, spell, targetingContext)
if targetPriority > 0 and (not bestTarget or targetPriority > bestTarget.priority) then
bestTarget = {
type = targetType,
priority = targetPriority,
available = true
}
end
end
return bestTarget
end
-- Target priority evaluation lookup table for better performance
local TARGET_PRIORITY_EVALUATORS = {
[TARGET_TYPES.SELF] = function(context)
return 100 -- Always available
end,
[TARGET_TYPES.CURRENT_TARGET] = function(context)
if context.targetIsFriendly then
return 90 -- High priority if we have a friendly target
else
return 0 -- Not available
end
end,
[TARGET_TYPES.FOCUS] = function(context)
if context.focusIsFriendly then
return 85 -- Good priority for focus target
else
return 0 -- Not available
end
end,
[TARGET_TYPES.TANK] = function(context)
-- Check if current target or focus is a tank
local targetIsTank = context.targetIsFriendly and UnitGroupRolesAssigned("target") == "TANK"
local focusIsTank = context.focusIsFriendly and UnitGroupRolesAssigned("focus") == "TANK"
if targetIsTank then
return 95 -- Very high priority for tank targeting spells
elseif focusIsTank then
return 90 -- Also high priority if focus is tank
elseif context.inParty or context.inRaid then
return 70 -- Medium priority, assume tank exists in group
else
return 0 -- No tank available
end
end,
[TARGET_TYPES.PARTY_MEMBER] = function(context)
if context.inParty or context.inRaid then
return 75 -- Good priority if in group
else
return 0 -- Not in party
end
end,
[TARGET_TYPES.LOWEST_HEALTH] = function(context)
-- We can't read health during combat due to WoW API limitations.
-- As a fallback, we prioritize the current target if it is friendly,
-- assuming it needs healing. If in a party or raid, we assign medium
-- priority, as manual targeting may be required. If neither condition
-- is met, we return 0, indicating no one is available to heal.
if context.targetIsFriendly then
return 80 -- Assume current target needs healing
elseif context.inParty or context.inRaid then
return 60 -- Medium priority, would need to target manually
else
return 0 -- No one to heal
end
end,
[TARGET_TYPES.TARGET_OF_TARGET] = function(context)
if context.hasTarget and UnitExists("targettarget") and UnitIsFriend("player", "targettarget") then
return 70 -- Available and useful for some situations
else
return 0 -- Not available
end
end,
[TARGET_TYPES.GROUND_TARGET] = function(context)
return 80 -- Always available for ground-targeted spells
end
}
function Engine:EvaluateTargetPriority(targetType, spell, context)
--[[
Evaluate the priority score for a given target type based on the spell and context.
Scoring System:
- Priority scores range from 0 to 100, where higher values indicate better target choices.
- A score of 0 means the target type is not available or applicable.
- Scores are assigned based on contextual factors such as whether the target is friendly,
whether the player is in a group, and the type of spell being cast.
Parameters:
- targetType: The type of target being evaluated (e.g., SELF, CURRENT_TARGET, FOCUS).
- spell: The spell being considered for casting, which includes its target types.
- context: A table containing contextual information (e.g., whether the player is in combat,
whether a target exists, and whether the target is friendly).
Returns:
- A numerical priority score (0-100) indicating the suitability of the target type.
]]
local evaluator = TARGET_PRIORITY_EVALUATORS[targetType]
if evaluator then
return evaluator(context)
end
return 0 -- Unknown target type
end
function Engine:GetTargetingSuggestionsText(suggestion)
if not suggestion then
return nil
end
local targetSuggestion = self:EvaluateTargetingSuggestion(suggestion)
if targetSuggestion and targetSuggestion.type then
return targetSuggestion.type.name
end
return nil
end
function Engine:GetTargetingSuggestionsIcon(suggestion)
if not suggestion then
return nil
end
local targetSuggestion = self:EvaluateTargetingSuggestion(suggestion)
if targetSuggestion and targetSuggestion.type then
return targetSuggestion.type.icon
end
return nil
end
function Engine:GetTargetingSuggestionsDescription(suggestion)
if not suggestion then
return nil
end
local targetSuggestion = self:EvaluateTargetingSuggestion(suggestion)
if targetSuggestion and targetSuggestion.type then
return targetSuggestion.type.description
end
return suggestion.targetingDescription or nil
end
function Engine:SetSuggestion(suggestion)
if suggestion ~= currentSuggestion then
currentSuggestion = suggestion
-- Notify UI of change
if HealIQ.UI then
HealIQ.UI:UpdateSuggestion(suggestion)
end
-- Debug output (only when debug mode is on)
if HealIQ.debug then
if suggestion then
local targetText = self:GetTargetingSuggestionsText(suggestion)
local suggestionText = suggestion.name
if targetText then
suggestionText = suggestionText .. " → " .. targetText
end
HealIQ:Print("Suggesting: " .. suggestionText)
HealIQ:DebugLog("Generated suggestion: " .. suggestion.name .. " (priority: " .. suggestion.priority .. ", target: " .. (targetText or "none") .. ")")
else
HealIQ:Print("No suggestion")
HealIQ:DebugLog("No suggestion generated")
end
end
-- Track suggestion stats
if suggestion and HealIQ.sessionStats then
HealIQ.sessionStats.suggestions = HealIQ.sessionStats.suggestions + 1
end
end
end
function Engine:SetQueue(queue)
-- Compare queue arrays for changes
local changed = false
if #queue ~= #currentQueue then
changed = true
else
for i, suggestion in ipairs(queue) do
if not currentQueue[i] or suggestion.id ~= currentQueue[i].id then
changed = true
break
end
end
end
if changed then
currentQueue = queue
-- Notify UI of queue change
if HealIQ.UI then