Skip to content

Commit 1b428af

Browse files
Xian55claude
andcommitted
Addon: [1.9.13] Fix FocusTarget bits stale on Vanilla/SoM - TargetFocusTargetGoal never runs
The event-driven BitCache introduced in PR #742 broke the Assist Focus workflow on Vanilla Classic / Season of Mastery. The GOAP planner would pick "Follow Focus" (cost 19) instead of "Target Focus Target" (cost 10) because TargetFocusTargetGoal.CanRun() always evaluated to false. Root cause: UNIT_FLAGS does not fire for derived/compound unit tokens like "focustarget" or "party1target". So focusTargetInCombat (bit 6) was only set when UpdateFocusCache() ran on UNIT_TARGET (target change). If the mob entered combat after being targeted, the combat flag stayed false forever until the focus changed target. Additionally, on Vanilla Classic the "focus" unit token doesn't exist - the addon maps it to "party1" via DataToColor.C.unitFocus. The OnUnitTarget_BitCache and OnUnitFlags_BitCache handlers only checked for the literal "focus" string, missing "party1" entirely. Finally, PLAYER_FOCUS_CHANGED may not exist on Vanilla Classic, and using RegisterEvent instead of SafeRegisterEvent could abort subsequent event registrations in the same block if it errors. Changes: BitCache.lua: - Poll focusTargetInCombat every frame in UpdatePolledValues() since UNIT_FLAGS never fires for derived unit tokens - this is 1 cheap UnitAffectingCombat() call per frame, only when focusTargetExists EventHandlers.lua: - Add DataToColor.C.unitFocus checks alongside literal "focus" in OnUnitTarget_BitCache and OnUnitFlags_BitCache so Vanilla "party1" token is handled correctly - Same for DataToColor.C.unitFocusTarget alongside "focustarget" - Use SafeRegisterEvent for PLAYER_FOCUS_CHANGED to prevent errors on Vanilla Classic from aborting subsequent event registrations - Register GROUP_ROSTER_UPDATE event with new OnGroupRosterUpdate_BitCache handler to refresh focus cache when party composition changes ClassConfiguration.cs: - On SoM/Vanilla, override TargetFocus.BindingID from TARGETFOCUS to TARGETPARTYMEMBER1 since Vanilla has no /targetfocus keybind Addon version bumped 1.9.12 -> 1.9.13 Fixes #788 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c5e77e5 commit 1b428af

6 files changed

Lines changed: 28 additions & 7 deletions

File tree

Addons/DataToColor/BitCache.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ local function UpdatePolledValues()
387387
bits3Cache.chatInputActive = DataToColor:IsChatInputActive() or false
388388
UpdateMailFrameCache()
389389

390+
-- Focus target combat state - UNIT_FLAGS doesn't fire for derived units
391+
-- like "focustarget" / "party1target", so we must poll
392+
if bits2Cache.focusTargetExists then
393+
bits2Cache.focusTargetInCombat = UnitAffectingCombat(DataToColor.C.unitFocusTarget) or false
394+
end
395+
390396
-- Spell states - must be polled because bot checks these immediately after
391397
-- sending key presses, faster than START/STOP_AUTOREPEAT_SPELL events fire
392398
UpdateSpellStateCache()

Addons/DataToColor/DataToColor.toc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Title: DataToColor
33
## Author: FreeHongKongMMO
44
## Notes: Displays data as colors (Legacy Cataclysm 4.3.0)
5-
## Version: 1.9.12
5+
## Version: 1.9.13
66
## RequiredDeps:
77
## OptionalDeps: Ace3, LibRangeCheck, cTimerBackport
88
## SavedVariables:

Addons/DataToColor/DataToColor_Classic.toc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Title: DataToColor
33
## Author: FreeHongKongMMO
44
## Notes: Displays data as colors (Classic)
5-
## Version: 1.9.12
5+
## Version: 1.9.13
66
## RequiredDeps:
77
## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino
88
## SavedVariables:

Addons/DataToColor/DataToColor_TBC.toc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## Title: DataToColor
33
## Author: FreeHongKongMMO
44
## Notes: Displays data as colors (Classic TBC)
5-
## Version: 1.9.12
5+
## Version: 1.9.13
66
## RequiredDeps:
77
## OptionalDeps: Ace3, LibRangeCheck, LibClassicCasterino
88
## SavedVariables:

