From aacd7b56ad08f7c60b268dcd3a71eb32d90909e7 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Wed, 3 Jun 2026 14:27:17 -0400 Subject: [PATCH] refactor(battle-node): extract TurnStartHandler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unions the two legacy TurnStart arms (IsRealForwardableFromScripted case 11 + BothAfterReady case 12) into TurnStartHandler. Both arms produce (Other, Env, false) with no extra guards or state mutations — union is behavior-equivalent. Co-Authored-By: Claude Sonnet 4.6 --- SVSim.BattleNode/Sessions/BattleSession.cs | 1 + .../Dispatch/Handlers/TurnStartHandler.cs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 SVSim.BattleNode/Sessions/Dispatch/Handlers/TurnStartHandler.cs diff --git a/SVSim.BattleNode/Sessions/BattleSession.cs b/SVSim.BattleNode/Sessions/BattleSession.cs index d503b23..a96f6a4 100644 --- a/SVSim.BattleNode/Sessions/BattleSession.cs +++ b/SVSim.BattleNode/Sessions/BattleSession.cs @@ -44,6 +44,7 @@ public sealed class BattleSession [NetworkBattleUri.TurnEndFinal] = new TurnEndFinalHandler(), [NetworkBattleUri.Retire] = new RetireKillHandler(), [NetworkBattleUri.Kill] = new RetireKillHandler(), + [NetworkBattleUri.TurnStart] = new TurnStartHandler(), }; private FrameDispatchContext BuildContext(IBattleParticipant from, MsgEnvelope env) => diff --git a/SVSim.BattleNode/Sessions/Dispatch/Handlers/TurnStartHandler.cs b/SVSim.BattleNode/Sessions/Dispatch/Handlers/TurnStartHandler.cs new file mode 100644 index 0000000..ff7e102 --- /dev/null +++ b/SVSim.BattleNode/Sessions/Dispatch/Handlers/TurnStartHandler.cs @@ -0,0 +1,15 @@ +using SVSim.BattleNode.Protocol; + +namespace SVSim.BattleNode.Sessions.Dispatch.Handlers; + +internal sealed class TurnStartHandler : IFrameHandler +{ + public IReadOnlyList 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)) + return new[] { new DispatchRoute(ctx.Other, ctx.Env, false) }; + return Array.Empty(); + } +}