From f7fc4fbdd3af8a4d3064e27fdf9707e756fa726a Mon Sep 17 00:00:00 2001 From: dingo Date: Thu, 7 May 2026 14:58:00 -0400 Subject: [PATCH] Re-apply aura effects at turn start for units already in range MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ModifyMP(Current) and similar per-turn aura bonuses were only applied once when a unit entered the aura range. The CurrentMp reset at turn start wiped the bonus without re-applying it. Added ReapplyAurasAtTurnStart which strips stale tracked effects (without reversal — the stat reset already undid them) and re-applies ApplyAuraEffects for active-player units still in range. Called in NextTurn after the Mp/Defense restore and ExpireActiveEffects. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../src/SOR.Game/Abilities/AbilitySystem.cs | 46 +++++++++++++++++++ Server/src/SOR.Game/GameEngine.cs | 4 ++ 2 files changed, 50 insertions(+) diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs index 6ca6f0a..b327a14 100644 --- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs +++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs @@ -5250,6 +5250,52 @@ public static class AbilitySystem return state; } + /// + /// Re-applies aura effects for units belonging to that are + /// already inside an aura's range at the start of their turn. + /// Called after the turn-start stat reset (CurrentMp/CurrentDefense restore) so that + /// per-turn bonuses like ModifyMP(Current) are re-granted on top of the fresh base values. + /// Stale tracked effects for each source→target pair are removed WITHOUT reversal because + /// the underlying Current stats were already reset by the turn transition. + /// + public static GameState ReapplyAurasAtTurnStart(GameState state, string activePlayerId) + { + if (state.Board is null) return state; + + var activePlayerUnits = BoardUnits(state.Players[activePlayerId]).ToList(); + if (activePlayerUnits.Count == 0) return state; + + foreach (var (auraOwnerId, auraPlayer) in state.Players) + foreach (var auraUnit in BoardUnits(auraPlayer).ToList()) + { + foreach (var def in ParseAbilities(auraUnit.AbilitiesJson) + .Where(d => d.Type == AbilityType.Aura && d.AuraRange is not null)) + { + int min = def.AuraRange!.Min, max = def.AuraRange.Max; + var auraPos = auraUnit.Position!.Value; + + foreach (var target in activePlayerUnits + .Where(t => t.InstanceId != auraUnit.InstanceId)) + { + int dist = auraPos.ManhattanDistance(target.Position!.Value); + if (dist < min || dist > max) continue; + + // Strip stale tracked effects for this source→target pair without reversal. + // Current stats (CurrentMp, CurrentDefense) were already reset by the + // turn transition, so applying the reversal would incorrectly subtract. + state.ActiveEffects.RemoveAll(ae => + ae.SourceInstanceId == auraUnit.InstanceId && + ae.TargetRef == target.InstanceId); + + // Re-apply fresh — same path as when the unit entered the aura. + ApplyAuraEffects(state, auraOwnerId, auraUnit, def, target.InstanceId); + } + } + } + + return state; + } + /// /// Fires OnLeaveAuraRange triggers for a unit about to leave the battlefield. /// Handles both existing auras and the leaving unit's own auras. diff --git a/Server/src/SOR.Game/GameEngine.cs b/Server/src/SOR.Game/GameEngine.cs index d687a15..c789d03 100644 --- a/Server/src/SOR.Game/GameEngine.cs +++ b/Server/src/SOR.Game/GameEngine.cs @@ -1057,6 +1057,10 @@ public static class GameEngine // Expire UntilStartOfOwnerTurn effects now that the new active player is set. AbilitySystem.ExpireActiveEffects(state, state.ActivePlayerAccountId, isEndOfTurn: false); + // Re-apply aura bonuses to units already in range (e.g. ModifyMP Current) so they + // take effect on top of the freshly-reset CurrentMp/CurrentDefense values. + AbilitySystem.ReapplyAurasAtTurnStart(state, state.ActivePlayerAccountId); + AbilitySystem.FireTrigger(state, new TriggerOccurrence { Kind = TriggerEventKind.TurnStart,