feat(battle-node): TurnEndHandler emits {turnState:0} to opponent only in PvP

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-03 18:07:44 -04:00
parent 6e85a6b2db
commit 3c8a00c928
2 changed files with 12 additions and 18 deletions

View File

@@ -1,4 +1,5 @@
using SVSim.BattleNode.Protocol; using SVSim.BattleNode.Protocol;
using SVSim.BattleNode.Protocol.Bodies;
namespace SVSim.BattleNode.Sessions.Dispatch.Handlers; namespace SVSim.BattleNode.Sessions.Dispatch.Handlers;
@@ -16,15 +17,11 @@ internal sealed class TurnEndHandler : IFrameHandler
{ {
if (ctx.Type == BattleType.Pvp && ctx.BothAfterReady()) if (ctx.Type == BattleType.Pvp && ctx.BothAfterReady())
{ {
var te = BattleFrames.BuildTurnEndBroadcast(); // Opponent sees {turnState}; receiving TurnEnd drives its SendJudge (handover gate).
var jg = BattleFrames.BuildJudgeBroadcast(); // battleCode/actionSeq/cemetery are dropped. The paired Judge{spin} is emitted by
return new[] // JudgeHandler when the active player sends its own Judge frame.
{ var te = ctx.Env with { Body = new TurnEndBody(TurnState: 0) };
new DispatchRoute(ctx.From, te, false), return new[] { new DispatchRoute(ctx.Other, te, false) };
new DispatchRoute(ctx.Other, te, false),
new DispatchRoute(ctx.From, jg, false),
new DispatchRoute(ctx.Other, jg, false),
};
} }
if (ctx.Type == BattleType.Scripted) if (ctx.Type == BattleType.Scripted)
return new[] { new DispatchRoute(ctx.Other, ctx.Env, false) }; return new[] { new DispatchRoute(ctx.Other, ctx.Env, false) };

View File

@@ -518,7 +518,7 @@ public class BattleSessionDispatchTests
} }
[Test] [Test]
public void Pvp_TurnEnd_from_A_in_BothAfterReady_broadcasts_TurnEnd_plus_Judge_to_both() public void Pvp_TurnEnd_from_A_emits_turnState_to_B_only()
{ {
var (s, a, b) = NewPvpSession(); var (s, a, b) = NewPvpSession();
DriveToAfterReady(s, a); DriveToAfterReady(s, a);
@@ -526,14 +526,11 @@ public class BattleSessionDispatchTests
var routes = s.ComputeFrames(a, NewEnvelope(NetworkBattleUri.TurnEnd)); var routes = s.ComputeFrames(a, NewEnvelope(NetworkBattleUri.TurnEnd));
Assert.That(routes.Count, Is.EqualTo(4)); Assert.That(routes.Count, Is.EqualTo(1));
Assert.That(routes.Select(r => (r.Target, r.Frame.Uri)), Is.EquivalentTo(new[] Assert.That(routes[0].Target, Is.SameAs(b));
{ Assert.That(routes[0].Frame.Uri, Is.EqualTo(NetworkBattleUri.TurnEnd));
((IBattleParticipant)a, NetworkBattleUri.TurnEnd), var body = (SVSim.BattleNode.Protocol.Bodies.TurnEndBody)routes[0].Frame.Body;
((IBattleParticipant)b, NetworkBattleUri.TurnEnd), Assert.That(body.TurnState, Is.EqualTo(0));
((IBattleParticipant)a, NetworkBattleUri.Judge),
((IBattleParticipant)b, NetworkBattleUri.Judge),
}));
} }
[Test] [Test]