fix(battle-node): assign turnState per side instead of hardcoding 0
Both PvP clients received turnState:0 ('both go first'). BuildBattleStart
now takes turnState; the Loaded arm assigns 0 to A, 1 to B — no Type check,
correct in Scripted (real player = A = first) and PvP (first arriver first).
Updated three existing BuildBattleStart callers in the test suite to pass
turnState:0 (the param is now required).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -71,7 +71,7 @@ public class ScriptedLifecycleTests
|
||||
[Test]
|
||||
public void BuildBattleStart_HasTurnStateZero_AndUsesContextBattleType()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildBattleStart(FixtureCtx(), ScriptedBotCtx(), selfViewerId: 1);
|
||||
var env = ScriptedLifecycle.BuildBattleStart(FixtureCtx(), ScriptedBotCtx(), selfViewerId: 1, turnState: 0);
|
||||
var body = (BattleStartBody)env.Body;
|
||||
Assert.That(body.TurnState, Is.EqualTo(0));
|
||||
Assert.That(body.BattleType, Is.EqualTo(11));
|
||||
@@ -87,7 +87,7 @@ public class ScriptedLifecycleTests
|
||||
BattleType = 42,
|
||||
};
|
||||
|
||||
var env = ScriptedLifecycle.BuildBattleStart(ctx, ScriptedBotCtx(), selfViewerId: 1);
|
||||
var env = ScriptedLifecycle.BuildBattleStart(ctx, ScriptedBotCtx(), selfViewerId: 1, turnState: 0);
|
||||
var body = (BattleStartBody)env.Body;
|
||||
|
||||
Assert.That(body.SelfInfo.ClassId, Is.EqualTo("7"));
|
||||
|
||||
@@ -86,7 +86,7 @@ public class TypedBodyWireShapeTests
|
||||
[Test]
|
||||
public void BuildBattleStart_SerializesAllWireKeysAndPreservesBattlePointAsymmetry()
|
||||
{
|
||||
var env = ScriptedLifecycle.BuildBattleStart(FixtureCtx(), ScriptedBotCtx(), selfViewerId: 906243102);
|
||||
var env = ScriptedLifecycle.BuildBattleStart(FixtureCtx(), ScriptedBotCtx(), selfViewerId: 906243102, turnState: 0);
|
||||
|
||||
var json = MsgEnvelope.ToJson(env);
|
||||
var node = JsonNode.Parse(json)!.AsObject();
|
||||
|
||||
@@ -52,6 +52,43 @@ public class BattleSessionDispatchTests
|
||||
Assert.That(a.Phase, Is.EqualTo(BattleSessionPhase.AwaitingSwap));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Pvp_Loaded_from_A_assigns_turnState_0()
|
||||
{
|
||||
var (s, a, _) = NewPvpSession();
|
||||
s.ComputeFrames(a, NewEnvelope(NetworkBattleUri.InitNetwork));
|
||||
s.ComputeFrames(a, NewEnvelope(NetworkBattleUri.InitBattle));
|
||||
var routes = s.ComputeFrames(a, NewEnvelope(NetworkBattleUri.Loaded));
|
||||
|
||||
var bs = (BattleStartBody)routes[0].Frame.Body;
|
||||
Assert.That(bs.TurnState, Is.EqualTo(0), "A (first arriver) goes first.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Pvp_Loaded_from_B_assigns_turnState_1()
|
||||
{
|
||||
var (s, _, b) = NewPvpSession();
|
||||
s.ComputeFrames(b, NewEnvelope(NetworkBattleUri.InitNetwork));
|
||||
s.ComputeFrames(b, NewEnvelope(NetworkBattleUri.InitBattle));
|
||||
var routes = s.ComputeFrames(b, NewEnvelope(NetworkBattleUri.Loaded));
|
||||
|
||||
var bs = (BattleStartBody)routes[0].Frame.Body;
|
||||
Assert.That(bs.TurnState, Is.EqualTo(1), "B (second arriver) goes second.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Scripted_Loaded_from_player_assigns_turnState_0()
|
||||
{
|
||||
// Real player is constructed as A in scripted sessions, so it always goes first.
|
||||
var (s, a, _) = NewSession();
|
||||
s.ComputeFrames(a, NewEnvelope(NetworkBattleUri.InitNetwork));
|
||||
s.ComputeFrames(a, NewEnvelope(NetworkBattleUri.InitBattle));
|
||||
var routes = s.ComputeFrames(a, NewEnvelope(NetworkBattleUri.Loaded));
|
||||
|
||||
var bs = (BattleStartBody)routes[0].Frame.Body;
|
||||
Assert.That(bs.TurnState, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Swap_pushes_SwapResponse_then_Ready_to_sender()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user