From 7d572ae55c71934b4f2315b85d3ed7c7ca1e5eea Mon Sep 17 00:00:00 2001 From: Shard Date: Thu, 19 Mar 2026 23:53:05 +0000 Subject: [PATCH] Standardize active ability execution between unit and card paths --- .../src/SOR.Game/Abilities/AbilitySystem.cs | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/Server/src/SOR.Game/Abilities/AbilitySystem.cs b/Server/src/SOR.Game/Abilities/AbilitySystem.cs index 1f45fbb..9883603 100644 --- a/Server/src/SOR.Game/Abilities/AbilitySystem.cs +++ b/Server/src/SOR.Game/Abilities/AbilitySystem.cs @@ -90,13 +90,9 @@ public static class AbilitySystem var ctx = new AbilityContext { State = state, ActorId = actorId, Source = source }; - // Evaluate source-side ActivationConditions only (Subject != "Target"). - // Target-subject conditions restrict which targets are valid; they are - // enforced by the client and applied per-target inside ExecuteActions. - if (def.ActivationConditions is { Length: > 0 }) - foreach (var cond in def.ActivationConditions.Where(c => c.Subject != "Target")) - if (!EvaluateCondition(cond, ctx, source)) - throw new GameException("ABILITY_CONDITION_NOT_MET"); + // Source-side activation conditions are shared with card-active execution. + if (!ValidateSourceActivationConditions(def, ctx, source)) + throw new GameException("ABILITY_CONDITION_NOT_MET"); if (def.Cost is { Length: > 0 }) PayCost(def.Cost, ctx); @@ -150,22 +146,32 @@ public static class AbilitySystem foreach (var def in activeDefs) { var ctx = new AbilityContext { State = state, ActorId = actorId, Source = card }; - // Evaluate source-side ActivationConditions only (Subject != "Target"). - // Target-side conditions are enforced by the client; the resolved targets - // provided by the client are filtered per-target inside ExecuteActions. - if (def.ActivationConditions is { Length: > 0 }) - { - bool sourceFailed = def.ActivationConditions - .Where(c => c.Subject != "Target") - .Any(c => !EvaluateCondition(c, ctx, card)); - if (sourceFailed) continue; - } - ExecuteActions(def.Actions, ctx, clientTargets, requireClientTargets: true); + // Keep condition and duration behavior aligned with ActivateAbility. + if (!ValidateSourceActivationConditions(def, ctx, card)) + continue; + + ExecuteActions(def.Actions, ctx, clientTargets, requireClientTargets: true, + activationRange: def.Range, forceDuration: def.Duration); } return state; } + private static bool ValidateSourceActivationConditions( + AbilityDefinition def, + AbilityContext ctx, + object sourceSubject) + { + if (def.ActivationConditions is not { Length: > 0 }) + return true; + + foreach (var cond in def.ActivationConditions.Where(c => c.Subject != "Target")) + if (!EvaluateCondition(cond, ctx, sourceSubject)) + return false; + + return true; + } + /// /// Scans every battlefield unit for Triggered abilities matching the occurrence /// and fires each matching one. Called inline from GameEngine mutation methods.