Implement triggered ability target prompting (Option D)

When a Triggered ability fires and any of its actions require a human target
pick, the server now pauses execution instead of auto-resolving:

Server:
- AbilitySystem.FireTrigger detects actions needing client input via
  ActionNeedsClientTargets(); stores PendingTriggeredTarget in GameState and
  returns early rather than executing the ability
- PushStateToPlayersAsync (GameHandlerBase) checks for PendingTriggeredTarget
  after every state push and sends a game.ability.triggered_target_request push
  to the owning player carrying the action definition and range
- New GameTriggeredTargetHandler (game.triggered_target) receives the player's
  picks, calls AbilitySystem.ResumeTriggeredAbility, and broadcasts the result
- PendingTriggeredTarget model stored in GameState.PendingTriggeredTarget (JSONB)

Client:
- Game.gd handles the triggered_target_request push and emits a signal
- game_screen.gd connects the signal, re-uses the existing ABILITY_TARGET mode
  and _start_ability_targeting() flow, then sends game.triggered_target instead
  of game.activate_ability when done
- A brief banner ("Triggered: <name> — select a target") informs the player

"Warrant Cover" (OnChanneled, Owner unit pick) will now correctly prompt the
player to select which friendly unit gains +1 Defense.

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-03-28 18:50:48 -04:00
co-authored by Claude Happy
parent cb601abd00
commit 515bfaabdf
9 changed files with 343 additions and 1 deletions
@@ -228,6 +228,26 @@ public static class AbilitySystem
_triggerCountsPerTurn[key] = used + 1;
}
// If any action needs a human pick, pause and request client input.
if (def.Actions.Any(ActionNeedsClientTargets))
{
state.PendingTriggeredTarget = new PendingTriggeredTarget
{
ActorId = ownerId,
SourceInstanceId = unit.InstanceId,
AbilityName = def.Name ?? "Triggered Ability",
ActionsJson = JsonSerializer.Serialize(def.Actions, _jsonOpts),
RangeJson = def.Range is not null
? JsonSerializer.Serialize(def.Range, _jsonOpts)
: null,
ForceDurationJson = def.Duration is not null
? JsonSerializer.Serialize(def.Duration, _jsonOpts)
: null,
};
// Return immediately — only one pending request at a time.
return state;
}
ExecuteActions(def.Actions, ctx, clientTargets: null, forceDuration: def.Duration);
}
}
@@ -508,6 +528,89 @@ public static class AbilitySystem
}
}
// ── Triggered ability client-target detection & resume ────────────────────
/// <summary>
/// Returns true when the action requires a human target pick rather than
/// being fully server-auto-resolvable. Used by <see cref="FireTrigger"/> to
/// decide whether to pause and request client input.
/// Also called by <c>GameHandlerBase</c> to locate the first client-pick action
/// for the <c>TriggeredTargetRequestPush</c> payload.
/// </summary>
internal static bool ActionNeedsClientTargets_Public(Models.Action action)
=> ActionNeedsClientTargets(action);
private static bool ActionNeedsClientTargets(Models.Action action)
{
// ChooseOne always needs the player to pick a branch.
if (action.ChooseOne is { Branches.Length: > 0 })
return true;
var sel = action.Target;
// Player-type targets are always server-resolved.
if (sel.Type == TargetType.Player)
return false;
// "All" targets are enumerated server-side with no player choice.
if (sel.Count.All)
return false;
// These ownerships are auto-resolved: self, random, chained from prior action.
return sel.Ownership is not (
TargetOwnership.Self or
TargetOwnership.ExactSelf or
TargetOwnership.Target or
TargetOwnership.Random);
}
/// <summary>
/// Resumes a triggered ability that was paused for client target input.
/// Called by <c>GameTriggeredTargetHandler</c> once the player submits their picks.
/// </summary>
public static GameState ResumeTriggeredAbility(
GameState state,
string actorId,
string requestId,
IReadOnlyList<AbilityTarget> clientTargets)
{
var pending = state.PendingTriggeredTarget
?? throw new GameException("NO_PENDING_TRIGGER");
if (pending.RequestId != requestId)
throw new GameException("REQUEST_ID_MISMATCH");
if (pending.ActorId != actorId)
throw new GameException("NOT_YOUR_TRIGGER");
// Clear before executing so any nested triggers don't see a stale request.
state.PendingTriggeredTarget = null;
var actions = JsonSerializer.Deserialize<Models.Action[]>(pending.ActionsJson, _jsonOpts) ?? [];
// Source unit may have left the battlefield while waiting — skip silently if so.
var source = state.Players.Values
.SelectMany(p => p.Field).OfType<FieldCard>()
.FirstOrDefault(f => f.InstanceId == pending.SourceInstanceId);
if (source is null) return state;
var ctx = new AbilityContext
{
State = state,
ActorId = pending.ActorId,
Source = source,
};
DurationModel? forceDuration = pending.ForceDurationJson is not null
? JsonSerializer.Deserialize<DurationModel>(pending.ForceDurationJson, _jsonOpts)
: null;
ExecuteActions(actions, ctx, clientTargets, requireClientTargets: true,
forceDuration: forceDuration);
return state;
}
// ── Target resolution ─────────────────────────────────────────────────────
private static List<object> ResolveTargets(