feat(battle-node): TurnStartHandler emits {spin:0} to opponent in PvP
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using SVSim.BattleNode.Protocol;
|
||||
using SVSim.BattleNode.Protocol.Bodies;
|
||||
|
||||
namespace SVSim.BattleNode.Sessions.Dispatch.Handlers;
|
||||
|
||||
@@ -6,10 +7,18 @@ internal sealed class TurnStartHandler : IFrameHandler
|
||||
{
|
||||
public IReadOnlyList<DispatchRoute> Handle(FrameDispatchContext ctx)
|
||||
{
|
||||
// Forward the opponent's turn-open to the other side. Union of the two legacy arms:
|
||||
// BothAfterReady (PvP / scripted real player) OR a scripted-bot emission (test stub path).
|
||||
if (ctx.BothAfterReady() || ctx.IsScriptedBot(ctx.From))
|
||||
// PvP: the active player's TurnStart{orderList} is dropped; the opponent receives {spin}
|
||||
// (spin=0 for the deterministic-turn slice) and self-generates its turn-open.
|
||||
if (ctx.Type == BattleType.Pvp && ctx.BothAfterReady())
|
||||
{
|
||||
var frame = ctx.Env with { Body = new OpponentTurnStartBody(Spin: 0) };
|
||||
return new[] { new DispatchRoute(ctx.Other, frame, false) };
|
||||
}
|
||||
|
||||
// Scripted-bot emission (test stub path): the bot already emits the {spin} shape — forward.
|
||||
if (ctx.IsScriptedBot(ctx.From))
|
||||
return new[] { new DispatchRoute(ctx.Other, ctx.Env, false) };
|
||||
|
||||
return Array.Empty<DispatchRoute>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,7 +384,7 @@ public class BattleSessionDispatchTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Pvp_TurnStart_from_A_in_BothAfterReady_forwards_to_B()
|
||||
public void Pvp_TurnStart_from_A_emits_spin0_to_B()
|
||||
{
|
||||
var (s, a, b) = NewPvpSession();
|
||||
DriveToAfterReady(s, a);
|
||||
@@ -395,6 +395,8 @@ public class BattleSessionDispatchTests
|
||||
Assert.That(routes.Count, Is.EqualTo(1));
|
||||
Assert.That(routes[0].Target, Is.SameAs(b));
|
||||
Assert.That(routes[0].Frame.Uri, Is.EqualTo(NetworkBattleUri.TurnStart));
|
||||
var body = (SVSim.BattleNode.Protocol.Bodies.OpponentTurnStartBody)routes[0].Frame.Body;
|
||||
Assert.That(body.Spin, Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user