using SVSim.BattleNode.Bridge; using SVSim.BattleNode.Lifecycle; using SVSim.BattleNode.Protocol; namespace SVSim.BattleNode.Sessions.Participants; /// /// Server-scripted opponent (today's v1.2 testing-harness behavior, repackaged). /// On with TurnEnd or TurnEndFinal, fires /// three times: OpponentTurnStart, /// OpponentTurnEnd, OpponentJudge. All other URIs are swallowed /// (no opponent reaction needed for v1.2 behavior). /// /// /// ViewerId, Context are fixtures matching /// and a scripted opponent profile. Used by Phase 1 to preserve the v1.2 burst /// behavior under the new participant abstraction; the session synthesizes /// Matched/BattleStart/Deal using only the OTHER (real) participant's Context for now — /// the scripted bot's Context is ignored for those frames in Phase 1. /// public sealed class ScriptedBotParticipant : IBattleParticipant { public long ViewerId => ScriptedLifecycle.FakeOpponentViewerId; public MatchContext Context { get; } = new( SelfDeckCardIds: Array.Empty(), ClassId: "0", CharaId: "0", CardMasterName: "card_master_node_10015", CountryCode: "JPN", UserName: "Opponent", SleeveId: "704141010", EmblemId: "400001100", DegreeId: "120027", FieldId: 5, IsOfficial: 0, BattleType: 0); public event Func? FrameEmitted; public async Task PushAsync(MsgEnvelope envelope, bool noStock, CancellationToken ct) { // v1.2 behavior: react to the player's TurnEnd / TurnEndFinal with the // three-frame burst. Everything else is silently swallowed. if (envelope.Uri is NetworkBattleUri.TurnEnd or NetworkBattleUri.TurnEndFinal) { await EmitAsync(ScriptedLifecycle.BuildOpponentTurnStart(), ct).ConfigureAwait(false); await EmitAsync(ScriptedLifecycle.BuildOpponentTurnEnd(), ct).ConfigureAwait(false); await EmitAsync(ScriptedLifecycle.BuildOpponentJudge(), ct).ConfigureAwait(false); } } public Task RunAsync(CancellationToken ct) => Task.CompletedTask; public Task TerminateAsync(BattleFinishReason reason) => Task.CompletedTask; public ValueTask DisposeAsync() => ValueTask.CompletedTask; private Task EmitAsync(MsgEnvelope env, CancellationToken ct) => FrameEmitted?.Invoke(env, ct) ?? Task.CompletedTask; }