feat(battle-node): cross-side gift + Echo-frame token mining
Close the two generated-token gaps that desynced PvP live test #3 (the Forestcraft Fairy), both sourced from the 2026-06-03 decomp-validation table. - MineAddOps now returns (idx, cardId, isSelf) and no longer drops isSelf:0. isSelf is the sender's perspective tag on CardObj.IsPlayer (RegisterToken.cs:22) and a card has one CardObj.Index, so an isSelf:0 add is the opponent's card. - New shared BattleSessionState.RecordTokensFrom routes isSelf:1 -> sender, isSelf:0 -> opponent (the gift lives in the recipient's map, consulted when they play it). PlayActionsHandler delegates to it. - EchoHandler now mines via the same helper but still returns no routes. An Echo's orderList carries the same add-op shape as a send (MakeEchoData -> MakeCommonSendAndEchoCardData), so MineAddOps applies verbatim; mining != relaying. Choice/copy/private-group adds stay skipped (no concrete cardId). Full solution 963/963 green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -41,4 +41,19 @@ internal sealed class BattleSessionState
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,22 @@
|
||||
using SVSim.BattleNode.Protocol;
|
||||
|
||||
namespace SVSim.BattleNode.Sessions.Dispatch.Handlers;
|
||||
|
||||
/// <summary>Echo is the receiver's per-frame ack; the client has no inbound Echo handler, so the
|
||||
/// node consumes it (bullet-2 audit). Relaying would risk an echo->echo storm.</summary>
|
||||
/// node never relays it (bullet-2 audit — relaying would risk an echo->echo storm). It IS mined,
|
||||
/// though: an Echo's orderList carries the same add-op shape as PlayActions
|
||||
/// (SendCardDataMaker.MakeEchoData -> MakeCommonSendAndEchoCardData), so it can hold a token's real
|
||||
/// identity — notably the receiver's own (isSelf:1) view of a cross-side gift. We mine it into the
|
||||
/// right side's idx->cardId map and still return no routes (mining != relaying).</summary>
|
||||
internal sealed class EchoHandler : IFrameHandler
|
||||
{
|
||||
public IReadOnlyList<DispatchRoute> Handle(FrameDispatchContext ctx) => Array.Empty<DispatchRoute>();
|
||||
public IReadOnlyList<DispatchRoute> Handle(FrameDispatchContext ctx)
|
||||
{
|
||||
if (ctx.Type == BattleType.Pvp && ctx.BothAfterReady())
|
||||
{
|
||||
var orderList = (ctx.Env.Body as RawBody)?.Entries.GetValueOrDefault("orderList");
|
||||
ctx.State.RecordTokensFrom(ctx.From, ctx.Other, orderList);
|
||||
}
|
||||
return Array.Empty<DispatchRoute>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ internal sealed class PlayActionsHandler : IFrameHandler
|
||||
|
||||
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);
|
||||
// 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);
|
||||
|
||||
var deckMap = ctx.State.GetOrSeedDeckMap(ctx.From);
|
||||
var played = KnownListBuilder.BuildPlayedCard(deckMap, playIdx, orderList);
|
||||
|
||||
@@ -42,17 +42,19 @@ internal static class KnownListBuilder
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Mine generated-token identities from the sender's <c>add</c> ops: yields
|
||||
/// <c>(idx, cardId)</c> for every idx in each <c>{add:{idx:[...], isSelf:1, card:{cardId}}}</c>
|
||||
/// op. Skips <c>isSelf:0</c> adds (cross-side gifts — belong in the other side's map, deferred)
|
||||
/// and any add whose <c>card</c> has no concrete <c>cardId</c> — choice tokens
|
||||
/// (<c>card:{candidates}</c>, <c>RegisterChoiceAdd</c>), copy tokens (<c>card:{baseIdx}</c>,
|
||||
/// <c>RegisterCopyToken</c>), and private-group adds (string <c>idx</c>) — all deferred and all
|
||||
/// caught by the <c>cardId</c>-key / <c>idx</c>-is-list guards. This is the only place a
|
||||
/// freshly-generated card's identity exists on the wire (bullet-3 audit F1; producing code
|
||||
/// <c>RegisterToken</c>/<c>RegisterActionBase</c>) — the played-card op itself never carries a
|
||||
/// <c>cardId</c>.</summary>
|
||||
public static IEnumerable<(int Idx, long CardId)> MineAddOps(object? orderList)
|
||||
/// <summary>Mine generated-token identities from a sender's <c>add</c> ops: yields
|
||||
/// <c>(idx, cardId, isSelf)</c> for every idx in each <c>{add:{idx:[...], isSelf, card:{cardId}}}</c>
|
||||
/// op. <c>isSelf</c> is surfaced verbatim (the sender's perspective tag on <c>CardObj.IsPlayer</c>,
|
||||
/// <c>RegisterToken.cs:22</c>) so the caller can route the identity into the correct side's map —
|
||||
/// <c>isSelf:1</c> = the sender's own token, <c>isSelf:0</c> = a cross-side gift living at this idx
|
||||
/// in the OPPONENT's index space (<see cref="BattleSessionState.RecordTokensFrom"/>). Skips any add
|
||||
/// whose <c>card</c> has no concrete <c>cardId</c> — choice tokens (<c>card:{candidates}</c>,
|
||||
/// <c>RegisterChoiceAdd</c>), copy tokens (<c>card:{baseIdx}</c>, <c>RegisterCopyToken</c>), and
|
||||
/// private-group adds (string <c>idx</c>) — all deferred and all caught by the <c>cardId</c>-key /
|
||||
/// <c>idx</c>-is-list guards. This is the only place a freshly-generated card's identity exists on
|
||||
/// the wire (bullet-3 audit F1; producing code <c>RegisterToken</c>/<c>RegisterActionBase</c>) —
|
||||
/// the played-card op itself never carries a <c>cardId</c>.</summary>
|
||||
public static IEnumerable<(int Idx, long CardId, int IsSelf)> MineAddOps(object? orderList)
|
||||
{
|
||||
if (orderList is not IEnumerable<object?> ops) yield break;
|
||||
foreach (var op in ops)
|
||||
@@ -61,7 +63,7 @@ internal static class KnownListBuilder
|
||||
if (!opDict.TryGetValue("add", out var addRaw) || addRaw is not IDictionary<string, object?> add) continue;
|
||||
|
||||
add.TryGetValue("isSelf", out var isSelfRaw);
|
||||
if (AsLong(isSelfRaw) != 1) continue; // own tokens only; cross-side gifts deferred
|
||||
var isSelf = (int)AsLong(isSelfRaw);
|
||||
|
||||
if (!add.TryGetValue("card", out var cardRaw) || cardRaw is not IDictionary<string, object?> card) continue;
|
||||
if (!card.TryGetValue("cardId", out var cardIdRaw)) continue; // candidates/isChoice → no identity yet
|
||||
@@ -69,7 +71,7 @@ internal static class KnownListBuilder
|
||||
|
||||
if (!add.TryGetValue("idx", out var idxRaw) || idxRaw is not IEnumerable<object?> idxList) continue;
|
||||
foreach (var i in idxList)
|
||||
yield return ((int)AsLong(i), cardId);
|
||||
yield return ((int)AsLong(i), cardId, isSelf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user