refactor(battlenode): key dispatch on OpponentIsAckOnly, drop per-frame BattleType switch
Behavior-identical; 231 BattleNode tests green with ZERO test changes. The 10 handler arms no longer switch on BattleType: - 4 Bot arms gate on the new FrameDispatchContext.OpponentIsAckOnly (Other is not IHasHandshakePhase) — the participant property the audit asked for. - 6 relay arms drop the Type == Pvp guard; it was redundant with BothSidesAfterReady() (only a two-real-player session has both handshake phases). Its doc now records that. - FrameDispatchContext.Type removed (+ the Type = Type in BuildContext). BattleSession.Type stays for the session-level drop cascade. Zero test churn because the stubs already encode the split: FakeRealParticipant/ProbeParticipant implement IHasHandshakePhase, the bot stub FakeParticipant doesn't, and NewBotSession uses it as the opponent. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -14,10 +14,17 @@ internal sealed class FrameDispatchContext
|
||||
internal required IBattleParticipant From { get; init; }
|
||||
internal required IBattleParticipant Other { get; init; }
|
||||
internal required MsgEnvelope Env { get; init; }
|
||||
internal required BattleType Type { get; init; }
|
||||
internal required string BattleId { get; init; }
|
||||
internal required BattleSessionState State { get; init; }
|
||||
|
||||
/// <summary>The opponent is an AI-passive (ack-only) bot: it runs no handshake — no
|
||||
/// <see cref="IHasHandshakePhase"/> — and receives no relayed frames (the client drives its own
|
||||
/// AI; the server only acks). This is the participant property that replaces the per-handler
|
||||
/// <c>BattleType.Bot</c> switch: the Bot dispatch arms gate on it. Its inverse — a live relay
|
||||
/// peer — is what <see cref="BothSidesAfterReady"/> already implies (only real peers have a
|
||||
/// handshake phase), so the relay arms need no separate opponent check.</summary>
|
||||
internal bool OpponentIsAckOnly => Other is not IHasHandshakePhase;
|
||||
|
||||
/// <summary>The dispatching participant's handshake phase (null for a non-IHasHandshakePhase
|
||||
/// participant, e.g. NoOpBot). Setting it advances the sender.</summary>
|
||||
internal HandshakePhase? SenderPhase
|
||||
@@ -34,7 +41,10 @@ internal sealed class FrameDispatchContext
|
||||
|
||||
/// <summary>BOTH participants have finished the handshake. Reads A/B (not From/Other) so the
|
||||
/// result is identical regardless of which side sent the frame. Contrast
|
||||
/// <see cref="SenderIsAfterReady"/> (sender only).</summary>
|
||||
/// <see cref="SenderIsAfterReady"/> (sender only). Only a live relay peer (real player) has a
|
||||
/// handshake phase, so this can only be true in a two-real-player (PvP) session — the relay
|
||||
/// dispatch arms gate on this instead of a <c>BattleType</c> check (an ack-only bot opponent,
|
||||
/// <see cref="OpponentIsAckOnly"/>, can never satisfy it).</summary>
|
||||
internal bool BothSidesAfterReady() =>
|
||||
(A as IHasHandshakePhase)?.Phase == HandshakePhase.AfterReady &&
|
||||
(B as IHasHandshakePhase)?.Phase == HandshakePhase.AfterReady;
|
||||
|
||||
Reference in New Issue
Block a user