feat(ability): implement AbilityBuilderR3 + engine additions

Engine:
- AbilityDefinition: add SourceZoneGate (zone-restricted triggers) and TriggerLimitPerGame
- Effects: add StatModOperator (Add/Subtract/Multiply/Divide/Percent) on all stat mod effects; reversal stored as delta
- Action/CostEntry: add CostPickMode enum (Random/SelfPick/EnemySeePick/EnemyRandomPick/EnemyPick)
- PendingCostPick: new model for interactive cost pause/resume (mirrors PendingTriggeredTarget)
- GameState: PendingCostPick field
- GameMessages: CostPickRequestPush, GameCostPickRequest, GameCostPickResponse records
- AbilitySystem: FireTrigger scans Hand/Discard/Deck when SourceZoneGate set; per-game trigger limit tracking; ApplyStatOperator helper; PayCosts/ResumeCostPick for interactive cost flow
- GameCostPickHandler + ServiceRegistration wiring

Admin:
- AbilityBuilderR3.razor: full ability builder at /cards/ability-builder-r3 (39 triggers, 69 effects, 32 conditions, form/canvas/mermaid modes, compiles to engine-native $type JSON)
- AbilityBuilderR2-Draft.razor: fix switch expression no-best-type error

Docs:
- BuilderR3.md: master plan document

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:
dingo
2026-04-18 20:15:13 -04:00
co-authored by Claude Happy
parent 26fa4c810d
commit 8f3911e881
20 changed files with 5290 additions and 133 deletions
@@ -53,10 +53,24 @@ public sealed class AbilityDefinition
/// <summary>
/// Maximum number of times this Triggered ability may resolve per turn.
/// Null or <= 0 means unlimited.
/// Null or &lt;= 0 means unlimited.
/// </summary>
public int? TriggerLimitPerTurn { get; set; }
/// <summary>
/// Maximum number of times this Triggered ability may resolve for the entire game.
/// Null or &lt;= 0 means unlimited.
/// </summary>
public int? TriggerLimitPerGame { get; set; }
/// <summary>
/// Restricts which zones the source card must be in for the trigger to be active.
/// Valid values: "Battlefield", "Hand", "Discard", "Deck".
/// Null or empty means the trigger fires regardless of the source card's zone.
/// Default behaviour (null) retains the existing battlefield-only scan.
/// </summary>
public string[]? SourceZoneGate { get; set; }
/// <summary>
/// Optional display name shown in the admin tool and client ability list.
/// Not required for game logic.
+27 -3
View File
@@ -113,16 +113,40 @@ public enum CostType
DealDamageToOwnSpirit,
}
/// <summary>
/// How the player(s) resolve the selection for an interactive cost (e.g. DiscardFromHand).
/// Null / absent: server auto-resolves (picks first N valid candidates).
/// </summary>
public enum CostPickMode
{
/// <summary>Server picks randomly from valid candidates.</summary>
Random,
/// <summary>Controlling player sees and picks which cards to pay.</summary>
SelfPick,
/// <summary>Opponent picks on behalf of the controlling player (sees all options).</summary>
EnemySeePick,
/// <summary>Opponent picks randomly from the controlling player's valid candidates.</summary>
EnemyRandomPick,
/// <summary>Opponent has free choice of which cards the controlling player pays.</summary>
EnemyPick,
}
/// <summary>
/// A single cost element for an Active ability.
/// Multiple CostEntry items must all be paid simultaneously before the ability resolves.
/// </summary>
public sealed class CostEntry
{
public CostType Type { get; set; }
public int Amount { get; set; } = 1;
public CostType Type { get; set; }
public int Amount { get; set; } = 1;
/// <summary>Optional filter for targeted costs (e.g. "Discard a Spirit card from hand").</summary>
public Filter[]? Filters { get; set; }
public Filter[]? Filters { get; set; }
/// <summary>
/// When set, the cost resolution is interactive: a player (controlling or opponent)
/// is prompted to pick which specific cards/units satisfy the cost.
/// Null = auto-resolve (engine picks first N matching candidates).
/// </summary>
public CostPickMode? PickMode { get; set; }
}
// ── Ability range ─────────────────────────────────────────────────────────────
@@ -104,15 +104,24 @@ public abstract class Effect { }
public enum StatTarget { Current, Max }
public sealed class ModifyHealthEffect : Effect { public ValueExpr Amount { get; set; } = new(); public StatTarget StatTarget { get; set; } = StatTarget.Current; }
public sealed class ModifyDefenseEffect : Effect { public ValueExpr Amount { get; set; } = new(); public StatTarget StatTarget { get; set; } = StatTarget.Current; }
public sealed class ModifyDamageEffect : Effect { public ValueExpr Amount { get; set; } = new(); }
public sealed class ModifyMPEffect : Effect { public ValueExpr Amount { get; set; } = new(); public StatTarget StatTarget { get; set; } = StatTarget.Current; }
/// <summary>
/// How to apply the Amount to the current stat value.
/// "Add" (default) and "Subtract" use the Amount directly (positive integer recommended;
/// Subtract flips the sign before applying). "Multiply" and "Divide" treat Amount as
/// the multiplier/divisor integer (e.g. Multiply 2 = ×2). "Percent" treats Amount as
/// a percentage (e.g. Percent 50 adds 50% of the base value).
/// </summary>
public enum StatModOperator { Add, Subtract, Multiply, Divide, Percent }
public sealed class ModifyHealthEffect : Effect { public ValueExpr Amount { get; set; } = new(); public StatTarget StatTarget { get; set; } = StatTarget.Current; public StatModOperator Operator { get; set; } = StatModOperator.Add; }
public sealed class ModifyDefenseEffect : Effect { public ValueExpr Amount { get; set; } = new(); public StatTarget StatTarget { get; set; } = StatTarget.Current; public StatModOperator Operator { get; set; } = StatModOperator.Add; }
public sealed class ModifyDamageEffect : Effect { public ValueExpr Amount { get; set; } = new(); public StatModOperator Operator { get; set; } = StatModOperator.Add; }
public sealed class ModifyMPEffect : Effect { public ValueExpr Amount { get; set; } = new(); public StatTarget StatTarget { get; set; } = StatTarget.Current; public StatModOperator Operator { get; set; } = StatModOperator.Add; }
public sealed class SetMovementTypeEffect : Effect { public MovementType MovementType { get; set; } }
public sealed class SetAttackRangeEffect : Effect { public int Min { get; set; } public int Max { get; set; } }
public sealed class ModifyMinAttackRangeEffect : Effect { public ValueExpr Amount { get; set; } = new(); }
public sealed class ModifyMaxAttackRangeEffect : Effect { public ValueExpr Amount { get; set; } = new(); }
public sealed class ModifyMinAttackRangeEffect : Effect { public ValueExpr Amount { get; set; } = new(); public StatModOperator Operator { get; set; } = StatModOperator.Add; }
public sealed class ModifyMaxAttackRangeEffect : Effect { public ValueExpr Amount { get; set; } = new(); public StatModOperator Operator { get; set; } = StatModOperator.Add; }
public sealed class ModifyCostEffect : Effect { public int? Sp { get; set; } public int? St { get; set; } }
public sealed class SetAffinityEffect : Effect { public AffinityExpr Affinity { get; set; } = new(); }
public sealed class GrantAdditionalAttackEffect : Effect { public int N { get; set; } = 1; }
@@ -0,0 +1,53 @@
namespace SOR.Game.Abilities.Models;
/// <summary>
/// Stored in GameState when an Active ability's cost requires interactive player selection
/// (e.g. "Discard a card of your choice from hand").
///
/// The engine pauses cost payment, pushes a CostPickRequestPush to the picker player,
/// then resumes via GameCostPickHandler once the player submits their selection.
/// </summary>
public sealed class PendingCostPick
{
/// <summary>Correlation ID sent to the client so responses can be matched.</summary>
public string RequestId { get; set; } = Guid.NewGuid().ToString("N");
/// <summary>AccountId of the player who activated the ability.</summary>
public string ActorId { get; set; } = string.Empty;
/// <summary>InstanceId of the unit whose ability cost is being resolved.</summary>
public string SourceInstanceId { get; set; } = string.Empty;
/// <summary>0-based index of the ability in the source unit's AbilitiesJson array.</summary>
public int AbilityIndex { get; set; }
/// <summary>AccountId of the player who must pick (may differ from ActorId for EnemyPick modes).</summary>
public string PickerActorId { get; set; } = string.Empty;
/// <summary>The cost type being interactively resolved.</summary>
public string CostType { get; set; } = string.Empty;
/// <summary>Number of cards/units the picker must select.</summary>
public int Amount { get; set; } = 1;
/// <summary>The pick mode driving who selects and how.</summary>
public string PickMode { get; set; } = string.Empty;
/// <summary>JSON-serialized Filter[]? — constraints on what the picker may select.</summary>
public string? FiltersJson { get; set; }
/// <summary>
/// JSON-serialized CostEntry[] of costs that still need paying after this pick resolves.
/// Empty when this is the last interactive cost.
/// </summary>
public string RemainingCostsJson { get; set; } = "[]";
/// <summary>JSON-serialized Action[] — the full action list to execute after all costs are paid.</summary>
public string ActionsJson { get; set; } = "[]";
/// <summary>JSON-serialized AbilityRange? — passed through to ExecuteActions on resume.</summary>
public string? RangeJson { get; set; }
/// <summary>JSON-serialized DurationModel? — forceDuration passed to ExecuteActions on resume.</summary>
public string? ForceDurationJson { get; set; }
}