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>
71 lines
4.3 KiB
C#
71 lines
4.3 KiB
C#
using SVSim.BattleNode.Sessions;
|
|
|
|
namespace SVSim.BattleNode.Sessions.Dispatch;
|
|
|
|
/// <summary>Mutable per-session state shared across frame handlers. The mulligan barrier's
|
|
/// post-swap hands, plus (PvP-equivalency, vanilla slice) the per-side idx->cardId map used to
|
|
/// synthesize the opponent-facing <c>knownList</c>. Generated tokens (cardIds mined from
|
|
/// orderList <c>add</c> ops) are recorded into the SAME
|
|
/// <see cref="IdxToCardId"/> map via <see cref="RecordToken"/>; a reveal-gate set is still future.</summary>
|
|
internal sealed class BattleSessionState
|
|
{
|
|
public BattleSessionPhase SessionPhase { get; set; } = BattleSessionPhase.AwaitingInitNetwork;
|
|
public Dictionary<IBattleParticipant, long[]> PostSwapHands { get; } = new();
|
|
|
|
/// <summary>Per-side idx->cardId, seeded lazily from <see cref="MatchContext.SelfDeckCardIds"/>.
|
|
/// Holds deck cards (idx 1..deckCount, seeded) and generated tokens (idx>deckCount, recorded
|
|
/// from add ops via <see cref="RecordToken"/>).</summary>
|
|
public Dictionary<IBattleParticipant, Dictionary<int, long>> IdxToCardId { get; } = new();
|
|
|
|
/// <summary>The sender's idx->cardId map, seeding it from its <see cref="MatchContext"/> on first
|
|
/// use. <c>BuildPlayerDeck</c> assigns deck idx = position+1, so entry (i+1) -> cardIds[i].</summary>
|
|
public IReadOnlyDictionary<int, long> GetOrSeedDeckMap(IBattleParticipant side)
|
|
{
|
|
if (!IdxToCardId.TryGetValue(side, out var map))
|
|
{
|
|
map = new Dictionary<int, long>();
|
|
var deck = side.Context.SelfDeckCardIds;
|
|
for (var i = 0; i < deck.Count; i++) map[i + 1] = deck[i];
|
|
IdxToCardId[side] = map;
|
|
}
|
|
return map;
|
|
}
|
|
|
|
/// <summary>Record a generated token's identity into the side's idx->cardId map (the same map
|
|
/// that holds deck cards). Mined from the sender's <c>orderList</c> <c>add</c> ops by
|
|
/// <see cref="KnownListBuilder.MineAddOps"/>; surfaced later by <c>BuildPlayedCard</c> when the
|
|
/// token is the played card. Deck idxs (1..deckCount) and token idxs (>deckCount) don't
|
|
/// collide — the client allocates token idxs after the deck.</summary>
|
|
public void RecordToken(IBattleParticipant side, int idx, long cardId)
|
|
{
|
|
GetOrSeedDeckMap(side); // ensure the per-side map exists (deck-seeded)
|
|
IdxToCardId[side][idx] = cardId; // overwrite-on-conflict: latest identity wins
|
|
}
|
|
|
|
/// <summary>Mine generated-token identities from a sender's <c>orderList</c> <c>add</c> ops and
|
|
/// record each into the correct side's map. <c>isSelf:1</c> → the sender's own token (<paramref
|
|
/// name="from"/>); <c>isSelf:0</c> → a cross-side gift living at that idx in the OPPONENT's index
|
|
/// space (<paramref name="other"/>) — <c>isSelf</c> is the sender's perspective tag on
|
|
/// <c>CardObj.IsPlayer</c> (RegisterToken.cs:22), and a card has a single <c>CardObj.Index</c>, so
|
|
/// the gifted idx is the same slot in the recipient's own map (the one consulted when the recipient
|
|
/// later plays it). Shared by <c>PlayActionsHandler</c> and <c>EchoHandler</c> — an Echo's orderList
|
|
/// carries the same add-op shape (<c>SendCardDataMaker.MakeEchoData</c>), so both mine identically;
|
|
/// Echo is mined but never relayed.</summary>
|
|
public void RecordTokensFrom(IBattleParticipant from, IBattleParticipant other, object? orderList)
|
|
{
|
|
foreach (var (idx, cardId, isSelf) in KnownListBuilder.MineAddOps(orderList))
|
|
RecordToken(isSelf == 1 ? from : other, idx, cardId);
|
|
}
|
|
|
|
/// <summary>Mine + record choice/Discover-token picks (<see cref="KnownListBuilder.MineChoicePicks"/>)
|
|
/// into the correct side's map, by the same <c>isSelf</c> routing as <see cref="RecordTokensFrom"/>.
|
|
/// The chosen cardId rides the generating send's <c>keyAction.selectCard</c> (not the orderList add
|
|
/// op, which carries candidates only); recorded regardless of the choice's <c>open</c> visibility —
|
|
/// an unplayed idx is never queried, so a stray record is harmless.</summary>
|
|
public void RecordChoicePicksFrom(IBattleParticipant from, IBattleParticipant other, object? orderList, object? keyAction)
|
|
{
|
|
foreach (var (idx, cardId, isSelf) in KnownListBuilder.MineChoicePicks(orderList, keyAction))
|
|
RecordToken(isSelf == 1 ? from : other, idx, cardId);
|
|
}
|
|
}
|