refactor(battle-node): rename ScriptedLifecycle->ServerBattleFrames, ScriptedProfiles->BattleFrameDefaults

Pure rename. These hold the shared server-authored frame builders used by every
battle mode's handshake/mulligan dispatch — the 'Scripted' name was a historical
accident that hid the PvP/Bot crossover. No behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-03 20:36:32 -04:00
parent e9493e24c4
commit ba18790156
14 changed files with 59 additions and 59 deletions

View File

@@ -1,13 +1,13 @@
namespace SVSim.BattleNode.Lifecycle; namespace SVSim.BattleNode.Lifecycle;
/// <summary> /// <summary>
/// Named constants and templates for the v1 scripted lifecycle. Every value here /// Default frame constants templated from TK2 prod captures, shared by the
/// originated in a real prod frame in /// server-authored battle-frame builders. Every value here originated in a real prod
/// <c>data_dumps/captures/battle-traffic_tk2_regular.ndjson</c>; pulling them out /// frame in <c>data_dumps/captures/battle-traffic_tk2_regular.ndjson</c>; pulling them
/// of <see cref="ScriptedLifecycle"/> makes the magic numerics navigable and gives /// out of <see cref="ServerBattleFrames"/> makes the magic numerics navigable and gives
/// the seed a single source of truth instead of two duplicated literals. /// the seed a single source of truth instead of two duplicated literals.
/// </summary> /// </summary>
internal static class ScriptedProfiles internal static class BattleFrameDefaults
{ {
// Shared per the spec — selfInfo.seed and oppoInfo.seed always agree. // Shared per the spec — selfInfo.seed and oppoInfo.seed always agree.
// From frame[2] (Matched). // From frame[2] (Matched).

View File

@@ -10,13 +10,13 @@ namespace SVSim.BattleNode.Lifecycle;
/// (Matched / BattleStart / Deal / Swap response / Ready) plus the post-mulligan hand /// (Matched / BattleStart / Deal / Swap response / Ready) plus the post-mulligan hand
/// computation. Used by every battle mode's handshake/mulligan dispatch arms. Hardcoded /// computation. Used by every battle mode's handshake/mulligan dispatch arms. Hardcoded
/// values are templated from the TK2 prod captures (battle-traffic_tk2_*.ndjson); see /// values are templated from the TK2 prod captures (battle-traffic_tk2_*.ndjson); see
/// <see cref="ScriptedProfiles"/> for provenance. /// <see cref="BattleFrameDefaults"/> for provenance.
/// </summary> /// </summary>
public static class ScriptedLifecycle public static class ServerBattleFrames
{ {
/// <summary> /// <summary>
/// Viewer id we present as the opponent on every scripted push. Out-of-range vs. real /// Viewer id we present as the opponent on every server-authored opponent push. Out-of-range
/// viewer ids so it can't collide with a real account in the auth pipeline. /// vs. real viewer ids so it can't collide with a real account in the auth pipeline.
/// </summary> /// </summary>
public const long FakeOpponentViewerId = 999_999_999L; public const long FakeOpponentViewerId = 999_999_999L;
@@ -57,8 +57,8 @@ public static class ScriptedLifecycle
TurnState: turnState, // 0 = this side goes first, 1 = second. Caller decides. TurnState: turnState, // 0 = this side goes first, 1 = second. Caller decides.
BattleType: selfCtx.BattleType, BattleType: selfCtx.BattleType,
SelfInfo: new BattleStartSelfInfo( SelfInfo: new BattleStartSelfInfo(
Rank: ScriptedProfiles.PlayerRank, Rank: BattleFrameDefaults.PlayerRank,
BattlePoint: ScriptedProfiles.PlayerBattlePoint, BattlePoint: BattleFrameDefaults.PlayerBattlePoint,
ClassId: selfCtx.ClassId, ClassId: selfCtx.ClassId,
CharaId: selfCtx.CharaId, CharaId: selfCtx.CharaId,
CardMasterName: selfCtx.CardMasterName), CardMasterName: selfCtx.CardMasterName),
@@ -111,8 +111,8 @@ public static class ScriptedLifecycle
EnvelopeForPush(NetworkBattleUri.Swap, EnvelopeForPush(NetworkBattleUri.Swap,
new SwapResponseBody(Self: BuildPosIdxList(hand))); new SwapResponseBody(Self: BuildPosIdxList(hand)));
/// <summary>Non-interactive opponent (scripted single / AINetwork): oppo is the /// <summary>Non-interactive opponent (Bot/AI): oppo is the placeholder
/// placeholder <see cref="InitialHand"/> (v1 behaviour).</summary> /// <see cref="InitialHand"/>.</summary>
public static MsgEnvelope BuildReady(IReadOnlyList<long> hand) => BuildReady(hand, InitialHand); public static MsgEnvelope BuildReady(IReadOnlyList<long> hand) => BuildReady(hand, InitialHand);
/// <summary>Both hands known (the mulligan barrier supplies the opponent's /// <summary>Both hands known (the mulligan barrier supplies the opponent's
@@ -122,8 +122,8 @@ public static class ScriptedLifecycle
new ReadyBody( new ReadyBody(
Self: BuildPosIdxList(selfHand), Self: BuildPosIdxList(selfHand),
Oppo: BuildPosIdxList(oppoHand), Oppo: BuildPosIdxList(oppoHand),
IdxChangeSeed: ScriptedProfiles.ReadyIdxChangeSeed, IdxChangeSeed: BattleFrameDefaults.ReadyIdxChangeSeed,
Spin: ScriptedProfiles.ReadySpin)); Spin: BattleFrameDefaults.ReadySpin));
private static IReadOnlyList<PosIdx> BuildPosIdxList(IReadOnlyList<long> hand) private static IReadOnlyList<PosIdx> BuildPosIdxList(IReadOnlyList<long> hand)
{ {

View File

@@ -10,7 +10,7 @@ internal static class BattleFrames
{ {
internal static MsgEnvelope BuildAck(NetworkBattleUri uri) => new( internal static MsgEnvelope BuildAck(NetworkBattleUri uri) => new(
uri, uri,
ViewerId: ScriptedLifecycle.FakeOpponentViewerId, ViewerId: ServerBattleFrames.FakeOpponentViewerId,
Uuid: WireConstants.ServerUuid, Uuid: WireConstants.ServerUuid,
Bid: null, Bid: null,
Try: 0, Try: 0,
@@ -21,7 +21,7 @@ internal static class BattleFrames
internal static MsgEnvelope BuildTurnEndBroadcast() => new( internal static MsgEnvelope BuildTurnEndBroadcast() => new(
NetworkBattleUri.TurnEnd, NetworkBattleUri.TurnEnd,
ViewerId: ScriptedLifecycle.FakeOpponentViewerId, ViewerId: ServerBattleFrames.FakeOpponentViewerId,
Uuid: WireConstants.ServerUuid, Uuid: WireConstants.ServerUuid,
Bid: null, Bid: null,
Try: 0, Try: 0,
@@ -32,18 +32,18 @@ internal static class BattleFrames
internal static MsgEnvelope BuildJudgeBroadcast() => new( internal static MsgEnvelope BuildJudgeBroadcast() => new(
NetworkBattleUri.Judge, NetworkBattleUri.Judge,
ViewerId: ScriptedLifecycle.FakeOpponentViewerId, ViewerId: ServerBattleFrames.FakeOpponentViewerId,
Uuid: WireConstants.ServerUuid, Uuid: WireConstants.ServerUuid,
Bid: null, Bid: null,
Try: 0, Try: 0,
Cat: EmitCategory.Battle, Cat: EmitCategory.Battle,
PubSeq: null, PubSeq: null,
PlaySeq: null, PlaySeq: null,
Body: new JudgeBody(Spin: ScriptedProfiles.OpponentJudgeSpin)); Body: new JudgeBody(Spin: BattleFrameDefaults.OpponentJudgeSpin));
internal static MsgEnvelope BuildBattleFinish(BattleResult result) => new( internal static MsgEnvelope BuildBattleFinish(BattleResult result) => new(
NetworkBattleUri.BattleFinish, NetworkBattleUri.BattleFinish,
ViewerId: ScriptedLifecycle.FakeOpponentViewerId, ViewerId: ServerBattleFrames.FakeOpponentViewerId,
Uuid: WireConstants.ServerUuid, Uuid: WireConstants.ServerUuid,
Bid: null, Bid: null,
Try: 0, Try: 0,

View File

@@ -23,9 +23,9 @@ internal sealed class InitBattleHandler : IFrameHandler
{ {
var r = new List<DispatchRoute> var r = new List<DispatchRoute>
{ {
new(ctx.From, ScriptedLifecycle.BuildMatched( new(ctx.From, ServerBattleFrames.BuildMatched(
ctx.From.Context, ctx.Other.Context, ctx.From.ViewerId, ctx.Other.ViewerId, ctx.From.Context, ctx.Other.Context, ctx.From.ViewerId, ctx.Other.ViewerId,
ctx.BattleId, ScriptedProfiles.BattleSeed), false), ctx.BattleId, BattleFrameDefaults.BattleSeed), false),
}; };
ctx.SenderPhase = BattleSessionPhase.AwaitingLoaded; ctx.SenderPhase = BattleSessionPhase.AwaitingLoaded;
return r; return r;

View File

@@ -21,9 +21,9 @@ internal sealed class LoadedHandler : IFrameHandler
var turnState = ReferenceEquals(ctx.From, ctx.A) ? 0 : 1; var turnState = ReferenceEquals(ctx.From, ctx.A) ? 0 : 1;
var r = new List<DispatchRoute> var r = new List<DispatchRoute>
{ {
new(ctx.From, ScriptedLifecycle.BuildBattleStart( new(ctx.From, ServerBattleFrames.BuildBattleStart(
ctx.From.Context, ctx.Other.Context, ctx.From.ViewerId, turnState), false), ctx.From.Context, ctx.Other.Context, ctx.From.ViewerId, turnState), false),
new(ctx.From, ScriptedLifecycle.BuildDeal(), false), new(ctx.From, ServerBattleFrames.BuildDeal(), false),
}; };
ctx.SenderPhase = BattleSessionPhase.AwaitingSwap; ctx.SenderPhase = BattleSessionPhase.AwaitingSwap;
return r; return r;

View File

@@ -12,10 +12,10 @@ internal sealed class SwapHandler : IFrameHandler
return Array.Empty<DispatchRoute>(); return Array.Empty<DispatchRoute>();
var routes = new List<DispatchRoute>(); var routes = new List<DispatchRoute>();
var hand = ScriptedLifecycle.ComputeHandAfterSwap(BattleFrames.ExtractIdxList(ctx.Env)); var hand = ServerBattleFrames.ComputeHandAfterSwap(BattleFrames.ExtractIdxList(ctx.Env));
// SwapResponse is always immediate — completes the sender's own mulligan UI. // SwapResponse is always immediate — completes the sender's own mulligan UI.
routes.Add(new DispatchRoute(ctx.From, ScriptedLifecycle.BuildSwapResponse(hand), false)); routes.Add(new DispatchRoute(ctx.From, ServerBattleFrames.BuildSwapResponse(hand), false));
ctx.State.PostSwapHands[ctx.From] = hand; ctx.State.PostSwapHands[ctx.From] = hand;
ctx.SenderPhase = BattleSessionPhase.AfterReady; ctx.SenderPhase = BattleSessionPhase.AfterReady;
@@ -29,8 +29,8 @@ internal sealed class SwapHandler : IFrameHandler
var opponent = ReferenceEquals(p, ctx.A) ? ctx.B : ctx.A; var opponent = ReferenceEquals(p, ctx.A) ? ctx.B : ctx.A;
var ready = opponent is IHasHandshakePhase var ready = opponent is IHasHandshakePhase
&& ctx.State.PostSwapHands.TryGetValue(opponent, out var oppoHand) && ctx.State.PostSwapHands.TryGetValue(opponent, out var oppoHand)
? ScriptedLifecycle.BuildReady(ctx.State.PostSwapHands[p], oppoHand) ? ServerBattleFrames.BuildReady(ctx.State.PostSwapHands[p], oppoHand)
: ScriptedLifecycle.BuildReady(ctx.State.PostSwapHands[p]); : ServerBattleFrames.BuildReady(ctx.State.PostSwapHands[p]);
routes.Add(new DispatchRoute(p, ready, false)); routes.Add(new DispatchRoute(p, ready, false));
} }
} }

View File

@@ -14,7 +14,7 @@ namespace SVSim.BattleNode.Sessions;
public interface IBattleParticipant : IAsyncDisposable public interface IBattleParticipant : IAsyncDisposable
{ {
/// <summary>Real viewer id, or a synthetic stable id for bots /// <summary>Real viewer id, or a synthetic stable id for bots
/// (<see cref="Lifecycle.ScriptedLifecycle.FakeOpponentViewerId"/>).</summary> /// (<see cref="Lifecycle.ServerBattleFrames.FakeOpponentViewerId"/>).</summary>
long ViewerId { get; } long ViewerId { get; }
/// <summary>Per-battle MatchContext snapshot, used for building Matched/BattleStart /// <summary>Per-battle MatchContext snapshot, used for building Matched/BattleStart

View File

@@ -8,13 +8,13 @@ namespace SVSim.BattleNode.Sessions.Participants;
/// Silent participant — produces no frames, swallows everything pushed to it. /// Silent participant — produces no frames, swallows everything pushed to it.
/// Used as the "other" participant in <see cref="BattleType.Bot"/> sessions, where /// Used as the "other" participant in <see cref="BattleType.Bot"/> sessions, where
/// the real opponent runs in the client and the server has no opponent-side state /// the real opponent runs in the client and the server has no opponent-side state
/// to model. ViewerId is <see cref="ScriptedLifecycle.FakeOpponentViewerId"/>; /// to model. ViewerId is <see cref="ServerBattleFrames.FakeOpponentViewerId"/>;
/// Context is a fixed stub (irrelevant — never read because no frames are pushed /// Context is a fixed stub (irrelevant — never read because no frames are pushed
/// to the other side). /// to the other side).
/// </summary> /// </summary>
public sealed class NoOpBotParticipant : IBattleParticipant public sealed class NoOpBotParticipant : IBattleParticipant
{ {
public long ViewerId => ScriptedLifecycle.FakeOpponentViewerId; public long ViewerId => ServerBattleFrames.FakeOpponentViewerId;
public MatchContext Context { get; } = new( public MatchContext Context { get; } = new(
SelfDeckCardIds: Array.Empty<long>(), SelfDeckCardIds: Array.Empty<long>(),
ClassId: "0", CharaId: "0", CardMasterName: "card_master_node_10015", ClassId: "0", CharaId: "0", CardMasterName: "card_master_node_10015",

View File

@@ -369,7 +369,7 @@ public sealed class RealParticipant : IBattleParticipant, IHasHandshakePhase
} }
var aliveEnv = new MsgEnvelope( var aliveEnv = new MsgEnvelope(
Uri: NetworkBattleUri.Gungnir, Uri: NetworkBattleUri.Gungnir,
ViewerId: SVSim.BattleNode.Lifecycle.ScriptedLifecycle.FakeOpponentViewerId, ViewerId: SVSim.BattleNode.Lifecycle.ServerBattleFrames.FakeOpponentViewerId,
Uuid: WireConstants.ServerUuid, Uuid: WireConstants.ServerUuid,
Bid: null, Bid: null,
Try: 0, Try: 0,

View File

@@ -34,7 +34,7 @@ namespace SVSim.UnitTests.BattleNode.Integration;
/// <para><b>Coverage:</b> a two-client PvP session emits all ten server-authored URIs /// <para><b>Coverage:</b> a two-client PvP session emits all ten server-authored URIs
/// (<c>InitNetwork, Matched, BattleStart, Deal, Swap, Ready, TurnStart, TurnEnd, Judge, /// (<c>InitNetwork, Matched, BattleStart, Deal, Swap, Ready, TurnStart, TurnEnd, Judge,
/// BattleFinish</c>). PvP authors the handshake/mulligan frames through the same shared /// BattleFinish</c>). PvP authors the handshake/mulligan frames through the same shared
/// <see cref="SVSim.BattleNode.Lifecycle.ScriptedLifecycle"/> builders, and the turn cycle /// <see cref="SVSim.BattleNode.Lifecycle.ServerBattleFrames"/> builders, and the turn cycle
/// (<c>TurnStart/TurnEnd/Judge</c>) falls out of the real two-client handover. Forwarded frames /// (<c>TurnStart/TurnEnd/Judge</c>) falls out of the real two-client handover. Forwarded frames
/// (<c>PlayActions / TurnEndActions / ChatStamp / TurnEndFinal</c>) relay the /// (<c>PlayActions / TurnEndActions / ChatStamp / TurnEndFinal</c>) relay the
/// client's own bytes verbatim, so their shape is the client's contract, not ours — out of scope /// client's own bytes verbatim, so their shape is the client's contract, not ours — out of scope

View File

@@ -7,14 +7,14 @@ using SVSim.BattleNode.Protocol.Bodies;
namespace SVSim.UnitTests.BattleNode.Lifecycle; namespace SVSim.UnitTests.BattleNode.Lifecycle;
[TestFixture] [TestFixture]
public class ScriptedLifecycleTests public class ServerBattleFramesTests
{ {
[Test] [Test]
public void BuildMatched_PutsOppoIdInSelfInfoEqualToTheRealOpponentVid() public void BuildMatched_PutsOppoIdInSelfInfoEqualToTheRealOpponentVid()
{ {
var env = ScriptedLifecycle.BuildMatched(FixtureCtx(), ScriptedBotCtx(), var env = ServerBattleFrames.BuildMatched(FixtureCtx(), ScriptedBotCtx(),
selfViewerId: 906243102, oppoViewerId: 847666884, selfViewerId: 906243102, oppoViewerId: 847666884,
battleId: "b", seed: ScriptedProfiles.BattleSeed); battleId: "b", seed: BattleFrameDefaults.BattleSeed);
Assert.That(env.Uri, Is.EqualTo(NetworkBattleUri.Matched)); Assert.That(env.Uri, Is.EqualTo(NetworkBattleUri.Matched));
var body = (MatchedBody)env.Body; var body = (MatchedBody)env.Body;
@@ -26,7 +26,7 @@ public class ScriptedLifecycleTests
[Test] [Test]
public void BuildMatched_ContainsThirtyCardSelfDeck() public void BuildMatched_ContainsThirtyCardSelfDeck()
{ {
var env = ScriptedLifecycle.BuildMatched(FixtureCtx(), ScriptedBotCtx(), 1, 2, "b", ScriptedProfiles.BattleSeed); var env = ServerBattleFrames.BuildMatched(FixtureCtx(), ScriptedBotCtx(), 1, 2, "b", BattleFrameDefaults.BattleSeed);
var body = (MatchedBody)env.Body; var body = (MatchedBody)env.Body;
Assert.That(body.SelfDeck.Count, Is.EqualTo(30)); Assert.That(body.SelfDeck.Count, Is.EqualTo(30));
} }
@@ -35,7 +35,7 @@ public class ScriptedLifecycleTests
public void BuildMatched_deck_idxs_pair_1to30_with_context_card_ids() public void BuildMatched_deck_idxs_pair_1to30_with_context_card_ids()
{ {
var draftedDeck = Enumerable.Range(1, 30).Select(i => 200_000_000L + i).ToList(); var draftedDeck = Enumerable.Range(1, 30).Select(i => 200_000_000L + i).ToList();
var env = ScriptedLifecycle.BuildMatched(FixtureCtx(draftedDeck), ScriptedBotCtx(), 1, 2, "b", ScriptedProfiles.BattleSeed); var env = ServerBattleFrames.BuildMatched(FixtureCtx(draftedDeck), ScriptedBotCtx(), 1, 2, "b", BattleFrameDefaults.BattleSeed);
var body = (MatchedBody)env.Body; var body = (MatchedBody)env.Body;
for (int i = 0; i < 30; i++) for (int i = 0; i < 30; i++)
@@ -56,7 +56,7 @@ public class ScriptedLifecycleTests
EmblemId = "888", DegreeId = "777", FieldId = 42, IsOfficial = 1, EmblemId = "888", DegreeId = "777", FieldId = 42, IsOfficial = 1,
}; };
var env = ScriptedLifecycle.BuildMatched(ctx, ScriptedBotCtx(), 1, 2, "b", ScriptedProfiles.BattleSeed); var env = ServerBattleFrames.BuildMatched(ctx, ScriptedBotCtx(), 1, 2, "b", BattleFrameDefaults.BattleSeed);
var body = (MatchedBody)env.Body; var body = (MatchedBody)env.Body;
Assert.That(body.SelfInfo.CountryCode, Is.EqualTo("JPN")); Assert.That(body.SelfInfo.CountryCode, Is.EqualTo("JPN"));
@@ -71,7 +71,7 @@ public class ScriptedLifecycleTests
[Test] [Test]
public void BuildBattleStart_HasTurnStateZero_AndUsesContextBattleType() public void BuildBattleStart_HasTurnStateZero_AndUsesContextBattleType()
{ {
var env = ScriptedLifecycle.BuildBattleStart(FixtureCtx(), ScriptedBotCtx(), selfViewerId: 1, turnState: 0); var env = ServerBattleFrames.BuildBattleStart(FixtureCtx(), ScriptedBotCtx(), selfViewerId: 1, turnState: 0);
var body = (BattleStartBody)env.Body; var body = (BattleStartBody)env.Body;
Assert.That(body.TurnState, Is.EqualTo(0)); Assert.That(body.TurnState, Is.EqualTo(0));
Assert.That(body.BattleType, Is.EqualTo(11)); Assert.That(body.BattleType, Is.EqualTo(11));
@@ -87,7 +87,7 @@ public class ScriptedLifecycleTests
BattleType = 42, BattleType = 42,
}; };
var env = ScriptedLifecycle.BuildBattleStart(ctx, ScriptedBotCtx(), selfViewerId: 1, turnState: 0); var env = ServerBattleFrames.BuildBattleStart(ctx, ScriptedBotCtx(), selfViewerId: 1, turnState: 0);
var body = (BattleStartBody)env.Body; var body = (BattleStartBody)env.Body;
Assert.That(body.SelfInfo.ClassId, Is.EqualTo("7")); Assert.That(body.SelfInfo.ClassId, Is.EqualTo("7"));
@@ -99,7 +99,7 @@ public class ScriptedLifecycleTests
[Test] [Test]
public void BuildDeal_HasThreeSelfAndThreeOppoEntries() public void BuildDeal_HasThreeSelfAndThreeOppoEntries()
{ {
var env = ScriptedLifecycle.BuildDeal(); var env = ServerBattleFrames.BuildDeal();
var body = (DealBody)env.Body; var body = (DealBody)env.Body;
Assert.That(body.Self.Count, Is.EqualTo(3)); Assert.That(body.Self.Count, Is.EqualTo(3));
Assert.That(body.Oppo.Count, Is.EqualTo(3)); Assert.That(body.Oppo.Count, Is.EqualTo(3));
@@ -108,28 +108,28 @@ public class ScriptedLifecycleTests
[Test] [Test]
public void ComputeHandAfterSwap_NoSwap_ReturnsInitialHand() public void ComputeHandAfterSwap_NoSwap_ReturnsInitialHand()
{ {
var hand = ScriptedLifecycle.ComputeHandAfterSwap(Array.Empty<long>()); var hand = ServerBattleFrames.ComputeHandAfterSwap(Array.Empty<long>());
Assert.That(hand, Is.EqualTo(new long[] { 1, 2, 3 })); Assert.That(hand, Is.EqualTo(new long[] { 1, 2, 3 }));
} }
[Test] [Test]
public void ComputeHandAfterSwap_SwapMiddleCard_ReplacesWithFreshDeckIdx() public void ComputeHandAfterSwap_SwapMiddleCard_ReplacesWithFreshDeckIdx()
{ {
var hand = ScriptedLifecycle.ComputeHandAfterSwap(new long[] { 2 }); var hand = ServerBattleFrames.ComputeHandAfterSwap(new long[] { 2 });
Assert.That(hand, Is.EqualTo(new long[] { 1, 4, 3 })); Assert.That(hand, Is.EqualTo(new long[] { 1, 4, 3 }));
} }
[Test] [Test]
public void ComputeHandAfterSwap_SwapAll_ReplacesAllWithFreshDeckIdxs() public void ComputeHandAfterSwap_SwapAll_ReplacesAllWithFreshDeckIdxs()
{ {
var hand = ScriptedLifecycle.ComputeHandAfterSwap(new long[] { 1, 2, 3 }); var hand = ServerBattleFrames.ComputeHandAfterSwap(new long[] { 1, 2, 3 });
Assert.That(hand, Is.EqualTo(new long[] { 4, 5, 6 })); Assert.That(hand, Is.EqualTo(new long[] { 4, 5, 6 }));
} }
[Test] [Test]
public void BuildSwapResponse_RendersGivenHandAsPositions() public void BuildSwapResponse_RendersGivenHandAsPositions()
{ {
var env = ScriptedLifecycle.BuildSwapResponse(new long[] { 1, 4, 3 }); var env = ServerBattleFrames.BuildSwapResponse(new long[] { 1, 4, 3 });
var body = (SwapResponseBody)env.Body; var body = (SwapResponseBody)env.Body;
Assert.That(body.Self.Count, Is.EqualTo(3)); Assert.That(body.Self.Count, Is.EqualTo(3));
Assert.That(body.Self[1].Idx, Is.EqualTo(4)); Assert.That(body.Self[1].Idx, Is.EqualTo(4));
@@ -138,7 +138,7 @@ public class ScriptedLifecycleTests
[Test] [Test]
public void BuildReady_IncludesIdxChangeSeedAndSpin_AndUsesGivenHand() public void BuildReady_IncludesIdxChangeSeedAndSpin_AndUsesGivenHand()
{ {
var env = ScriptedLifecycle.BuildReady(new long[] { 1, 4, 3 }); var env = ServerBattleFrames.BuildReady(new long[] { 1, 4, 3 });
var body = (ReadyBody)env.Body; var body = (ReadyBody)env.Body;
Assert.That(body.IdxChangeSeed, Is.EqualTo(771_335_280)); Assert.That(body.IdxChangeSeed, Is.EqualTo(771_335_280));
Assert.That(body.Spin, Is.EqualTo(243)); Assert.That(body.Spin, Is.EqualTo(243));
@@ -148,7 +148,7 @@ public class ScriptedLifecycleTests
[Test] [Test]
public void BuildReady_two_arg_sets_oppo_to_supplied_hand() public void BuildReady_two_arg_sets_oppo_to_supplied_hand()
{ {
var env = ScriptedLifecycle.BuildReady(new long[] { 1, 4, 3 }, new long[] { 1, 2, 6 }); var env = ServerBattleFrames.BuildReady(new long[] { 1, 4, 3 }, new long[] { 1, 2, 6 });
var body = (ReadyBody)env.Body; var body = (ReadyBody)env.Body;
Assert.That(body.Self.Select(p => p.Idx), Is.EqualTo(new[] { 1, 4, 3 })); Assert.That(body.Self.Select(p => p.Idx), Is.EqualTo(new[] { 1, 4, 3 }));
@@ -159,7 +159,7 @@ public class ScriptedLifecycleTests
[Test] [Test]
public void BuildReady_one_arg_defaults_oppo_to_InitialHand() public void BuildReady_one_arg_defaults_oppo_to_InitialHand()
{ {
var env = ScriptedLifecycle.BuildReady(new long[] { 1, 4, 3 }); var env = ServerBattleFrames.BuildReady(new long[] { 1, 4, 3 });
var body = (ReadyBody)env.Body; var body = (ReadyBody)env.Body;
Assert.That(body.Oppo.Select(p => p.Idx), Is.EqualTo(new[] { 1, 2, 3 }), Assert.That(body.Oppo.Select(p => p.Idx), Is.EqualTo(new[] { 1, 2, 3 }),

View File

@@ -27,8 +27,8 @@ public class TypedBodyWireShapeTests
// Matching.StartBattleLoad reads it back, and GetSelfDeck().Select(...) crashes // Matching.StartBattleLoad reads it back, and GetSelfDeck().Select(...) crashes
// with "Value cannot be null. Parameter name: source". The prod wire format // with "Value cannot be null. Parameter name: source". The prod wire format
// emits envelope keys (uri first) before body keys; we must too. // emits envelope keys (uri first) before body keys; we must too.
var env = ScriptedLifecycle.BuildMatched(FixtureCtx(), ScriptedBotCtx(), var env = ServerBattleFrames.BuildMatched(FixtureCtx(), ScriptedBotCtx(),
selfViewerId: 1, oppoViewerId: 2, battleId: "b", seed: ScriptedProfiles.BattleSeed); selfViewerId: 1, oppoViewerId: 2, battleId: "b", seed: BattleFrameDefaults.BattleSeed);
var json = MsgEnvelope.ToJson(env); var json = MsgEnvelope.ToJson(env);
var uriIdx = json.IndexOf("\"uri\":", StringComparison.Ordinal); var uriIdx = json.IndexOf("\"uri\":", StringComparison.Ordinal);
@@ -45,9 +45,9 @@ public class TypedBodyWireShapeTests
[Test] [Test]
public void BuildMatched_SerializesAllWireKeysExpectedByTheClient() public void BuildMatched_SerializesAllWireKeysExpectedByTheClient()
{ {
var env = ScriptedLifecycle.BuildMatched(FixtureCtx(), ScriptedBotCtx(), var env = ServerBattleFrames.BuildMatched(FixtureCtx(), ScriptedBotCtx(),
selfViewerId: 906243102, oppoViewerId: 847666884, battleId: "597830888107", selfViewerId: 906243102, oppoViewerId: 847666884, battleId: "597830888107",
seed: ScriptedProfiles.BattleSeed); seed: BattleFrameDefaults.BattleSeed);
var json = MsgEnvelope.ToJson(env); var json = MsgEnvelope.ToJson(env);
var node = JsonNode.Parse(json)!.AsObject(); var node = JsonNode.Parse(json)!.AsObject();
@@ -86,7 +86,7 @@ public class TypedBodyWireShapeTests
[Test] [Test]
public void BuildBattleStart_SerializesAllWireKeysAndPreservesBattlePointAsymmetry() public void BuildBattleStart_SerializesAllWireKeysAndPreservesBattlePointAsymmetry()
{ {
var env = ScriptedLifecycle.BuildBattleStart(FixtureCtx(), ScriptedBotCtx(), selfViewerId: 906243102, turnState: 0); var env = ServerBattleFrames.BuildBattleStart(FixtureCtx(), ScriptedBotCtx(), selfViewerId: 906243102, turnState: 0);
var json = MsgEnvelope.ToJson(env); var json = MsgEnvelope.ToJson(env);
var node = JsonNode.Parse(json)!.AsObject(); var node = JsonNode.Parse(json)!.AsObject();
@@ -109,7 +109,7 @@ public class TypedBodyWireShapeTests
[Test] [Test]
public void BuildDeal_SerializesSelfAndOppoArraysWithPosIdxShape() public void BuildDeal_SerializesSelfAndOppoArraysWithPosIdxShape()
{ {
var env = ScriptedLifecycle.BuildDeal(); var env = ServerBattleFrames.BuildDeal();
var json = MsgEnvelope.ToJson(env); var json = MsgEnvelope.ToJson(env);
var node = JsonNode.Parse(json)!.AsObject(); var node = JsonNode.Parse(json)!.AsObject();
@@ -125,7 +125,7 @@ public class TypedBodyWireShapeTests
[Test] [Test]
public void BuildSwapResponse_SerializesSelfWithoutOppo() public void BuildSwapResponse_SerializesSelfWithoutOppo()
{ {
var env = ScriptedLifecycle.BuildSwapResponse(new long[] { 1, 4, 3 }); var env = ServerBattleFrames.BuildSwapResponse(new long[] { 1, 4, 3 });
var json = MsgEnvelope.ToJson(env); var json = MsgEnvelope.ToJson(env);
var node = JsonNode.Parse(json)!.AsObject(); var node = JsonNode.Parse(json)!.AsObject();
@@ -137,7 +137,7 @@ public class TypedBodyWireShapeTests
[Test] [Test]
public void BuildReady_SerializesAllFieldsIncludingSeedAndSpin() public void BuildReady_SerializesAllFieldsIncludingSeedAndSpin()
{ {
var env = ScriptedLifecycle.BuildReady(new long[] { 1, 4, 3 }); var env = ServerBattleFrames.BuildReady(new long[] { 1, 4, 3 });
var json = MsgEnvelope.ToJson(env); var json = MsgEnvelope.ToJson(env);
var node = JsonNode.Parse(json)!.AsObject(); var node = JsonNode.Parse(json)!.AsObject();

View File

@@ -412,7 +412,7 @@ public class BattleSessionDispatchTests
private static (BattleSession, FakeRealParticipant, FakeParticipant) NewBotSession() private static (BattleSession, FakeRealParticipant, FakeParticipant) NewBotSession()
{ {
var a = new FakeRealParticipant(viewerId: 1001, PlayerACtx()); var a = new FakeRealParticipant(viewerId: 1001, PlayerACtx());
var b = new FakeParticipant(viewerId: ScriptedLifecycle.FakeOpponentViewerId, NoOpBotContext()); var b = new FakeParticipant(viewerId: ServerBattleFrames.FakeOpponentViewerId, NoOpBotContext());
var s = new BattleSession("bid-bot-1", BattleType.Bot, a, b, NullLogger<BattleSession>.Instance); var s = new BattleSession("bid-bot-1", BattleType.Bot, a, b, NullLogger<BattleSession>.Instance);
return (s, a, b); return (s, a, b);
} }

View File

@@ -39,6 +39,6 @@ public class NoOpBotParticipantTests
public void ViewerId_is_FakeOpponent() public void ViewerId_is_FakeOpponent()
{ {
var p = new NoOpBotParticipant(); var p = new NoOpBotParticipant();
Assert.That(p.ViewerId, Is.EqualTo(SVSim.BattleNode.Lifecycle.ScriptedLifecycle.FakeOpponentViewerId)); Assert.That(p.ViewerId, Is.EqualTo(SVSim.BattleNode.Lifecycle.ServerBattleFrames.FakeOpponentViewerId));
} }
} }