Re-apply aura effects at turn start for units already in range
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 <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -5250,6 +5250,52 @@ public static class AbilitySystem
|
||||
return state;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Re-applies aura effects for units belonging to <paramref name="activePlayerId"/> 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.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fires OnLeaveAuraRange triggers for a unit about to leave the battlefield.
|
||||
/// Handles both existing auras and the leaving unit's own auras.
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user