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:
@@ -613,6 +613,8 @@ public static class GameEngine
|
||||
if (attacker.IsExhausted) throw new GameException("CARD_EXHAUSTED");
|
||||
if (!attacker.CanAttack) throw new GameException("CARD_CANNOT_ATTACK");
|
||||
|
||||
if (!target.CanBeAttacked) throw new GameException("TARGET_CANNOT_BE_ATTACKED");
|
||||
|
||||
// Range + LOS validation when board is active.
|
||||
if (state.Board is not null && attacker.Position.HasValue && target.Position.HasValue)
|
||||
{
|
||||
@@ -634,7 +636,11 @@ public static class GameEngine
|
||||
if (target.CurrentHealth > 0 && target.CanAttack && !target.IsExhausted)
|
||||
ApplyDamage(attacker, target.Damage ?? 0);
|
||||
|
||||
attacker.IsExhausted = true;
|
||||
// Consume extra attack or exhaust normally.
|
||||
if (attacker.ExtraAttacksRemaining > 0)
|
||||
attacker.ExtraAttacksRemaining--;
|
||||
else
|
||||
attacker.IsExhausted = true;
|
||||
|
||||
bool gameOver = false;
|
||||
var activePlayer = state.Players[actorId];
|
||||
@@ -706,7 +712,8 @@ public static class GameEngine
|
||||
.FirstOrDefault(c => c.InstanceId == unitInstanceId)
|
||||
?? throw new GameException("UNIT_NOT_ON_FIELD");
|
||||
|
||||
if (unit.IsLeader) throw new GameException("CANNOT_SACRIFICE_ARCH_SPIRIT");
|
||||
if (unit.IsLeader) throw new GameException("CANNOT_SACRIFICE_ARCH_SPIRIT");
|
||||
if (!unit.CanBeSacrificed) throw new GameException("UNIT_CANNOT_BE_SACRIFICED");
|
||||
|
||||
var archSpirit = player.ArchSpirit ?? throw new GameException("NO_ARCH_SPIRIT");
|
||||
if (archSpirit.Position is null) throw new GameException("ARCH_SPIRIT_NOT_PLACED");
|
||||
@@ -715,8 +722,14 @@ public static class GameEngine
|
||||
if (!unit.Position.Value.IsOrthogonallyAdjacentTo(archSpirit.Position.Value))
|
||||
throw new GameException("UNIT_NOT_ADJACENT_TO_ARCH_SPIRIT");
|
||||
|
||||
var sacValue = SacrificeSystem.GetSacrificeValue(unit.StCost, unit.SpCost);
|
||||
var stReturn = SacrificeSystem.GetSTReturn(player.CurrentSt, sacValue);
|
||||
int stReturn;
|
||||
if (unit.FixedSacrificeReturn.HasValue && unit.FixedSacrificeReturn.Value >= 0)
|
||||
stReturn = unit.FixedSacrificeReturn.Value;
|
||||
else
|
||||
{
|
||||
var sacValue = SacrificeSystem.GetSacrificeValue(unit.StCost, unit.SpCost);
|
||||
stReturn = SacrificeSystem.GetSTReturn(player.CurrentSt, sacValue);
|
||||
}
|
||||
player.CurrentSt += stReturn;
|
||||
|
||||
AbilitySystem.EvaluateAurasOnLeave(state, unitInstanceId);
|
||||
@@ -756,13 +769,15 @@ public static class GameEngine
|
||||
var active = state.Players[actorId];
|
||||
foreach (var card in active.Field.OfType<FieldCard>())
|
||||
{
|
||||
card.IsExhausted = false;
|
||||
card.AbilityUsesThisTurn = null;
|
||||
card.IsExhausted = false;
|
||||
card.AbilityUsesThisTurn = null;
|
||||
card.ExtraAttacksRemaining = 0;
|
||||
}
|
||||
if (active.ArchSpirit is not null)
|
||||
{
|
||||
active.ArchSpirit.IsExhausted = false;
|
||||
active.ArchSpirit.AbilityUsesThisTurn = null;
|
||||
active.ArchSpirit.IsExhausted = false;
|
||||
active.ArchSpirit.AbilityUsesThisTurn = null;
|
||||
active.ArchSpirit.ExtraAttacksRemaining = 0;
|
||||
}
|
||||
|
||||
AbilitySystem.FireTrigger(state, new TriggerOccurrence
|
||||
|
||||
Reference in New Issue
Block a user