refactor(battle-node): generalise BuildMatched/BuildBattleStart for PvP
Both helpers now take the opponent's MatchContext + an explicit seed instead of pulling ScriptedProfiles.OpponentMatchedProfile / OpponentBattleStartProfile internally. ScriptedBotParticipant.Context fixture absorbs the cosmetic fields previously hardcoded in ScriptedProfiles so Scripted's wire bytes stay identical - verified by integration tests still green. Phase 2 prep: PvP arms will call the same helpers with the real opponent participant's Context. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -22,35 +22,58 @@ public static class ScriptedLifecycle
|
||||
/// </summary>
|
||||
public const long FakeOpponentViewerId = 999_999_999L;
|
||||
|
||||
public static MsgEnvelope BuildMatched(MatchContext ctx, long playerViewerId, long opponentViewerId, string battleId) =>
|
||||
public static MsgEnvelope BuildMatched(
|
||||
MatchContext selfCtx, MatchContext oppoCtx,
|
||||
long selfViewerId, long oppoViewerId,
|
||||
string battleId, long seed) =>
|
||||
EnvelopeForPush(NetworkBattleUri.Matched,
|
||||
new MatchedBody(
|
||||
SelfInfo: new MatchedSelfInfo(
|
||||
CountryCode: ctx.CountryCode,
|
||||
UserName: ctx.UserName,
|
||||
SleeveId: ctx.SleeveId,
|
||||
EmblemId: ctx.EmblemId,
|
||||
DegreeId: ctx.DegreeId,
|
||||
FieldId: ctx.FieldId,
|
||||
IsOfficial: ctx.IsOfficial,
|
||||
OppoId: opponentViewerId,
|
||||
Seed: ScriptedProfiles.BattleSeed),
|
||||
OppoInfo: ScriptedProfiles.OpponentMatchedProfile with { OppoId = playerViewerId },
|
||||
SelfDeck: BuildPlayerDeck(ctx.SelfDeckCardIds)),
|
||||
CountryCode: selfCtx.CountryCode,
|
||||
UserName: selfCtx.UserName,
|
||||
SleeveId: selfCtx.SleeveId,
|
||||
EmblemId: selfCtx.EmblemId,
|
||||
DegreeId: selfCtx.DegreeId,
|
||||
FieldId: selfCtx.FieldId,
|
||||
IsOfficial: selfCtx.IsOfficial,
|
||||
OppoId: oppoViewerId,
|
||||
Seed: seed),
|
||||
OppoInfo: new MatchedOppoInfo(
|
||||
CountryCode: oppoCtx.CountryCode,
|
||||
UserName: oppoCtx.UserName,
|
||||
SleeveId: oppoCtx.SleeveId,
|
||||
EmblemId: oppoCtx.EmblemId,
|
||||
DegreeId: oppoCtx.DegreeId,
|
||||
FieldId: oppoCtx.FieldId,
|
||||
IsOfficial: oppoCtx.IsOfficial,
|
||||
OppoId: selfViewerId,
|
||||
Seed: seed,
|
||||
OppoDeckCount: oppoCtx.SelfDeckCardIds.Count),
|
||||
SelfDeck: BuildPlayerDeck(selfCtx.SelfDeckCardIds)),
|
||||
bid: battleId);
|
||||
|
||||
public static MsgEnvelope BuildBattleStart(MatchContext ctx, long playerViewerId) =>
|
||||
public static MsgEnvelope BuildBattleStart(
|
||||
MatchContext selfCtx, MatchContext oppoCtx, long selfViewerId) =>
|
||||
EnvelopeForPush(NetworkBattleUri.BattleStart,
|
||||
new BattleStartBody(
|
||||
TurnState: 0, // player goes first
|
||||
BattleType: ctx.BattleType,
|
||||
BattleType: selfCtx.BattleType,
|
||||
SelfInfo: new BattleStartSelfInfo(
|
||||
Rank: ScriptedProfiles.PlayerRank,
|
||||
BattlePoint: ScriptedProfiles.PlayerBattlePoint,
|
||||
ClassId: ctx.ClassId,
|
||||
CharaId: ctx.CharaId,
|
||||
CardMasterName: ctx.CardMasterName),
|
||||
OppoInfo: ScriptedProfiles.OpponentBattleStartProfile));
|
||||
ClassId: selfCtx.ClassId,
|
||||
CharaId: selfCtx.CharaId,
|
||||
CardMasterName: selfCtx.CardMasterName),
|
||||
OppoInfo: new BattleStartOppoInfo(
|
||||
// Rank/IsMasterRank/BattlePoint/MasterPoint stay hardcoded —
|
||||
// PvP rank tracking is deferred (per spec § Out of scope).
|
||||
Rank: "1",
|
||||
IsMasterRank: "0",
|
||||
BattlePoint: 0,
|
||||
MasterPoint: "0",
|
||||
ClassId: oppoCtx.ClassId,
|
||||
CharaId: oppoCtx.CharaId,
|
||||
CardMasterName: oppoCtx.CardMasterName)));
|
||||
|
||||
public static MsgEnvelope BuildDeal() =>
|
||||
EnvelopeForPush(NetworkBattleUri.Deal,
|
||||
|
||||
@@ -98,15 +98,19 @@ public sealed class BattleSession
|
||||
|
||||
case NetworkBattleUri.InitBattle when Phase == BattleSessionPhase.AwaitingInitBattle:
|
||||
// Phase 1: push Matched only to the "real" participant. The session reads
|
||||
// selfInfo from from.Context; opponent half currently comes from
|
||||
// ScriptedProfiles inside ScriptedLifecycle.BuildMatched (Phase 2 generalises
|
||||
// to use other.Context for per-perspective Matched).
|
||||
result.Add((from, ScriptedLifecycle.BuildMatched(from.Context, from.ViewerId, other.ViewerId, BattleId), false));
|
||||
// selfInfo from from.Context and oppoInfo from other.Context (the scripted
|
||||
// bot's Context fixture preserves the prod-captured cosmetics that previously
|
||||
// lived in ScriptedProfiles).
|
||||
result.Add((from, ScriptedLifecycle.BuildMatched(
|
||||
from.Context, other.Context,
|
||||
from.ViewerId, other.ViewerId,
|
||||
BattleId, ScriptedProfiles.BattleSeed), false));
|
||||
Phase = BattleSessionPhase.AwaitingLoaded;
|
||||
break;
|
||||
|
||||
case NetworkBattleUri.Loaded when Phase == BattleSessionPhase.AwaitingLoaded:
|
||||
result.Add((from, ScriptedLifecycle.BuildBattleStart(from.Context, from.ViewerId), false));
|
||||
result.Add((from, ScriptedLifecycle.BuildBattleStart(
|
||||
from.Context, other.Context, from.ViewerId), false));
|
||||
result.Add((from, ScriptedLifecycle.BuildDeal(), false));
|
||||
Phase = BattleSessionPhase.AwaitingSwap;
|
||||
break;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Linq;
|
||||
using SVSim.BattleNode.Bridge;
|
||||
using SVSim.BattleNode.Lifecycle;
|
||||
using SVSim.BattleNode.Protocol;
|
||||
@@ -22,8 +23,12 @@ public sealed class ScriptedBotParticipant : IBattleParticipant
|
||||
{
|
||||
public long ViewerId => ScriptedLifecycle.FakeOpponentViewerId;
|
||||
public MatchContext Context { get; } = new(
|
||||
SelfDeckCardIds: Array.Empty<long>(),
|
||||
ClassId: "0", CharaId: "0", CardMasterName: "card_master_node_10015",
|
||||
// 30 dummy card ids so oppoCtx.SelfDeckCardIds.Count == 30 (matches the
|
||||
// hardcoded OppoDeckCount that ScriptedProfiles.OpponentMatchedProfile shipped).
|
||||
SelfDeckCardIds: Enumerable.Range(1, 30).Select(_ => 0L).ToList(),
|
||||
// BattleStart opponent half: ClassId/CharaId from ScriptedProfiles.OpponentBattleStartProfile.
|
||||
ClassId: "8", CharaId: "8", CardMasterName: "card_master_node_10015",
|
||||
// Matched opponent half: cosmetic fields from ScriptedProfiles.OpponentMatchedProfile.
|
||||
CountryCode: "JPN", UserName: "Opponent", SleeveId: "704141010",
|
||||
EmblemId: "400001100", DegreeId: "120027", FieldId: 5, IsOfficial: 0,
|
||||
BattleType: 0);
|
||||
|
||||
Reference in New Issue
Block a user