Standardize active ability execution between unit and card paths
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Scans every battlefield unit for Triggered abilities matching the occurrence
|
||||
/// and fires each matching one. Called inline from GameEngine mutation methods.
|
||||
|
||||
Reference in New Issue
Block a user