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 };
|
var ctx = new AbilityContext { State = state, ActorId = actorId, Source = source };
|
||||||
|
|
||||||
// Evaluate source-side ActivationConditions only (Subject != "Target").
|
// Source-side activation conditions are shared with card-active execution.
|
||||||
// Target-subject conditions restrict which targets are valid; they are
|
if (!ValidateSourceActivationConditions(def, ctx, source))
|
||||||
// enforced by the client and applied per-target inside ExecuteActions.
|
throw new GameException("ABILITY_CONDITION_NOT_MET");
|
||||||
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");
|
|
||||||
|
|
||||||
if (def.Cost is { Length: > 0 })
|
if (def.Cost is { Length: > 0 })
|
||||||
PayCost(def.Cost, ctx);
|
PayCost(def.Cost, ctx);
|
||||||
@@ -150,22 +146,32 @@ public static class AbilitySystem
|
|||||||
foreach (var def in activeDefs)
|
foreach (var def in activeDefs)
|
||||||
{
|
{
|
||||||
var ctx = new AbilityContext { State = state, ActorId = actorId, Source = card };
|
var ctx = new AbilityContext { State = state, ActorId = actorId, Source = card };
|
||||||
// Evaluate source-side ActivationConditions only (Subject != "Target").
|
// Keep condition and duration behavior aligned with ActivateAbility.
|
||||||
// Target-side conditions are enforced by the client; the resolved targets
|
if (!ValidateSourceActivationConditions(def, ctx, card))
|
||||||
// provided by the client are filtered per-target inside ExecuteActions.
|
continue;
|
||||||
if (def.ActivationConditions is { Length: > 0 })
|
|
||||||
{
|
ExecuteActions(def.Actions, ctx, clientTargets, requireClientTargets: true,
|
||||||
bool sourceFailed = def.ActivationConditions
|
activationRange: def.Range, forceDuration: def.Duration);
|
||||||
.Where(c => c.Subject != "Target")
|
|
||||||
.Any(c => !EvaluateCondition(c, ctx, card));
|
|
||||||
if (sourceFailed) continue;
|
|
||||||
}
|
|
||||||
ExecuteActions(def.Actions, ctx, clientTargets, requireClientTargets: true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
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>
|
/// <summary>
|
||||||
/// Scans every battlefield unit for Triggered abilities matching the occurrence
|
/// Scans every battlefield unit for Triggered abilities matching the occurrence
|
||||||
/// and fires each matching one. Called inline from GameEngine mutation methods.
|
/// and fires each matching one. Called inline from GameEngine mutation methods.
|
||||||
|
|||||||
Reference in New Issue
Block a user