Phase 2 absorbed the scripted opponent cosmetics + class/chara fixture into ScriptedBotParticipant.Context; the two profile fields have been unreferenced since (kept one phase as documentation tie-back, per PLAN.md L104 (d)). The Context comments now describe the values directly with frame[N] provenance instead of pointing at the deleted fields. Also removes the now-unused SVSim.BattleNode.Protocol.Bodies import from ScriptedProfiles.cs. 948 tests passing (unchanged). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
57 lines
2.9 KiB
C#
57 lines
2.9 KiB
C#
using System.Linq;
|
|
using SVSim.BattleNode.Bridge;
|
|
using SVSim.BattleNode.Lifecycle;
|
|
using SVSim.BattleNode.Protocol;
|
|
|
|
namespace SVSim.BattleNode.Sessions.Participants;
|
|
|
|
/// <summary>
|
|
/// Server-scripted opponent (today's v1.2 testing-harness behavior, repackaged).
|
|
/// On <see cref="PushAsync"/> with <c>TurnEnd</c> or <c>TurnEndFinal</c>, fires
|
|
/// <see cref="FrameEmitted"/> three times: <c>OpponentTurnStart</c>,
|
|
/// <c>OpponentTurnEnd</c>, <c>OpponentJudge</c>. All other URIs are swallowed
|
|
/// (no opponent reaction needed for v1.2 behavior).
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// ViewerId, Context are fixtures matching <see cref="ScriptedLifecycle.FakeOpponentViewerId"/>
|
|
/// and a scripted opponent profile. The Context fixture is the source of truth for the
|
|
/// scripted opponent's half of Matched and BattleStart (cosmetics, deck count, class/chara) —
|
|
/// <see cref="BattleSession.ComputeFrames"/> reads <c>other.Context</c> for those frames.
|
|
/// Deal still uses fixed scripted frames that ignore Context.
|
|
/// </remarks>
|
|
public sealed class ScriptedBotParticipant : IBattleParticipant
|
|
{
|
|
public long ViewerId => ScriptedLifecycle.FakeOpponentViewerId;
|
|
public MatchContext Context { get; } = new(
|
|
// 30 dummy card ids so oppoCtx.SelfDeckCardIds.Count == 30 — prod frame[2] (Matched)
|
|
// shipped OppoDeckCount: 30.
|
|
SelfDeckCardIds: Enumerable.Range(1, 30).Select(_ => 0L).ToList(),
|
|
// BattleStart opponent half (frame[5]): ClassId/CharaId both "8" (neutral test class).
|
|
ClassId: "8", CharaId: "8", CardMasterName: "card_master_node_10015",
|
|
// Matched opponent half (frame[2]): cosmetic fields from the prod capture.
|
|
CountryCode: "JPN", UserName: "Opponent", SleeveId: "704141010",
|
|
EmblemId: "400001100", DegreeId: "120027", FieldId: 5, IsOfficial: 0,
|
|
BattleType: 0);
|
|
|
|
public event Func<MsgEnvelope, CancellationToken, Task>? 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;
|
|
}
|