refactor(battle-node): extract TurnEndFinalHandler
This commit is contained in:
@@ -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) =>
|
||||
|
||||
@@ -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>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user