diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs index 586aaf6..48f25c3 100644 --- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs +++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs @@ -496,7 +496,14 @@ public static class AbilitySystem { int needed = selector.Count.N; if (!selector.Count.UpTo && candidates.Count < needed) + { + // In passive-to-new-target mode (restrictTargets set) there is no + // player-driven target selection; zero candidates simply means this + // passive does not apply to the new unit — skip silently. + if (restrictTargets is not null) + return []; throw new GameException("INSUFFICIENT_TARGETS"); + } candidates = candidates.Take(needed).ToList(); } @@ -1935,8 +1942,15 @@ public static class AbilitySystem var ctx = new AbilityContext { State = state, ActorId = ownerId, Source = source }; var fallback = new DurationModel { Type = DurationType.WhileSourceOnBattlefield }; foreach (var def in ParseAbilities(source.AbilitiesJson).Where(d => d.Type == AbilityType.Passive)) + { + // Honour ability-level activation conditions (e.g. IsOnTileWithAffinity). + if (def.ActivationConditions is { Length: > 0 } && + !def.ActivationConditions.All(c => EvaluateCondition(c, ctx, source))) + continue; + ExecuteActions(def.Actions, ctx, clientTargets: null, forceDuration: def.Duration ?? fallback); + } } /// @@ -1954,8 +1968,15 @@ public static class AbilitySystem { var ctx = new AbilityContext { State = state, ActorId = ownerId, Source = sourceUnit }; foreach (var def in ParseAbilities(sourceUnit.AbilitiesJson).Where(d => d.Type == AbilityType.Passive)) + { + // Respect activation conditions evaluated against the source unit. + if (def.ActivationConditions is { Length: > 0 } && + !def.ActivationConditions.All(c => EvaluateCondition(c, ctx, sourceUnit))) + continue; + ExecuteActions(def.Actions, ctx, clientTargets: null, restrictTargets: restrict, forceDuration: def.Duration ?? fallback); + } } } @@ -1987,6 +2008,31 @@ public static class AbilitySystem } } + /// + /// Revokes and reapplies every passive that carries , + /// keeping condition-gated buffs in sync with the current game state. + /// Call after any action that could change condition outcomes (unit movement, + /// tile affinity change, ability activation, etc.). + /// Units without conditional passives are skipped at zero cost. + /// + public static void ReEvaluateConditionalPassives(GameState state) + { + foreach (var (ownerId, player) in state.Players) + { + foreach (var unit in player.Field.OfType().ToList()) + { + bool hasConditional = ParseAbilities(unit.AbilitiesJson) + .Any(d => d.Type == AbilityType.Passive && d.ActivationConditions is { Length: > 0 }); + if (!hasConditional) continue; + + // Full revoke-then-reapply so stat modifiers stay correct regardless + // of which side of a condition boundary the unit currently sits on. + RevokePassivesForSource(state, unit.InstanceId); + ApplyPassivesForSource(state, unit.InstanceId, ownerId); + } + } + } + // ── Aura range evaluation ───────────────────────────────────────────────── /// diff --git a/Server/src/SOR.Game/GameEngine.cs b/Server/src/SOR.Game/GameEngine.cs index c84e122..dd1d3cd 100644 --- a/Server/src/SOR.Game/GameEngine.cs +++ b/Server/src/SOR.Game/GameEngine.cs @@ -324,6 +324,9 @@ public static class GameEngine ActorId = actorId, CardType = "Terramorpha", }); + + // Tile affinities changed — re-evaluate conditional passives for all units. + AbilitySystem.ReEvaluateConditionalPassives(state); } else if (card.CardType == "Ruin") { @@ -590,6 +593,9 @@ public static class GameEngine }); } + // A unit changed tiles — re-evaluate tile-affinity (and other) conditional passives. + AbilitySystem.ReEvaluateConditionalPassives(state); + return state; } @@ -869,6 +875,8 @@ public static class GameEngine Data = new TriggerEventData { SourceId = sourceInstanceId }, }); + AbilitySystem.ReEvaluateConditionalPassives(state); + return state; }