feat(battle-node): add IBattleParticipant interface
Central abstraction for v2 broker. PushAsync (session -> participant), FrameEmitted (participant -> session), RunAsync (drives inbound), TerminateAsync (cleanup). Three impls land in Tasks 3-5.
This commit is contained in:
46
SVSim.BattleNode/Sessions/IBattleParticipant.cs
Normal file
46
SVSim.BattleNode/Sessions/IBattleParticipant.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using SVSim.BattleNode.Bridge;
|
||||
using SVSim.BattleNode.Protocol;
|
||||
|
||||
namespace SVSim.BattleNode.Sessions;
|
||||
|
||||
/// <summary>
|
||||
/// One side of a battle. Two of these are held by a <c>BattleSession</c>; the session
|
||||
/// brokers between them. Concrete impls (added in subsequent Phase-1 tasks):
|
||||
/// <list type="bullet">
|
||||
/// <item><c>RealParticipant</c> — WS-backed.</item>
|
||||
/// <item><c>NoOpBotParticipant</c> — silent; for <c>BattleType.Bot</c> (AI-passive).</item>
|
||||
/// <item><c>ScriptedBotParticipant</c> — wraps the v1.2 lifecycle for
|
||||
/// <c>BattleType.Scripted</c> (solo testing harness).</item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
public interface IBattleParticipant : IAsyncDisposable
|
||||
{
|
||||
/// <summary>Real viewer id, or a synthetic stable id for bots
|
||||
/// (<see cref="Lifecycle.ScriptedLifecycle.FakeOpponentViewerId"/>).</summary>
|
||||
long ViewerId { get; }
|
||||
|
||||
/// <summary>Per-battle MatchContext snapshot, used for building Matched/BattleStart
|
||||
/// selfInfo when this participant is "self" in the perspective.</summary>
|
||||
MatchContext Context { get; }
|
||||
|
||||
/// <summary>Session calls this to deliver a frame from the OTHER participant
|
||||
/// (or a server-synthesized broadcast). Real impl: encode + WS-send.
|
||||
/// NoOp: swallow. Scripted: may emit a response via <see cref="FrameEmitted"/>.</summary>
|
||||
/// <param name="noStock">True for control frames (BattleFinish, JudgeResult, ack);
|
||||
/// bypasses playSeq assignment + archive.</param>
|
||||
Task PushAsync(MsgEnvelope envelope, bool noStock, CancellationToken ct);
|
||||
|
||||
/// <summary>Participant fires this when it has a frame to send TO the session
|
||||
/// (its own gameplay action). Real impl: fires on WS recv. NoOp: never fires.
|
||||
/// Scripted: fires from inside PushAsync when the scripted lifecycle wants to
|
||||
/// respond to an inbound frame.</summary>
|
||||
event Func<MsgEnvelope, CancellationToken, Task>? FrameEmitted;
|
||||
|
||||
/// <summary>Drives the participant's inbound loop. For Real: the WS read loop
|
||||
/// (returns when the WS closes). For NoOp/Scripted: completes immediately (the
|
||||
/// session keeps running as long as the OTHER participant's RunAsync is alive).</summary>
|
||||
Task RunAsync(CancellationToken ct);
|
||||
|
||||
/// <summary>Called when the battle ends. Concrete impls clean up (close WS, etc.).</summary>
|
||||
Task TerminateAsync(BattleFinishReason reason);
|
||||
}
|
||||
Reference in New Issue
Block a user