From e415a7660fbc663dfd95e2a6268e66b82fcfebff Mon Sep 17 00:00:00 2001 From: GaboGG Date: Mon, 20 Jul 2026 20:00:19 -0400 Subject: [PATCH] Fix spirit stance flip-flop: 3-turn cooldown on toggle Spirit stance was toggling on/off every turn because conditions (OC >= 60, SP > 10%) would be met immediately after toggling off. Added a 3-turn cooldown via STATE._spiritCooldown that blocks re-toggling until it expires. Prevents wasted turns on spirit stance spam. --- scripts/hv-unified.user.js | 11 ++++++++--- scripts/latest.user.js | 11 ++++++++--- src/strategy-engine.js | 11 ++++++++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/scripts/hv-unified.user.js b/scripts/hv-unified.user.js index 5ea7f06..c50bc6e 100644 --- a/scripts/hv-unified.user.js +++ b/scripts/hv-unified.user.js @@ -1006,11 +1006,16 @@ function strategyAdept() { } } - // 6. Spirit Stance at OC 60 — but only if we have SP to sustain it - if (STATE.oc >= 60 && !STATE.spiritStance && STATE.sp > 0.10) + // 6. Spirit Stance at OC 60 — with cooldown to prevent flip-flopping + if (STATE.oc >= 60 && !STATE.spiritStance && STATE.sp > 0.10 && !STATE._spiritCooldown) { + STATE._spiritCooldown = 3; return { type: 'toggle_spirit' }; - if (STATE.sp < 0.03 && STATE.spiritStance) + } + if (STATE.sp < 0.03 && STATE.spiritStance && !STATE._spiritCooldown) { + STATE._spiritCooldown = 3; return { type: 'toggle_spirit' }; + } + if (STATE._spiritCooldown > 0) STATE._spiritCooldown--; // 7. Damage spells const dmg = CFG.useAttackSpells ? getBestDamageSpell() : null; diff --git a/scripts/latest.user.js b/scripts/latest.user.js index 5ea7f06..c50bc6e 100644 --- a/scripts/latest.user.js +++ b/scripts/latest.user.js @@ -1006,11 +1006,16 @@ function strategyAdept() { } } - // 6. Spirit Stance at OC 60 — but only if we have SP to sustain it - if (STATE.oc >= 60 && !STATE.spiritStance && STATE.sp > 0.10) + // 6. Spirit Stance at OC 60 — with cooldown to prevent flip-flopping + if (STATE.oc >= 60 && !STATE.spiritStance && STATE.sp > 0.10 && !STATE._spiritCooldown) { + STATE._spiritCooldown = 3; return { type: 'toggle_spirit' }; - if (STATE.sp < 0.03 && STATE.spiritStance) + } + if (STATE.sp < 0.03 && STATE.spiritStance && !STATE._spiritCooldown) { + STATE._spiritCooldown = 3; return { type: 'toggle_spirit' }; + } + if (STATE._spiritCooldown > 0) STATE._spiritCooldown--; // 7. Damage spells const dmg = CFG.useAttackSpells ? getBestDamageSpell() : null; diff --git a/src/strategy-engine.js b/src/strategy-engine.js index a313487..d879721 100644 --- a/src/strategy-engine.js +++ b/src/strategy-engine.js @@ -363,11 +363,16 @@ function strategyAdept() { } } - // 6. Spirit Stance at OC 60 — but only if we have SP to sustain it - if (STATE.oc >= 60 && !STATE.spiritStance && STATE.sp > 0.10) + // 6. Spirit Stance at OC 60 — with cooldown to prevent flip-flopping + if (STATE.oc >= 60 && !STATE.spiritStance && STATE.sp > 0.10 && !STATE._spiritCooldown) { + STATE._spiritCooldown = 3; return { type: 'toggle_spirit' }; - if (STATE.sp < 0.03 && STATE.spiritStance) + } + if (STATE.sp < 0.03 && STATE.spiritStance && !STATE._spiritCooldown) { + STATE._spiritCooldown = 3; return { type: 'toggle_spirit' }; + } + if (STATE._spiritCooldown > 0) STATE._spiritCooldown--; // 7. Damage spells const dmg = CFG.useAttackSpells ? getBestDamageSpell() : null;