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;
/// <summary>
/// Named constants and templates for the v1 scripted lifecycle. Every value here
/// originated in a real prod frame in
/// <c>data_dumps/captures/battle-traffic_tk2_regular.ndjson</c>; pulling them out
/// of <see cref="ScriptedLifecycle"/> makes the magic numerics navigable and gives
/// Default frame constants templated from TK2 prod captures, shared by the
/// server-authored battle-frame builders. Every value here originated in a real prod
/// frame in <c>data_dumps/captures/battle-traffic_tk2_regular.ndjson</c>; pulling them
/// out of <see cref="ServerBattleFrames"/> makes the magic numerics navigable and gives
/// the seed a single source of truth instead of two duplicated literals.
/// </summary>
internal static class ScriptedProfiles
internal static class BattleFrameDefaults
{
// Shared per the spec — selfInfo.seed and oppoInfo.seed always agree.
// 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
/// 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
/// <see cref="ScriptedProfiles"/> for provenance.
/// <see cref="BattleFrameDefaults"/> for provenance.
/// </summary>
public static class ScriptedLifecycle
public static class ServerBattleFrames
{
/// <summary>
/// Viewer id we present as the opponent on every scripted push. Out-of-range vs. real
/// viewer ids so it can't collide with a real account in the auth pipeline.
/// Viewer id we present as the opponent on every server-authored opponent push. Out-of-range
/// vs. real viewer ids so it can't collide with a real account in the auth pipeline.
/// </summary>
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.
BattleType: selfCtx.BattleType,
SelfInfo: new BattleStartSelfInfo(
Rank: ScriptedProfiles.PlayerRank,
BattlePoint: ScriptedProfiles.PlayerBattlePoint,
Rank: BattleFrameDefaults.PlayerRank,
BattlePoint: BattleFrameDefaults.PlayerBattlePoint,
ClassId: selfCtx.ClassId,
CharaId: selfCtx.CharaId,
CardMasterName: selfCtx.CardMasterName),
@@ -111,8 +111,8 @@ public static class ScriptedLifecycle
EnvelopeForPush(NetworkBattleUri.Swap,
new SwapResponseBody(Self: BuildPosIdxList(hand)));
/// <summary>Non-interactive opponent (scripted single / AINetwork): oppo is the
/// placeholder <see cref="InitialHand"/> (v1 behaviour).</summary>
/// <summary>Non-interactive opponent (Bot/AI): oppo is the placeholder
/// <see cref="InitialHand"/>.</summary>
public static MsgEnvelope BuildReady(IReadOnlyList<long> hand) => BuildReady(hand, InitialHand);
/// <summary>Both hands known (the mulligan barrier supplies the opponent's
@@ -122,8 +122,8 @@ public static class ScriptedLifecycle
new ReadyBody(
Self: BuildPosIdxList(selfHand),
Oppo: BuildPosIdxList(oppoHand),
IdxChangeSeed: ScriptedProfiles.ReadyIdxChangeSeed,
Spin: ScriptedProfiles.ReadySpin));
IdxChangeSeed: BattleFrameDefaults.ReadyIdxChangeSeed,
Spin: BattleFrameDefaults.ReadySpin));
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(
uri,
ViewerId: ScriptedLifecycle.FakeOpponentViewerId,
ViewerId: ServerBattleFrames.FakeOpponentViewerId,
Uuid: WireConstants.ServerUuid,
Bid: null,
Try: 0,
@@ -21,7 +21,7 @@ internal static class BattleFrames
internal static MsgEnvelope BuildTurnEndBroadcast() => new(
NetworkBattleUri.TurnEnd,
ViewerId: ScriptedLifecycle.FakeOpponentViewerId,
ViewerId: ServerBattleFrames.FakeOpponentViewerId,
Uuid: WireConstants.ServerUuid,
Bid: null,
Try: 0,
@@ -32,18 +32,18 @@ internal static class BattleFrames
internal static MsgEnvelope BuildJudgeBroadcast() => new(
NetworkBattleUri.Judge,
ViewerId: ScriptedLifecycle.FakeOpponentViewerId,
ViewerId: ServerBattleFrames.FakeOpponentViewerId,
Uuid: WireConstants.ServerUuid,
Bid: null,
Try: 0,
Cat: EmitCategory.Battle,
PubSeq: null,
PlaySeq: null,
Body: new JudgeBody(Spin: ScriptedProfiles.OpponentJudgeSpin));
Body: new JudgeBody(Spin: BattleFrameDefaults.OpponentJudgeSpin));
internal static MsgEnvelope BuildBattleFinish(BattleResult result) => new(
NetworkBattleUri.BattleFinish,
ViewerId: ScriptedLifecycle.FakeOpponentViewerId,
ViewerId: ServerBattleFrames.FakeOpponentViewerId,
Uuid: WireConstants.ServerUuid,
Bid: null,
Try: 0,

View File

@@ -23,9 +23,9 @@ internal sealed class InitBattleHandler : IFrameHandler
{
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.BattleId, ScriptedProfiles.BattleSeed), false),
ctx.BattleId, BattleFrameDefaults.BattleSeed), false),
};
ctx.SenderPhase = BattleSessionPhase.AwaitingLoaded;
return r;

View File

@@ -21,9 +21,9 @@ internal sealed class LoadedHandler : IFrameHandler
var turnState = ReferenceEquals(ctx.From, ctx.A) ? 0 : 1;
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),
new(ctx.From, ScriptedLifecycle.BuildDeal(), false),
new(ctx.From, ServerBattleFrames.BuildDeal(), false),
};
ctx.SenderPhase = BattleSessionPhase.AwaitingSwap;
return r;

View File

@@ -12,10 +12,10 @@ internal sealed class SwapHandler : IFrameHandler
return Array.Empty<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.
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.SenderPhase = BattleSessionPhase.AfterReady;
@@ -29,8 +29,8 @@ internal sealed class SwapHandler : IFrameHandler
var opponent = ReferenceEquals(p, ctx.A) ? ctx.B : ctx.A;
var ready = opponent is IHasHandshakePhase
&& ctx.State.PostSwapHands.TryGetValue(opponent, out var oppoHand)
? ScriptedLifecycle.BuildReady(ctx.State.PostSwapHands[p], oppoHand)
: ScriptedLifecycle.BuildReady(ctx.State.PostSwapHands[p]);
? ServerBattleFrames.BuildReady(ctx.State.PostSwapHands[p], oppoHand)
: ServerBattleFrames.BuildReady(ctx.State.PostSwapHands[p]);
routes.Add(new DispatchRoute(p, ready, false));
}
}

View File

@@ -14,7 +14,7 @@ namespace SVSim.BattleNode.Sessions;
public interface IBattleParticipant : IAsyncDisposable
{
/// <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; }
/// <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.
/// 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
/// 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
/// to the other side).
/// </summary>
public sealed class NoOpBotParticipant : IBattleParticipant
{
public long ViewerId => ScriptedLifecycle.FakeOpponentViewerId;
public long ViewerId => ServerBattleFrames.FakeOpponentViewerId;
public MatchContext Context { get; } = new(
SelfDeckCardIds: Array.Empty<long>(),
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(
Uri: NetworkBattleUri.Gungnir,
ViewerId: SVSim.BattleNode.Lifecycle.ScriptedLifecycle.FakeOpponentViewerId,
ViewerId: SVSim.BattleNode.Lifecycle.ServerBattleFrames.FakeOpponentViewerId,
Uuid: WireConstants.ServerUuid,
Bid: null,
Try: 0,