refactor(battle-node): extract LoadedHandler

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-03 14:10:33 -04:00
parent e5ec8a0de1
commit 3e2931b085
2 changed files with 35 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
using SVSim.BattleNode.Lifecycle;
using SVSim.BattleNode.Protocol;
namespace SVSim.BattleNode.Sessions.Dispatch.Handlers;
internal sealed class LoadedHandler : IFrameHandler
{
public IReadOnlyList<DispatchRoute> Handle(FrameDispatchContext ctx)
{
// case 3: Bot — silent (client populates opponent state from AIBattleStart HTTP data).
if (ctx.Type == BattleType.Bot && ctx.SenderPhase == BattleSessionPhase.AwaitingLoaded)
{
ctx.SenderPhase = BattleSessionPhase.AwaitingSwap;
return Array.Empty<DispatchRoute>();
}
// case 6: general — BattleStart (per-perspective) + Deal to the sender.
if (ctx.SenderPhase == BattleSessionPhase.AwaitingLoaded)
{
// A goes first deterministically (turnState 0); B goes second (turnState 1).
var turnState = ReferenceEquals(ctx.From, ctx.A) ? 0 : 1;
var r = new List<DispatchRoute>
{
new(ctx.From, ScriptedLifecycle.BuildBattleStart(
ctx.From.Context, ctx.Other.Context, ctx.From.ViewerId, turnState), false),
new(ctx.From, ScriptedLifecycle.BuildDeal(), false),
};
ctx.SenderPhase = BattleSessionPhase.AwaitingSwap;
return r;
}
return Array.Empty<DispatchRoute>();
}
}