using SVSim.BattleNode.Protocol; using SVSim.BattleNode.Protocol.Bodies; namespace SVSim.BattleNode.Sessions.Dispatch.Handlers; /// 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 (idx>deck) degrade silently to /// {playIdx,type} (no knownList). Scripted/Bot drop (no rule). internal sealed class PlayActionsHandler : IFrameHandler { public IReadOnlyList Handle(FrameDispatchContext ctx) { if (ctx.Type != BattleType.Pvp || !ctx.BothAfterReady()) return Array.Empty(); var entries = (ctx.Env.Body as RawBody)?.Entries ?? new Dictionary(); var playIdx = (int)KnownListBuilder.AsLong(entries.GetValueOrDefault("playIdx")); var type = (int)KnownListBuilder.AsLong(entries.GetValueOrDefault("type")); var deckMap = ctx.State.GetOrSeedDeckMap(ctx.From); var played = KnownListBuilder.BuildPlayedCard(deckMap, playIdx, entries.GetValueOrDefault("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) }; } }