refactor(battle-node): extract TurnEndFinalHandler

This commit is contained in:
gamer147
2026-06-03 14:21:54 -04:00
parent 538099ff4b
commit d35818360f
2 changed files with 28 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ public sealed class BattleSession
[NetworkBattleUri.Loaded] = new LoadedHandler(),
[NetworkBattleUri.Swap] = new SwapHandler(),
[NetworkBattleUri.TurnEnd] = new TurnEndHandler(),
[NetworkBattleUri.TurnEndFinal] = new TurnEndFinalHandler(),
};
private FrameDispatchContext BuildContext(IBattleParticipant from, MsgEnvelope env) =>

View File

@@ -0,0 +1,27 @@
using SVSim.BattleNode.Protocol;
namespace SVSim.BattleNode.Sessions.Dispatch.Handlers;
internal sealed class TurnEndFinalHandler : IFrameHandler
{
public IReadOnlyList<DispatchRoute> Handle(FrameDispatchContext ctx)
{
// case 4: Bot — Judge to sender only.
if (ctx.Type == BattleType.Bot && ctx.SenderPhase == BattleSessionPhase.AfterReady)
return new[] { new DispatchRoute(ctx.From, BattleFrames.BuildJudgeBroadcast(), false) };
// case 9: general — forward the envelope to other + paired BattleFinish + Terminal.
if (ctx.SenderPhase == BattleSessionPhase.AfterReady)
{
ctx.State.SessionPhase = BattleSessionPhase.Terminal;
return new[]
{
new DispatchRoute(ctx.Other, ctx.Env, false),
new DispatchRoute(ctx.From, BattleFrames.BuildBattleFinish(BattleResult.LifeWin), true),
new DispatchRoute(ctx.Other, BattleFrames.BuildBattleFinish(BattleResult.LifeLose), true),
};
}
return Array.Empty<DispatchRoute>();
}
}