Addons/DataToColor/EventHandlers.lua

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,10 @@ function DataToColor:RegisterEvents()
159159
---------------------------------------------------------------------------
160160
DataToColor:RegisterEvent('UNIT_TARGET', 'OnUnitTarget_BitCache')
161161
DataToColor:RegisterEvent('UPDATE_MOUSEOVER_UNIT', 'OnMouseoverChanged_BitCache')
162-
DataToColor:RegisterEvent('PLAYER_FOCUS_CHANGED', 'OnFocusChanged_BitCache')
162+
DataToColor:SafeRegisterEvent('PLAYER_FOCUS_CHANGED', 'OnFocusChanged_BitCache')
163163
DataToColor:RegisterEvent('PLAYER_REGEN_DISABLED', 'OnEnteredCombat')
164164
DataToColor:RegisterEvent('UNIT_FLAGS', 'OnUnitFlags_BitCache')
165+
DataToColor:RegisterEvent('GROUP_ROSTER_UPDATE', 'OnGroupRosterUpdate_BitCache')
165166
DataToColor:RegisterEvent('PLAYER_DEAD', 'OnPlayerDead_BitCache')
166167
DataToColor:RegisterEvent('PLAYER_ALIVE', 'OnPlayerAlive_BitCache')
167168
DataToColor:RegisterEvent('PLAYER_UNGHOST', 'OnPlayerUnghost_BitCache')
@@ -937,7 +938,7 @@ function DataToColor:OnUnitTarget_BitCache(event, unit)
937938
if DataToColor.BitCache and DataToColor.BitCache.updateTargetTarget then
938939
if unit == "target" then
939940
DataToColor.BitCache.updateTargetTarget()
940-
elseif unit == "focus" then
941+
elseif unit == "focus" or unit == DataToColor.C.unitFocus then
941942
DataToColor.BitCache.updateFocus()
942943
elseif unit == "pet" then
943944
DataToColor.BitCache.updatePet()
@@ -974,13 +975,19 @@ function DataToColor:OnUnitFlags_BitCache(event, unit)
974975
if not DataToColor.BitCache or not DataToColor.BitCache.bits1 then return end
975976
if unit == "target" then
976977
DataToColor.BitCache.bits1.targetInCombat = UnitAffectingCombat(unit) or false
977-
elseif unit == "focus" then
978+
elseif unit == "focus" or unit == DataToColor.C.unitFocus then
978979
DataToColor.BitCache.bits2.focusInCombat = UnitAffectingCombat(unit) or false
979-
elseif unit == "focustarget" then
980+
elseif unit == "focustarget" or unit == DataToColor.C.unitFocusTarget then
980981
DataToColor.BitCache.bits2.focusTargetInCombat = UnitAffectingCombat(unit) or false
981982
end
982983
end
983984

985+
function DataToColor:OnGroupRosterUpdate_BitCache(event)
986+
if DataToColor.BitCache and DataToColor.BitCache.updateFocus then
987+
DataToColor.BitCache.updateFocus()
988+
end
989+
end
990+
984991
function DataToColor:OnPlayerDead_BitCache(event)
985992
if DataToColor.BitCache and DataToColor.BitCache.bits1 then
986993
DataToColor.BitCache.bits1.playerIsDeadOrGhost = true

Core/ClassConfig/ClassConfiguration.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
using Newtonsoft.Json;
55

6+
using SharedLib;
7+
68
using System;
79
using System.Collections.Frozen;
810
using System.Collections.Generic;
@@ -213,6 +215,12 @@ public void Initialise(IServiceProvider sp, Dictionary<int, string> overridePath
213215

214216
RequirementFactory factory = new(sp, this);
215217

218+
// Vanilla has no TARGETFOCUS binding — use TARGETPARTYMEMBER1 instead
219+
if (playerReader.Version == ClientVersion.SoM)
220+
{
221+
TargetFocus.BindingID = BindingID.TARGETPARTYMEMBER1;
222+
}
223+
216224
var baseActionKeys = GetByType<KeyAction>();
217225
foreach ((string _, KeyAction keyAction) in baseActionKeys)
218226
{

0 commit comments

Comments
 (0)