Implement missing ability effect handlers and gameplay rules

- GameState: add CardInstance fields — CanBeAttacked, CanBeBlocked,
  CanBeObstructed, CanUseAbility, CanBeSacrificed, ExtraAttacksRemaining,
  FixedSacrificeReturn, DisabledAbilities, IsRevealed
- GameState: add PendingDeferredEffect model + GameState.PendingDeferredEffects
- GameEngine.Attack: enforce CanBeAttacked; ExtraAttacksRemaining (extra
  attacks decrement rather than exhausting)
- GameEngine.Sacrifice: enforce CanBeSacrificed; use FixedSacrificeReturn
  override when set
- GameEngine.EndTurn: reset ExtraAttacksRemaining to 0 with other resets

AbilitySystem effect handlers (18 new):
  §5.1  GrantAdditionalAttackEffect
  §5.2  SetCanBeAttacked/Blocked/Obstructed/UseAbility/BeSacrificed
  §5.3  AddAbility/RemoveAbility/EnableAbility/DisableAbility
  §5.7  ReturnToBattlefield, SearchDeck, RevealCards, PlaceOnDeck
  §5.9  DisplaceUnit (absolute direction: N/S/E/W/NE/NW/SE/SW)
  §5.10 GrantMovementControl, SetFixedSacrificeReturn
  §5.12 ApplyOnEvent (deferred; fires once on trigger; cancelled on source death)

AbilitySystem additions:
- ActivateAbility: enforce CanUseAbility + DisabledAbilities
- FireCardEffects / ActivateAbility: requireClientTargets=true for
  mandatory explicit-target validation (gameplay-todo.md)
- ResolveTargets: empty candidates when clientTargets=null + mandatory
  selector, causing INSUFFICIENT_TARGETS for required but missing targets
- FireTrigger: drain PendingDeferredEffects that match the current event
- KillUnit: cancel PendingDeferredEffects whose source is dying
- ParseDirection, TileMatchesFilters helpers
- CreateTokenFieldCard: copy new CardInstance flag fields

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-02-26 21:28:41 -05:00
co-authored by Claude Happy
parent 7c89f4d0db
commit 92d2e34a68
3 changed files with 441 additions and 15 deletions
+70
View File
@@ -40,6 +40,12 @@ public sealed class GameState
/// Decremented / expired during EndTurn processing.
/// </summary>
public List<ActiveEffect> ActiveEffects { get; set; } = new();
/// <summary>
/// Deferred effects (from ApplyOnEventEffect) waiting to fire when their trigger occurs.
/// Consumed on firing; cancelled when source unit leaves the battlefield.
/// </summary>
public List<PendingDeferredEffect> PendingDeferredEffects { get; set; } = new();
}
public sealed class PlayerState
@@ -213,6 +219,48 @@ public class CardInstance
/// Null until at least one genus tag is added.
/// </summary>
public List<string>? Genus { get; set; }
// ── Unit restriction flags (set by ability effects) ───────────────────────
/// <summary>False when an effect prevents this unit from being targeted by attacks.</summary>
public bool CanBeAttacked { get; set; } = true;
/// <summary>False when an effect prevents this unit from being blocked in combat.</summary>
public bool CanBeBlocked { get; set; } = true;
/// <summary>False when an effect prevents this unit from being path-obstructed.</summary>
public bool CanBeObstructed { get; set; } = true;
/// <summary>False when an effect prevents this unit from using abilities.</summary>
public bool CanUseAbility { get; set; } = true;
/// <summary>False when this unit cannot be sacrificed.</summary>
public bool CanBeSacrificed { get; set; } = true;
// ── Extra attacks ─────────────────────────────────────────────────────────
/// <summary>
/// Additional attacks this unit may declare this turn before becoming exhausted.
/// Granted by GrantAdditionalAttackEffect. Decremented on each extra attack; reset at turn start.
/// </summary>
public int ExtraAttacksRemaining { get; set; }
// ── Sacrifice override ────────────────────────────────────────────────────
/// <summary>
/// When non-null and ≥ 0, overrides the normal ST sacrifice formula for this unit.
/// Null = use normal formula. -1 = sentinel "no override" for reversal tracking.
/// </summary>
public int? FixedSacrificeReturn { get; set; }
// ── Disabled abilities ────────────────────────────────────────────────────
/// <summary>
/// Ability names that are temporarily disabled on this unit.
/// Null until at least one ability is disabled.
/// </summary>
public List<string>? DisabledAbilities { get; set; }
// ── Reveal ────────────────────────────────────────────────────────────────
/// <summary>True if this card has been revealed to all players.</summary>
public bool IsRevealed { get; set; }
}
/// <summary>
@@ -228,6 +276,28 @@ public sealed class FieldCard : CardInstance
public int CurrentMp { get; set; }
}
/// <summary>
/// A deferred effect (from ApplyOnEventEffect) scheduled to fire once when its trigger event occurs.
/// Consumed after firing; cancelled if the source unit leaves the battlefield before the event fires.
/// </summary>
public sealed class PendingDeferredEffect
{
/// <summary>InstanceId of the unit that created this deferred effect.</summary>
public string SourceInstanceId { get; set; } = string.Empty;
/// <summary>AccountId of the player who owns the source unit.</summary>
public string OwnerAccountId { get; set; } = string.Empty;
/// <summary>Serialized TriggerEvent JSON — the event to watch for.</summary>
public string TriggerJson { get; set; } = "{}";
/// <summary>InstanceId (card) or AccountId (player) of the entity to apply effects to.</summary>
public string TargetRef { get; set; } = string.Empty;
/// <summary>Serialized Effect[] JSON — effects applied to TargetRef when the trigger fires.</summary>
public string EffectsJson { get; set; } = "[]";
}
/// <summary>
/// A duration-tracked effect currently applied to a unit or player.
/// Stored in GameState.ActiveEffects; decremented / expired during EndTurn.