feat(battle-node): mine generated-token cardIds from orderList add ops
KnownListBuilder.MineAddOps extracts (idx,cardId) from isSelf:1 add ops, skipping cross-side gifts and choice tokens. Bullet-3 audit F1. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -42,6 +42,37 @@ 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)
|
||||
{
|
||||
if (orderList is not IEnumerable<object?> ops) yield break;
|
||||
foreach (var op in ops)
|
||||
{
|
||||
if (op is not IDictionary<string, object?> opDict) continue;
|
||||
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
|
||||
|
||||
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
|
||||
var cardId = AsLong(cardIdRaw);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Rename <c>targetList</c> -> <c>oppoTargetList</c>; <c>isSelf</c> is actor-relative
|
||||
/// and passes through unchanged (F2). Null for a missing/empty list.</summary>
|
||||
public static IReadOnlyList<OppoTargetEntry>? RenameTargets(object? targetList)
|
||||
|
||||
Reference in New Issue
Block a user