Fix ability lock-out guards, implement SummonTokenEffect, thread card targets
- GameEngine.Transition: enforce CanTransitionArchSpirit flag - GameEngine.ChannelCard: enforce CanChannelSpirit, CanChannelRepentance, CanChannelInstinct, CanChannelRuin, CanChannelTerramorphaMono/Di/Tri - GameEngine.ChannelCard: accept IReadOnlyList<AbilityTarget>? cardTargets; thread through FireCardEffects for Repentance/Instinct effects - AbilitySystem.FireCardEffects: accept and forward clientTargets to ExecuteActions - AbilitySystem.ExecuteEffect: implement SummonTokenEffect — deserialize TokenDefJson, create SpiritToken FieldCard, place on board, fire UnitEnterBattlefield + aura enter - GamePlayCardRequest: add IReadOnlyList<AbilityTarget>? Targets for unit/tile inputs - GamePlayCardHandler: pass req.Targets to ChannelCard 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:
@@ -94,12 +94,13 @@ public static class AbilitySystem
|
||||
/// Resolve the EffectsJson action list on a non-unit card (Repentance, Instinct, Ruin)
|
||||
/// immediately when it is channeled. The card itself is the source in the context.
|
||||
/// </summary>
|
||||
public static GameState FireCardEffects(GameState state, string actorId, CardInstance card)
|
||||
public static GameState FireCardEffects(GameState state, string actorId, CardInstance card,
|
||||
IReadOnlyList<AbilityTarget>? clientTargets = null)
|
||||
{
|
||||
var actions = ParseEffects(card.EffectsJson);
|
||||
if (actions.Length == 0) return state;
|
||||
var ctx = new AbilityContext { State = state, ActorId = actorId, Source = card };
|
||||
ExecuteActions(actions, ctx, clientTargets: null);
|
||||
ExecuteActions(actions, ctx, clientTargets);
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -741,11 +742,67 @@ public static class AbilitySystem
|
||||
break;
|
||||
}
|
||||
|
||||
// ── §5.11 Token summoning ─────────────────────────────────────────
|
||||
case SummonTokenEffect ste when target is Coord coord:
|
||||
{
|
||||
var board = ctx.State.Board;
|
||||
if (board is null) break;
|
||||
var tile = board.GetTile(coord);
|
||||
if (tile is null || !tile.IsEmpty) break;
|
||||
|
||||
// TokenDefJson is deserialized directly as CardInstance field values.
|
||||
var proto = JsonSerializer.Deserialize<CardInstance>(ste.TokenDefJson, _jsonOpts);
|
||||
if (proto is null) break;
|
||||
|
||||
proto.InstanceId = Guid.NewGuid().ToString("N")[..8];
|
||||
proto.CardType = "SpiritToken";
|
||||
|
||||
var tokenField = CreateTokenFieldCard(proto, coord);
|
||||
ctx.State.Players[ctx.ActorId].Field.Add(tokenField);
|
||||
board.PlaceUnit(coord, tokenField.InstanceId, ctx.ActorId);
|
||||
|
||||
FireTrigger(ctx.State, new TriggerOccurrence
|
||||
{
|
||||
Kind = TriggerEventKind.UnitEnterBattlefield,
|
||||
ActorId = ctx.ActorId,
|
||||
UnitType = "SpiritToken",
|
||||
Data = new TriggerEventData { SourceId = tokenField.InstanceId },
|
||||
});
|
||||
EvaluateAurasOnEnter(ctx.State, tokenField.InstanceId);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static FieldCard CreateTokenFieldCard(CardInstance proto, Coord position)
|
||||
=> new()
|
||||
{
|
||||
InstanceId = proto.InstanceId,
|
||||
Name = proto.Name,
|
||||
CardType = "SpiritToken",
|
||||
Affinity = proto.Affinity,
|
||||
MaxHealth = proto.MaxHealth,
|
||||
CurrentHealth = proto.MaxHealth,
|
||||
MaxDefense = proto.MaxDefense,
|
||||
CurrentDefense = proto.MaxDefense,
|
||||
Damage = proto.Damage,
|
||||
CanAttack = proto.CanAttack,
|
||||
CanDefend = proto.CanDefend,
|
||||
CanMove = proto.CanMove,
|
||||
MovementType = proto.MovementType,
|
||||
MaxMp = proto.MaxMp,
|
||||
CurrentMp = proto.MaxMp ?? 0,
|
||||
MinAttackRange = proto.MinAttackRange,
|
||||
MaxAttackRange = proto.MaxAttackRange,
|
||||
RequiresLos = proto.RequiresLos,
|
||||
AbilitiesJson = proto.AbilitiesJson,
|
||||
IsExhausted = false,
|
||||
Position = position,
|
||||
};
|
||||
|
||||
// ── Damage helper ─────────────────────────────────────────────────────────
|
||||
|
||||
private static void ApplyDamageToUnit(
|
||||
|
||||
@@ -183,11 +183,11 @@ public static class GameEngine
|
||||
/// Ruin: placed on a random tile matching the card's affinity (ignores occupancy).
|
||||
/// Abilities fire at TurnStart if a Spirit/ArchSpirit occupies the tile.
|
||||
///
|
||||
/// Repentance / Instinct: targetTiles may be null. The card goes to Discard after
|
||||
/// cost payment — full effect resolution is deferred to AbilitySystem (future).
|
||||
/// Repentance / Instinct: pass ability targets via cardTargets for unit/tile inputs.
|
||||
/// </summary>
|
||||
public static GameState ChannelCard(
|
||||
GameState state, string actorId, string cardInstanceId, IReadOnlyList<Coord>? targetTiles)
|
||||
GameState state, string actorId, string cardInstanceId, IReadOnlyList<Coord>? targetTiles,
|
||||
IReadOnlyList<AbilityTarget>? cardTargets = null)
|
||||
{
|
||||
var player = state.Players[actorId];
|
||||
var card = player.Hand.FirstOrDefault(c => c.InstanceId == cardInstanceId)
|
||||
@@ -358,7 +358,7 @@ public static class GameEngine
|
||||
player.CurrentSt -= card.StCost;
|
||||
|
||||
// Fire inline effects if the card has an EffectsJson action list.
|
||||
AbilitySystem.FireCardEffects(state, actorId, card);
|
||||
AbilitySystem.FireCardEffects(state, actorId, card, cardTargets);
|
||||
|
||||
player.Discard.Add(card);
|
||||
|
||||
|
||||
@@ -22,13 +22,15 @@ public sealed record GamePlaceArchSpiritRequest(Guid SessionId, CoordDto Positio
|
||||
/// Spirit cards require TargetTile (single tile within ArchSpirit's channeling range).
|
||||
/// Terramorpha cards require TargetTiles (1 tile for Mono, 2 for Di, 3 for Tri — each
|
||||
/// subsequent tile must be orthogonally adjacent to the previous).
|
||||
/// Other card types (Repentance, Instinct, Ruin) may omit both.
|
||||
/// Repentance / Instinct: pass ability targets via Targets when effects need unit/tile input.
|
||||
/// Ruin / Other: no tile required.
|
||||
/// </summary>
|
||||
public sealed record GamePlayCardRequest(
|
||||
Guid SessionId,
|
||||
string CardInstanceId,
|
||||
CoordDto? TargetTile = null,
|
||||
IReadOnlyList<CoordDto>? TargetTiles = null);
|
||||
Guid SessionId,
|
||||
string CardInstanceId,
|
||||
CoordDto? TargetTile = null,
|
||||
IReadOnlyList<CoordDto>? TargetTiles = null,
|
||||
IReadOnlyList<AbilityTarget>? Targets = null);
|
||||
|
||||
/// <summary>Move a unit on the board to a new tile.</summary>
|
||||
public sealed record GameMoveUnitRequest(Guid SessionId, string UnitInstanceId, CoordDto TargetPosition);
|
||||
|
||||
@@ -49,7 +49,7 @@ internal sealed class GamePlayCardHandler : GameHandlerBase, IMessageHandler
|
||||
else if (req.TargetTile is not null)
|
||||
targets = new[] { new Coord(req.TargetTile.X, req.TargetTile.Y) };
|
||||
|
||||
var newState = GameEngine.ChannelCard(state, actorId, req.CardInstanceId, targets);
|
||||
var newState = GameEngine.ChannelCard(state, actorId, req.CardInstanceId, targets, req.Targets);
|
||||
|
||||
await SaveStateAsync(_gameDb, session, newState, actorId, "game.play_card",
|
||||
JsonSerializer.Serialize(req), ct);
|
||||
|
||||
Reference in New Issue
Block a user