463 lines
29 KiB
C#
463 lines
29 KiB
C#
using SVSim.BattleNode.Bridge;
|
|
using SVSim.BattleNode.Protocol;
|
|
using SVSim.BattleNode.Sessions;
|
|
using SVSim.BattleNode.Sessions.Dispatch;
|
|
using SVSim.BattleNode.Sessions.Engine;
|
|
using SVSim.BattleNode.Sessions.Participants;
|
|
|
|
namespace SVSim.UnitTests.BattleNode.Integration;
|
|
|
|
/// <summary>
|
|
/// Node-native battle harness for the Headless-Conductor milestones (M-HC-*). It reproduces what
|
|
/// <c>BattleSession.EnsureEngineSetup</c> does — shuffle each side's deck from a FIXED master seed and
|
|
/// <c>SessionBattleEngine.Setup</c> the two seats — then exposes the engine + state + participants so
|
|
/// later milestone tests can drive multi-frame sequences and assert on engine board state.
|
|
///
|
|
/// <para>WHY drive the engine directly (not a full <c>BattleSession</c>): the session's <c>_state</c>
|
|
/// and <c>_engine</c> are private with no fixed-seed injection point, and every milestone assertion is
|
|
/// on engine board state. The engine (<c>SessionBattleEngine</c>) is the unit under test, so we seat it
|
|
/// the same way the session does and skip the WS/dispatch scaffolding.</para>
|
|
///
|
|
/// <para>The oracle by construction: the node assigns idx = position in the shuffled order
|
|
/// (<see cref="BattleSessionState.GetShuffledDeck"/>), and the engine's headless draw is lowest-Index
|
|
/// first, so a FIXED seed makes the engine's draw order reproduce the node's BY CONSTRUCTION.</para>
|
|
///
|
|
/// <para>Engine globals (<c>CardMaster</c>, <c>GameMgr</c>, <c>Wizard.Data</c>) are primed by
|
|
/// <c>SessionBattleEngine.Setup</c> itself (it calls <c>EngineGlobalInit.EnsureInitialized()</c>, which
|
|
/// loads the full cards.json from <c>AppContext.BaseDirectory/Data/cards.json</c>). The harness adds no
|
|
/// global init of its own. NOTE: unlike the live session, the harness does NOT acquire
|
|
/// <c>EngineSessionGate</c> — driving the engine directly bypasses it. One engine-backed battle at a
|
|
/// time is assumed within a test (the engine's process-global statics can't back two concurrently).</para>
|
|
/// </summary>
|
|
internal sealed class NodeNativeBattleHarness : IDisposable
|
|
{
|
|
/// <summary>A deterministic master seed so deck shuffles (and the engine RNG stream born from it)
|
|
/// are reproducible. Matches the value the engine construction tests use.</summary>
|
|
public const int FixedMasterSeed = 12345;
|
|
|
|
/// <summary>Default seat A viewer id — distinct from <see cref="DefaultSeatBViewerId"/> so the two
|
|
/// sides shuffle independently (the shuffle seed mixes in the viewer id).</summary>
|
|
public const long DefaultSeatAViewerId = 1001;
|
|
public const long DefaultSeatBViewerId = 1002;
|
|
|
|
/// <summary>Spellboost cost-reducer card (looking ahead to M-HC-3). Known id present in cards.json
|
|
/// (sourced from tk2 battle capture / existing engine tests); a cards.json regeneration that drops
|
|
/// it will produce a traceable failure here.</summary>
|
|
public const long SpellboostCardId = 101314020;
|
|
|
|
/// <summary>A second spellboost card seen in the tk2 capture. Known id present in cards.json
|
|
/// (sourced from tk2 battle capture / existing engine tests); a cards.json regeneration that drops
|
|
/// it will produce a traceable failure here.</summary>
|
|
public const long SpellboostCardIdAlt = 100314020;
|
|
|
|
/// <summary>A plain vanilla follower the engine resolution path proved out
|
|
/// (HeadlessFixture.FollowerId). The bulk of the deterministic deck. Known id present in cards.json
|
|
/// (sourced from tk2 battle capture / existing engine tests); a cards.json regeneration that drops
|
|
/// it will produce a traceable failure here.</summary>
|
|
public const long VanillaFollowerId = 100011010;
|
|
|
|
/// <summary>A SECOND, distinct cost-1 vanilla follower (char_type 1, cost 1, no skill) — present +
|
|
/// creatable in cards.json. Used by the opponent-reveal substitution test as the WIRE cardId that
|
|
/// must override a seeded identity (it is deliberately NOT in any harness deck, so its only route
|
|
/// onto the board is a reveal). Named here so card-id provenance stays traceable as ids accumulate
|
|
/// (Task-4 review nit promoted in M-HC-3).</summary>
|
|
public const long AltVanillaFollowerId = 101211120;
|
|
|
|
/// <summary>A truly skill-less cost-1 vanilla follower with attack >= life (a 1/1), so a mutual
|
|
/// follower-vs-follower attack is a LETHAL trade (each deals 1, each has 1 life → both die). The
|
|
/// proven vanillas <see cref="VanillaFollowerId"/>/<see cref="AltVanillaFollowerId"/> are 1/2, so they
|
|
/// survive a single trade — this id is the one that exercises the death/removal arm of an attack
|
|
/// (M-HC-4a follower trade). Present + creatable in cards.json (no skill, char_type 1, cost 1, 1/1).</summary>
|
|
public const long VanillaOneOneFollowerId = 900011080;
|
|
|
|
/// <summary>A SIMPLE single-target when_play DAMAGE spell (M-HC-4c fixture). cards.json id 100414020:
|
|
/// char_type 4 (spell), clan 4 (Dragoncraft), cost 1, skill <c>damage</c> / skill_timing
|
|
/// <c>when_play</c> / skill_target <c>character=op&target=inplay&card_type=unit&select_count=1</c>
|
|
/// / skill_option <c>damage=2</c> — i.e. "deal 2 damage to a selected enemy follower". Concrete sane
|
|
/// cost (1), no board-state-dependent magnitude, no condition beyond an enemy unit existing — the
|
|
/// cleanest targeted-play fixture in the current dump. Present + creatable in cards.json.</summary>
|
|
public const long SingleTargetDamageSpellId = 100414020;
|
|
|
|
/// <summary>The flat damage magnitude of <see cref="SingleTargetDamageSpellId"/> (skill_option
|
|
/// <c>damage=2</c>). The targeted-play test asserts the enemy follower's life drops by exactly this.</summary>
|
|
public const int SingleTargetDamageAmount = 2;
|
|
|
|
/// <summary>A high-life vanilla follower (M-HC-4c damage TARGET). cards.json id 101411060: char_type 1,
|
|
/// clan 4, cost 2, 1/4, no skill. A 1/4 body takes <see cref="SingleTargetDamageAmount"/> (2) and
|
|
/// SURVIVES at life 2 — so the targeted-damage assertion reads a clean life DROP (not a death/removal,
|
|
/// which would only prove BoardCount). Present + creatable in cards.json.</summary>
|
|
public const long HighLifeVanillaFollowerId = 101411060;
|
|
|
|
/// <summary>Base life of <see cref="HighLifeVanillaFollowerId"/> (4). Pre-damage pin for the target.</summary>
|
|
public const int HighLifeVanillaFollowerLife = 4;
|
|
|
|
/// <summary>A SIMPLE CHOICE card (M-HC-4c choice fixture). cards.json id 127011010: char_type 1
|
|
/// (follower), clan 0 (Neutral — playable under any seat class), cost 1, 1/2, skill
|
|
/// <c>choice,token_draw</c> / skill_timing <c>when_choice_play,when_play</c> / skill_option
|
|
/// <c>card_id=121011010:120011010,...</c> — i.e. "choose ONE of two tokens to add to hand"
|
|
/// (<see cref="ChoiceTokenA"/> / <see cref="ChoiceTokenB"/>). The choice OUTCOME is directly
|
|
/// observable: the chosen token lands in the caster's hand, so a test can assert which branch
|
|
/// resolved by the new hand card's identity. (The token resolves into HAND — confirmed against the
|
|
/// capture's <c>orderList.add{to:20}</c> hand-zone op — despite the skill_option <c>summon_side=me</c>
|
|
/// superficially reading like a summon-to-board.) Present + creatable in cards.json.</summary>
|
|
public const long ChoiceCardId = 127011010;
|
|
|
|
/// <summary>The first choice option of <see cref="ChoiceCardId"/> (token added to hand).</summary>
|
|
public const long ChoiceTokenA = 121011010;
|
|
|
|
/// <summary>The second choice option of <see cref="ChoiceCardId"/> (token added to hand).</summary>
|
|
public const long ChoiceTokenB = 120011010;
|
|
|
|
/// <summary>A BOARD-DEPENDENT cost-reducer follower (M-HC-4d fixture). cards.json id 127011020:
|
|
/// char_type 1 (follower), clan 0 (Neutral — playable under any seat class), base cost 6, 3/3, skill
|
|
/// <c>cost_change,rush</c> / skill_timing <c>when_evolve_other,when_change_inplay</c> / skill_option
|
|
/// <c>set=1,none</c> / skill_condition (cost_change) <c>turn=self&{me.hand_self.unit.count}>0&
|
|
/// character=me&target=evolution_card&card_type=unit</c> / skill_target <c>character=me&target=self
|
|
/// &card_type=unit</c> — i.e. "WHILE in hand, when ANOTHER of your followers evolves on your turn (and you
|
|
/// hold at least one other unit in hand), SET this card's cost to 1." The engine's evolve path
|
|
/// (<c>UnitBattleCard</c> non-skill evolve) scans the evolving player's HAND for cards whose skills have
|
|
/// <c>OnWhenEvolveOtherStart != 0</c> and registers them via <c>SkillCollectionBase.CreateWhenEvolveOtherInfo</c>;
|
|
/// <c>Skill_cost_change</c> then applies a <c>CostSetModifier(1)</c> to this card, so its resolved
|
|
/// <c>Cost</c> drops 6 → 1. Because the node reads opponent-facing cost straight off the resolved engine
|
|
/// (<c>SessionBattleEngine.PlayedCardCost</c>, M-HC-3), this board-dependent reduction is captured BY
|
|
/// CONSTRUCTION once evolve resolves headless (M-HC-4b) — this card validates that. Present + creatable in
|
|
/// cards.json.</summary>
|
|
public const long BoardDependentCostCardId = 127011020;
|
|
|
|
/// <summary>Base cost of <see cref="BoardDependentCostCardId"/> (6) — the pre-evolve resolved cost.</summary>
|
|
public const int BoardDependentCostBase = 6;
|
|
|
|
/// <summary>The flat cost <see cref="BoardDependentCostCardId"/> resolves to AFTER another follower evolves
|
|
/// on the controller's turn (skill_option <c>set=1</c> → <c>CostSetModifier(1)</c>). Independent of how many
|
|
/// followers evolved (a SET, not an add) — exactly 1.</summary>
|
|
public const int BoardDependentCostReduced = 1;
|
|
|
|
public BattleSessionState State { get; }
|
|
public StubParticipant SeatA { get; }
|
|
public StubParticipant SeatB { get; }
|
|
public SessionBattleEngine Engine { get; }
|
|
|
|
/// <summary>This side's deck in the node's shuffled order (idx == position + 1).</summary>
|
|
public IReadOnlyList<long> SeatADeck { get; }
|
|
public IReadOnlyList<long> SeatBDeck { get; }
|
|
|
|
private NodeNativeBattleHarness(
|
|
BattleSessionState state, StubParticipant a, StubParticipant b, SessionBattleEngine engine,
|
|
IReadOnlyList<long> seatADeck, IReadOnlyList<long> seatBDeck)
|
|
{
|
|
State = state;
|
|
SeatA = a;
|
|
SeatB = b;
|
|
Engine = engine;
|
|
SeatADeck = seatADeck;
|
|
SeatBDeck = seatBDeck;
|
|
}
|
|
|
|
/// <summary>Build a 30-card deck: mostly the vanilla follower plus a couple of spellboost cards
|
|
/// (so later milestones have a cost-reducer to play). All ids exist in cards.json.</summary>
|
|
public static IReadOnlyList<long> DefaultDeck()
|
|
{
|
|
var deck = new List<long>(30) { SpellboostCardId, SpellboostCardIdAlt };
|
|
deck.AddRange(Enumerable.Repeat(VanillaFollowerId, 30 - deck.Count));
|
|
return deck;
|
|
}
|
|
|
|
/// <summary>A deck for the M-HC-4d board-dependent-cost test: an alternating mix of the vanilla
|
|
/// follower (to play turn 1 and EVOLVE on seat A's evolve turn) and the <see cref="BoardDependentCostCardId"/>
|
|
/// (the <c>when_evolve_other set=1</c> cost-reducer that must sit IN HAND across the evolve). Alternating
|
|
/// 15/15 guarantees BOTH identities populate the opening hand + early draws regardless of the fixed shuffle;
|
|
/// the test locates each by identity (not a shuffle-dependent position). The cost-reducer's condition
|
|
/// <c>{me.hand_self.unit.count}>0</c> (another unit in hand) is satisfied because copies of BOTH followers
|
|
/// remain in hand at the evolve.</summary>
|
|
public static IReadOnlyList<long> BoardDependentCostDeck()
|
|
{
|
|
var deck = new List<long>(30);
|
|
for (int i = 0; i < 15; i++) { deck.Add(VanillaFollowerId); deck.Add(BoardDependentCostCardId); }
|
|
return deck;
|
|
}
|
|
|
|
/// <summary>Seat the engine exactly as <c>BattleSession.EnsureEngineSetup</c> does: shuffle each
|
|
/// side's deck from the fixed seed via <see cref="BattleSessionState.GetShuffledDeck"/>, then
|
|
/// <c>SessionBattleEngine.Setup(seed, deckA, deckB, classA, classB)</c>.</summary>
|
|
public static NodeNativeBattleHarness Create(
|
|
IReadOnlyList<long>? seatADeck = null,
|
|
IReadOnlyList<long>? seatBDeck = null,
|
|
CardClass seatAClass = CardClass.Forestcraft,
|
|
CardClass seatBClass = CardClass.Swordcraft,
|
|
int masterSeed = FixedMasterSeed)
|
|
{
|
|
var state = new BattleSessionState(masterSeed);
|
|
|
|
var a = new StubParticipant(DefaultSeatAViewerId, MakeCtx(seatADeck ?? DefaultDeck(), seatAClass));
|
|
var b = new StubParticipant(DefaultSeatBViewerId, MakeCtx(seatBDeck ?? DefaultDeck(), seatBClass));
|
|
|
|
var shuffledA = state.GetShuffledDeck(a);
|
|
var shuffledB = state.GetShuffledDeck(b);
|
|
|
|
var engine = new SessionBattleEngine();
|
|
engine.Setup(state.MasterSeed, shuffledA, shuffledB,
|
|
(int)a.Context.ClassId, (int)b.Context.ClassId);
|
|
|
|
return new NodeNativeBattleHarness(state, a, b, engine, shuffledA, shuffledB);
|
|
}
|
|
|
|
private static MatchContext MakeCtx(IReadOnlyList<long> deck, CardClass cls) => new(
|
|
SelfDeckCardIds: deck,
|
|
ClassId: cls, CharaId: ((int)cls).ToString(), CardMasterName: "card_master_node_10015",
|
|
CountryCode: CountryCodes.Korea, UserName: "Player", SleeveId: "3000011",
|
|
EmblemId: "701441011", DegreeId: "300003", FieldId: 43, IsOfficial: 0,
|
|
BattleModeId: BattleModes.TakeTwo);
|
|
|
|
// --- engine board-state pass-throughs (seat:true == player A, false == opponent B) ----------
|
|
|
|
public bool IsReady => Engine.IsReady;
|
|
public int LeaderLife(bool playerSeat) => Engine.LeaderLife(playerSeat);
|
|
public int Pp(bool playerSeat) => Engine.Pp(playerSeat);
|
|
public int HandCount(bool playerSeat) => Engine.HandCount(playerSeat);
|
|
public int BoardCount(bool playerSeat) => Engine.BoardCount(playerSeat);
|
|
public int DeckCount(bool playerSeat) => Engine.DeckCount(playerSeat);
|
|
public int Turn(bool playerSeat) => Engine.Turn(playerSeat);
|
|
|
|
/// <summary>The engine Index of seat A's hand card at <paramref name="handPos"/> (the playIdx a
|
|
/// Play frame would carry to play it).</summary>
|
|
public int PlayerHandCardIndex(int handPos) => Engine.HandCardIndex(playerSeat: true, handPos);
|
|
|
|
/// <summary>The wire CardId of the hand card at <paramref name="handPos"/> on the given seat. Lets a
|
|
/// test find a specific card (e.g. the spellboost reducer) in a shuffled opening hand by identity.</summary>
|
|
public int HandCardId(bool playerSeat, int handPos) => Engine.HandCardId(playerSeat, handPos);
|
|
|
|
/// <summary>The engine Index of the hand card at <paramref name="handPos"/> on the given seat.</summary>
|
|
public int HandCardIndex(bool playerSeat, int handPos) => Engine.HandCardIndex(playerSeat, handPos);
|
|
|
|
/// <summary>The real wire <c>CardId</c> of the in-play follower at <paramref name="boardPos"/> on the
|
|
/// given seat (0-based, leader excluded). Asserts an opponent reveal seated the substituted identity
|
|
/// (M-HC-2).</summary>
|
|
public int InPlayCardId(bool playerSeat, int boardPos) => Engine.InPlayCardId(playerSeat, boardPos);
|
|
|
|
/// <summary>The engine <c>Index</c> of the in-play follower at <paramref name="boardPos"/> — the wire
|
|
/// <c>playIdx</c> an ATTACK frame carries to address that follower as the attacker (M-HC-4a).</summary>
|
|
public int InPlayCardIndex(bool playerSeat, int boardPos) => Engine.InPlayCardIndex(playerSeat, boardPos);
|
|
|
|
/// <summary>The current life/health of the in-play follower at <paramref name="boardPos"/>.</summary>
|
|
public int InPlayCardLife(bool playerSeat, int boardPos) => Engine.InPlayCardLife(playerSeat, boardPos);
|
|
|
|
/// <summary>The attack stat of the in-play follower at <paramref name="boardPos"/>.</summary>
|
|
public int InPlayCardAtk(bool playerSeat, int boardPos) => Engine.InPlayCardAtk(playerSeat, boardPos);
|
|
|
|
/// <summary>True while the in-play follower at <paramref name="boardPos"/> can still attack this turn.</summary>
|
|
public bool InPlayCardAttackable(bool playerSeat, int boardPos) => Engine.InPlayCardAttackable(playerSeat, boardPos);
|
|
|
|
/// <summary>True once the in-play follower at <paramref name="boardPos"/> has evolved (M-HC-4b).</summary>
|
|
public bool IsEvolved(bool playerSeat, int boardPos) => Engine.IsEvolved(playerSeat, boardPos);
|
|
|
|
/// <summary>The seat's current evolve-point count (M-HC-4b). An evolve spends one EP.</summary>
|
|
public int Ep(bool playerSeat) => Engine.Ep(playerSeat);
|
|
|
|
/// <summary>Turns remaining until the seat may evolve (0 == unlocked) (M-HC-4b).</summary>
|
|
public int EvolveWaitTurnCount(bool playerSeat) => Engine.EvolveWaitTurnCount(playerSeat);
|
|
|
|
/// <summary>Build an envelope for <paramref name="body"/> and ingest it into the engine for the
|
|
/// given seat (player == seat A). Mirrors <c>BattleNodeFlowTests.MakeEnvelopeWith</c> +
|
|
/// <c>SessionBattleEngine.Receive</c>.</summary>
|
|
public EngineIngestResult Push(NetworkBattleUri uri, Dictionary<string, object?> body, bool isPlayerSeat)
|
|
{
|
|
var seat = isPlayerSeat ? SeatA : SeatB;
|
|
var env = new MsgEnvelope(
|
|
uri, ViewerId: seat.ViewerId, Uuid: "udid-test", Bid: null, RetryAttempt: 0,
|
|
Cat: EmitCategory.Battle, PubSeq: null, PlaySeq: null,
|
|
Body: new RawBody(body));
|
|
return Engine.Receive(env, isPlayerSeat);
|
|
}
|
|
|
|
/// <summary>The engine's <c>NetworkBattleDefine.PlayActionType.ATTACK</c> opcode — confirmed
|
|
/// <c>= 10</c> in <c>SVSim.BattleEngine/Engine/NetworkBattleDefine.cs</c> (NOT 31, which is
|
|
/// PLAY_HAND_SELECT). The receiver maps the wire <c>type</c> int straight to the enum
|
|
/// (NetworkBattleReceiver.cs:1093).</summary>
|
|
public const int AttackOpcode = 10;
|
|
|
|
/// <summary>The engine's "self" viewer id (== <c>Certification.viewer_id</c> seeded by EngineGlobalInit).
|
|
/// The IsRecovery target parse derives a target's owner from <c>vid != PlayerStaticData.UserViewerID</c>
|
|
/// (== this value) — NOT from the <c>isSelf</c> key (that key is only read on the live, non-recovery
|
|
/// parse). So a target vid == this resolves on BattlePlayer (engine seat A); vid != this on BattleEnemy
|
|
/// (seat B).</summary>
|
|
private const long SelfSeatVid = EngineGlobalInit.ThisViewerId;
|
|
|
|
/// <summary>A viewer id distinct from <see cref="SelfSeatVid"/>, stamped when the target sits on the
|
|
/// engine's ENEMY seat (so the recovery parse marks it isSelf=true → BattleEnemy).</summary>
|
|
private const long EnemySeatVid = EngineGlobalInit.ThisViewerId + 1;
|
|
|
|
/// <summary>Build a PlayActions ATTACK frame. <paramref name="attackerIdx"/> is the attacker's in-play
|
|
/// engine <c>Index</c> (the wire <c>playIdx</c>); the target is described in <c>targetList</c> as
|
|
/// <c>{targetIdx, vid, selectSkillIndex}</c>.
|
|
/// <para>The dispatch reads <c>(_isPlayer ? PlayerTargetDataList : OpponentTargetDataList)</c>
|
|
/// (WatchOperationCollection.InPlayActionOperation), and the <c>targetList</c> key populates the seat's
|
|
/// list matching the ingest's <c>isPlayer</c> — so a seat-A (<c>isPlayer:true</c>) attack correctly fills
|
|
/// <c>PlayerTargetDataList</c>. The target's OWNER is then resolved by
|
|
/// <c>NetworkBattleGenericTool.LookForActionDataToTargetCard</c> with fixed-seat semantics:
|
|
/// <c>isSelf == false</c> → <c>BattlePlayer</c> (engine seat A); <c>isSelf == true</c> → <c>BattleEnemy</c>
|
|
/// (engine seat B). Under IsRecovery, <c>isSelf</c> is computed from <c>vid</c> (see
|
|
/// <see cref="EnemySeatVid"/>), so <paramref name="targetOnEnemySeat"/> selects the vid stamp.</para>
|
|
/// <para>For a seat-A attack on seat B's leader: <c>targetIdx = 0</c> (the leader/Class card is Index 0)
|
|
/// and <c>targetOnEnemySeat = true</c>.</para></summary>
|
|
public static Dictionary<string, object?> AttackBody(int attackerIdx, int targetIdx, bool targetOnEnemySeat) => new()
|
|
{
|
|
["playIdx"] = attackerIdx,
|
|
["type"] = AttackOpcode,
|
|
["targetList"] = new List<object?>
|
|
{
|
|
new Dictionary<string, object?>
|
|
{
|
|
["targetIdx"] = (long)targetIdx,
|
|
["vid"] = targetOnEnemySeat ? EnemySeatVid : SelfSeatVid,
|
|
["selectSkillIndex"] = new List<object?>(),
|
|
},
|
|
},
|
|
};
|
|
|
|
/// <summary>The engine's <c>NetworkBattleDefine.PlayActionType.PLAY_HAND_SELECT</c> opcode — confirmed
|
|
/// <c>= 31</c> in <c>SVSim.BattleEngine/Engine/NetworkBattleDefine.cs</c>. A TARGETED hand play (a
|
|
/// when_play spell/fanfare that selects a target) carries this opcode (the "_SELECT" suffix), as
|
|
/// opposed to the plain <c>PLAY_HAND = 30</c> a vanilla play uses. The recovery receive path branches
|
|
/// on it to <c>RecoveryOperationCollection.PlaySkillSelectHandCardOperation</c> →
|
|
/// <c>PlayHandCardReflection.PlayAction</c>, which resolves the target from <c>targetList</c> via
|
|
/// <c>NetworkBattleGenericTool.LookForActionDataToTargetCard</c> (seat A) before applying the skill.</summary>
|
|
public const int PlayHandSelectOpcode = 31;
|
|
|
|
/// <summary>Build a PlayActions PLAY_HAND_SELECT (targeted hand-play) frame. <paramref name="playIdx"/>
|
|
/// is the played hand card's engine <c>Index</c> (the wire <c>playIdx</c>); the single target is
|
|
/// described in <c>targetList</c> in the SAME <c>{targetIdx, vid, selectSkillIndex}</c> shape as
|
|
/// <see cref="AttackBody"/>/<see cref="EvolveSelectBody"/> (the receive parse reads it identically —
|
|
/// <c>CreateTargetList</c> in NetworkBattleReceiver.cs:2164 — into the seat's TargetDataList, and under
|
|
/// IsRecovery resolves the target's owner from <c>vid</c>, not an isSelf key).
|
|
/// <para>For a seat-A spell targeting an enemy follower: <paramref name="targetIdx"/> = the enemy
|
|
/// follower's in-play engine Index and <paramref name="targetOnEnemySeat"/> = <c>true</c> (vid stamped
|
|
/// <see cref="EnemySeatVid"/> → isSelf=true → <c>LookForActionDataToTargetCard</c> resolves it on
|
|
/// <c>BattleEnemy.ClassAndInPlayCardList</c>).</para></summary>
|
|
public static Dictionary<string, object?> TargetedPlayBody(int playIdx, int targetIdx, bool targetOnEnemySeat) => new()
|
|
{
|
|
["playIdx"] = playIdx,
|
|
["type"] = PlayHandSelectOpcode,
|
|
["targetList"] = new List<object?>
|
|
{
|
|
new Dictionary<string, object?>
|
|
{
|
|
["targetIdx"] = (long)targetIdx,
|
|
["vid"] = targetOnEnemySeat ? EnemySeatVid : SelfSeatVid,
|
|
["selectSkillIndex"] = new List<object?>(),
|
|
},
|
|
},
|
|
};
|
|
|
|
/// <summary>Build a PlayActions CHOICE hand-play frame. A choice play carries the plain
|
|
/// <c>PLAY_HAND = 30</c> opcode plus a <c>keyAction</c> list that the receiver parses
|
|
/// (NetworkBattleReceiver.cs:1176-1228) into <c>keyActionType=Choice</c> (→ <c>ReceiveData.IsChoice</c>)
|
|
/// and <c>choiceIdList</c> = the chosen token id(s). Each entry is
|
|
/// <c>{ type:"Choice", cardId:<played card id>, selectCard:[<tokenId>] }</c>. The receiver reads
|
|
/// <c>selectCard</c> via <c>ConvertToListInt</c> (NetworkBattleReceiver.cs:1202), i.e. it consumes a
|
|
/// FLAT list of the chosen token id(s). (The verbatim CLIENT-SEND capture of THIS card —
|
|
/// <c>data_dumps/captures/battle_test/rng/battle-traffic_cl1.ndjson</c> — wraps it as
|
|
/// <c>selectCard:{cardId:[121011010],open:0}</c>; that wrapper is unwrapped before the node's
|
|
/// server-authored receive frame, which is what the receiver — and this driver — consume.)
|
|
/// <paramref name="playIdx"/> is the choice card's hand engine <c>Index</c>; <paramref name="playedCardId"/>
|
|
/// its wire id; <paramref name="chosenTokenId"/> the selected option.</summary>
|
|
public static Dictionary<string, object?> ChoicePlayBody(int playIdx, long playedCardId, long chosenTokenId) => new()
|
|
{
|
|
["playIdx"] = playIdx,
|
|
["type"] = 30, // PLAY_HAND — choice is signalled via keyAction, not a distinct opcode
|
|
["keyAction"] = new List<object?>
|
|
{
|
|
new Dictionary<string, object?>
|
|
{
|
|
// The real capture sends type:1 (int); "Choice" (string) is equivalent — the receiver does
|
|
// Enum.Parse(KeyActionType, type.ToString()) and KeyActionType.Choice == 1, so the string and
|
|
// the int both parse to the same enum value.
|
|
["type"] = "Choice",
|
|
["cardId"] = playedCardId,
|
|
// The RECEIVE parse reads selectCard via ConvertToListInt (NetworkBattleReceiver.cs:1202),
|
|
// i.e. a FLAT list of the chosen token id(s). (The verbatim CLIENT-SEND capture wraps it as
|
|
// {cardId:[...],open:0}, but that wrapper is unwrapped before the node's server-authored
|
|
// receive frame; the receiver consumes the flat list.)
|
|
["selectCard"] = new List<object?> { chosenTokenId },
|
|
},
|
|
},
|
|
};
|
|
|
|
/// <summary>The engine's <c>NetworkBattleDefine.PlayActionType.EVOLUTION</c> opcode — confirmed
|
|
/// <c>= 20</c> in <c>SVSim.BattleEngine/Engine/NetworkBattleDefine.cs</c> (EVOLUTION_SELECT is 21). The
|
|
/// receiver maps the wire <c>type</c> int straight to the enum; EVOLUTION/EVOLUTION_SELECT route through
|
|
/// the SAME InPlayAction dispatch arm as ATTACK (NetworkOperationCollection.cs:163-170).</summary>
|
|
public const int EvolutionOpcode = 20;
|
|
|
|
/// <summary>The engine's <c>NetworkBattleDefine.PlayActionType.EVOLUTION_SELECT</c> opcode — confirmed
|
|
/// <c>= 21</c> in <c>SVSim.BattleEngine/Engine/NetworkBattleDefine.cs</c>.</summary>
|
|
public const int EvolutionSelectOpcode = 21;
|
|
|
|
/// <summary>Build a PlayActions EVOLUTION frame for the in-play follower addressed by its engine
|
|
/// <c>Index</c> (<paramref name="cardIdx"/> == the wire <c>playIdx</c>). A plain (non-targeted) evolve
|
|
/// carries no targetList — the dispatch's <c>list</c> stays empty and the engine evolves the card in
|
|
/// place (InPlayCardReflection.Evol).</summary>
|
|
public static Dictionary<string, object?> EvolveBody(int cardIdx) => new()
|
|
{
|
|
["playIdx"] = cardIdx,
|
|
["type"] = EvolutionOpcode,
|
|
};
|
|
|
|
/// <summary>Build a PlayActions EVOLUTION_SELECT frame: the follower at engine <c>Index</c>
|
|
/// <paramref name="cardIdx"/> evolves and targets the card at <paramref name="targetIdx"/>. The target is
|
|
/// described in the SAME <c>{targetIdx, vid, selectSkillIndex}</c> shape as <see cref="AttackBody"/>
|
|
/// (the dispatch resolves the target's owner from <c>vid</c> under IsRecovery, not from an isSelf key);
|
|
/// <paramref name="targetOnEnemySeat"/> selects the vid stamp.</summary>
|
|
public static Dictionary<string, object?> EvolveSelectBody(int cardIdx, int targetIdx, bool targetOnEnemySeat) => new()
|
|
{
|
|
["playIdx"] = cardIdx,
|
|
["type"] = EvolutionSelectOpcode,
|
|
["targetList"] = new List<object?>
|
|
{
|
|
new Dictionary<string, object?>
|
|
{
|
|
["targetIdx"] = (long)targetIdx,
|
|
["vid"] = targetOnEnemySeat ? EnemySeatVid : SelfSeatVid,
|
|
["selectSkillIndex"] = new List<object?>(),
|
|
},
|
|
},
|
|
};
|
|
|
|
public void Dispose() { /* engine holds no unmanaged resources; nothing to release. */ }
|
|
|
|
/// <summary>Minimal test-only <see cref="IBattleParticipant"/> exposing only the
|
|
/// <see cref="ViewerId"/> + <see cref="Context"/> that the harness reads. Broker members
|
|
/// (<c>PushAsync</c>, <c>RunAsync</c>, <c>TerminateAsync</c>) throw <see cref="NotSupportedException"/>
|
|
/// — the harness drives the engine directly, so a frame must never reach the participant relay.
|
|
/// Silent no-ops would let a misrouted push pass undetected.</summary>
|
|
internal sealed class StubParticipant : IBattleParticipant, IHasHandshakePhase
|
|
{
|
|
public long ViewerId { get; }
|
|
public MatchContext Context { get; }
|
|
|
|
/// <summary>Handshake cursor (M-HC-3a handler-emit test). Implementing
|
|
/// <see cref="IHasHandshakePhase"/> lets a test build a <c>FrameDispatchContext</c> over two
|
|
/// StubParticipants and advance both to <see cref="HandshakePhase.AfterReady"/> so
|
|
/// <c>BothSidesAfterReady()</c> passes (the PvP relay gate). Harness tests that drive the engine
|
|
/// directly never read this; it defaults to the pre-handshake state and is harmless to them.</summary>
|
|
public HandshakePhase Phase { get; set; } = HandshakePhase.AwaitingInitNetwork;
|
|
|
|
public StubParticipant(long viewerId, MatchContext context)
|
|
{
|
|
ViewerId = viewerId;
|
|
Context = context;
|
|
}
|
|
|
|
#pragma warning disable CS0067 // FrameEmitted is part of the interface but the stub never raises it.
|
|
public event Func<MsgEnvelope, CancellationToken, Task>? FrameEmitted;
|
|
#pragma warning restore CS0067
|
|
|
|
public Task PushAsync(MsgEnvelope envelope, Stock stock, CancellationToken ct) =>
|
|
throw new NotSupportedException("StubParticipant.PushAsync — harness drives the engine directly; a frame must not reach the participant relay.");
|
|
public Task RunAsync(CancellationToken ct) =>
|
|
throw new NotSupportedException("StubParticipant.RunAsync should not be called in harness tests.");
|
|
public Task TerminateAsync(BattleFinishReason reason) =>
|
|
throw new NotSupportedException("StubParticipant.TerminateAsync should not be called in harness tests.");
|
|
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
|
|
}
|
|
}
|