Files
SVSimServer/SVSim.BattleNode/Sessions/Dispatch/Handlers/PlayActionsHandler.cs
gamer147 d8b5ef950d feat(battle-node): reveal generated tokens on play via remembered identity
PlayActionsHandler mines add ops into BattleSessionState.RecordToken each
frame; a token played in a later frame now synthesizes a knownList from the
remembered cardId instead of degrading. Bullet-3 audit F1.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-03 23:36:44 -04:00

43 lines
2.0 KiB
C#

using SVSim.BattleNode.Protocol;
using SVSim.BattleNode.Protocol.Bodies;
namespace SVSim.BattleNode.Sessions.Dispatch.Handlers;
/// <summary>PvP PlayActions translator (vanilla deck-card slice). Synthesizes the opponent-facing
/// knownList from the sender's idx->cardId map + the orderList move op, renames targetList ->
/// oppoTargetList, drops orderList, consumes keyAction.
/// Token plays resolve their cardId from add ops 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");
// Mine generated-token identities from this frame's add ops into the sender's idx->cardId
// map, so a token played in a LATER frame resolves its cardId (bullet-3 audit F1).
foreach (var (idx, cardId) in KnownListBuilder.MineAddOps(orderList))
ctx.State.RecordToken(ctx.From, idx, cardId);
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);
var frame = ctx.Env with { Body = body };
return new[] { new DispatchRoute(ctx.Other, frame, false) };
}
}