feat(battle-node): TurnEndActionsHandler emits empty body to opponent in PvP
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -51,7 +51,7 @@ public sealed class BattleSession
|
||||
[NetworkBattleUri.Judge] = new JudgeHandler(),
|
||||
[NetworkBattleUri.PlayActions] = new PlayActionsHandler(),
|
||||
[NetworkBattleUri.Echo] = new EchoHandler(),
|
||||
[NetworkBattleUri.TurnEndActions] = forwardWhenReady,
|
||||
[NetworkBattleUri.TurnEndActions] = new TurnEndActionsHandler(),
|
||||
[NetworkBattleUri.JudgeResult] = forwardWhenReady,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using SVSim.BattleNode.Protocol;
|
||||
|
||||
namespace SVSim.BattleNode.Sessions.Dispatch.Handlers;
|
||||
|
||||
/// <summary>PvP TurnEndActions: the sender's orderList is dropped; the opponent receives an
|
||||
/// empty body (it only flips _sendEcho + runs the opponent's end-of-turn triggers via the
|
||||
/// opponent's own engine). Scripted/Bot drop.</summary>
|
||||
internal sealed class TurnEndActionsHandler : IFrameHandler
|
||||
{
|
||||
public IReadOnlyList<DispatchRoute> Handle(FrameDispatchContext ctx)
|
||||
{
|
||||
if (ctx.Type == BattleType.Pvp && ctx.BothAfterReady())
|
||||
{
|
||||
var frame = ctx.Env with { Body = new RawBody(new Dictionary<string, object?>()) };
|
||||
return new[] { new DispatchRoute(ctx.Other, frame, false) };
|
||||
}
|
||||
return Array.Empty<DispatchRoute>();
|
||||
}
|
||||
}
|
||||
@@ -508,16 +508,19 @@ public class BattleSessionDispatchTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Pvp_TurnEndActions_from_A_in_BothAfterReady_forwards_to_B()
|
||||
public void Pvp_TurnEndActions_from_A_emits_empty_body_to_B()
|
||||
{
|
||||
var (s, a, b) = NewPvpSession();
|
||||
DriveToAfterReady(s, a);
|
||||
DriveToAfterReady(s, b);
|
||||
|
||||
var routes = s.ComputeFrames(a, NewEnvelope(NetworkBattleUri.TurnEndActions));
|
||||
var body = MoveOrderList(3, 20, 30); // a non-empty orderList that must be dropped
|
||||
var routes = s.ComputeFrames(a, EnvWith(NetworkBattleUri.TurnEndActions, body));
|
||||
|
||||
Assert.That(routes.Count, Is.EqualTo(1));
|
||||
Assert.That(routes[0].Target, Is.SameAs(b));
|
||||
Assert.That(routes[0].Frame.Uri, Is.EqualTo(NetworkBattleUri.TurnEndActions));
|
||||
Assert.That(((RawBody)routes[0].Frame.Body).Entries, Is.Empty, "orderList is dropped; body is empty.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user