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,