Choice/Discover-into-hand fanfares add a candidates-only token to hand; the
chosen cardId rides keyAction.selectCard on the generating play, not the
orderList add op. Record idx->chosenCardId at generation (candidate-membership
join) so the later play reveals the real identity via the existing
BuildPlayedCard path; forward {type,cardId} to the opponent and strip
selectCard for hidden (open:0) picks (pass through for open:1, provisional).
- KnownListBuilder.MineChoicePicks + StripKeyActionForOpponent (pure)
- BattleSessionState.RecordChoicePicksFrom (reuses IdxToCardId, no new state)
- PlayActionsBroadcastBody.keyAction + KeyActionEntry/SelectCardEntry
- PlayActionsHandler wires both; EchoHandler unchanged (picks ride the send)
Tests (TDD red->green): 8 KnownListBuilder + 2 dispatch + 2 conformance
(shape-locked to tk2_regular L151 generation / L193 reveal). Full suite 976/0.
Spec: docs/superpowers/specs/2026-06-04-battle-node-choice-token-reveal-design.md
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
52 lines
2.8 KiB
C#
52 lines
2.8 KiB
C#
using SVSim.BattleNode.Protocol;
|
|
using SVSim.BattleNode.Protocol.Bodies;
|
|
|
|
namespace SVSim.BattleNode.Sessions.Dispatch.Handlers;
|
|
|
|
/// <summary>PvP PlayActions translator. Synthesizes the opponent-facing knownList from the sender's
|
|
/// idx->cardId map + the orderList move op, renames targetList -> oppoTargetList, drops orderList,
|
|
/// and forwards a stripped keyAction for choice/Discover plays ({type,cardId}; selectCard dropped
|
|
/// for a hidden open:0 pick). Token plays resolve their cardId from add ops (concrete tokens) or
|
|
/// keyAction.selectCard (choice picks) mined on earlier frames; an un-generated token idx still
|
|
/// degrades to {playIdx,type} (no knownList). Bot drop (no rule).</summary>
|
|
internal sealed class PlayActionsHandler : IFrameHandler
|
|
{
|
|
public IReadOnlyList<DispatchRoute> Handle(FrameDispatchContext ctx)
|
|
{
|
|
if (ctx.Type != BattleType.Pvp || !ctx.BothAfterReady())
|
|
return Array.Empty<DispatchRoute>();
|
|
|
|
var entries = (ctx.Env.Body as RawBody)?.Entries ?? new Dictionary<string, object?>();
|
|
var playIdx = (int)KnownListBuilder.AsLong(entries.GetValueOrDefault("playIdx"));
|
|
var type = (int)KnownListBuilder.AsLong(entries.GetValueOrDefault("type"));
|
|
|
|
var orderList = entries.GetValueOrDefault("orderList");
|
|
var keyAction = entries.GetValueOrDefault("keyAction");
|
|
|
|
// Mine generated-token identities from this frame's add ops into the right side's idx->cardId
|
|
// map (isSelf:1 → sender; isSelf:0 → opponent, a cross-side gift), so a token played in a LATER
|
|
// frame resolves its cardId — by whichever side ends up playing it (bullet-3 audit F1).
|
|
ctx.State.RecordTokensFrom(ctx.From, ctx.Other, orderList);
|
|
|
|
// Choice/Discover-into-hand: the chosen cardId rides keyAction.selectCard (the orderList's
|
|
// choiceAdd carries candidates only). Record idx->chosenCardId now so the later play reveals it.
|
|
ctx.State.RecordChoicePicksFrom(ctx.From, ctx.Other, orderList, keyAction);
|
|
|
|
var deckMap = ctx.State.GetOrSeedDeckMap(ctx.From);
|
|
var played = KnownListBuilder.BuildPlayedCard(deckMap, playIdx, orderList);
|
|
var oppoTargets = KnownListBuilder.RenameTargets(entries.GetValueOrDefault("targetList"));
|
|
|
|
var body = new PlayActionsBroadcastBody(
|
|
PlayIdx: playIdx,
|
|
Type: type,
|
|
KnownList: played is null ? null : new[] { played },
|
|
OppoTargetList: oppoTargets,
|
|
// {type,cardId} forwarded so the opponent renders the choice token; selectCard dropped
|
|
// when open==0 (hidden draw-to-hand pick). Null for a vanilla play (no keyAction).
|
|
KeyAction: KnownListBuilder.StripKeyActionForOpponent(keyAction));
|
|
|
|
var frame = ctx.Env with { Body = body };
|
|
return new[] { new DispatchRoute(ctx.Other, frame, false) };
|
|
}
|
|
}
|