refactor(battlenode): type MatchContext.ClassId as CardClass enum (§C)
Behavior-preserving; full solution builds, 1013 tests green. ClassId is the one genuinely-closed set of the three flagged stringly fields, so it becomes a CardClass enum (1..8). Wire stays "1".."8": producer casts (CardClass)run.ClassId, ServerBattleFrames renders via CardClassWire.ToWireValue(). RankBattleController's AI-start path drops a fragile int.TryParse(...)?:-1 for (int)cast. CharaId (free-form leader/skin id, e.g. "5000123") and CountryCode (open-ended account data) stay string with proper XML docs; CountryCodes.Korea/Japan name the captured values. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
29
SVSim.BattleNode/Bridge/CardClass.cs
Normal file
29
SVSim.BattleNode/Bridge/CardClass.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
namespace SVSim.BattleNode.Bridge;
|
||||
|
||||
/// <summary>
|
||||
/// A Shadowverse class (craft). The wire carries it as the stringified ordinal (<c>"1".."8"</c> on
|
||||
/// the <c>classId</c> field); this enum replaces that stringly-typed value on
|
||||
/// <see cref="MatchContext.ClassId"/> so the legal set lives in the type, not a trailing comment.
|
||||
/// <see cref="None"/> covers an unset / placeholder context. Use <see cref="CardClassWire.ToWireValue"/>
|
||||
/// to render the wire string.
|
||||
/// </summary>
|
||||
public enum CardClass
|
||||
{
|
||||
None = 0,
|
||||
Forestcraft = 1,
|
||||
Swordcraft = 2,
|
||||
Runecraft = 3,
|
||||
Dragoncraft = 4,
|
||||
Shadowcraft = 5,
|
||||
Bloodcraft = 6,
|
||||
Havencraft = 7,
|
||||
Portalcraft = 8,
|
||||
}
|
||||
|
||||
/// <summary>Wire rendering for <see cref="CardClass"/>.</summary>
|
||||
public static class CardClassWire
|
||||
{
|
||||
/// <summary>The <c>classId</c> wire value — the class ordinal as a string (<c>"1".."8"</c>,
|
||||
/// <c>"0"</c> for <see cref="CardClass.None"/>), matching what the client sends/expects.</summary>
|
||||
public static string ToWireValue(this CardClass cardClass) => ((int)cardClass).ToString();
|
||||
}
|
||||
13
SVSim.BattleNode/Bridge/CountryCodes.cs
Normal file
13
SVSim.BattleNode/Bridge/CountryCodes.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace SVSim.BattleNode.Bridge;
|
||||
|
||||
/// <summary>
|
||||
/// Known values for <see cref="MatchContext.CountryCode"/>. NOT a closed set — the field is the
|
||||
/// account's region code copied verbatim from viewer data (any value, possibly empty), and the node
|
||||
/// never branches on it. These constants just name the values seen in the prod captures so test
|
||||
/// fixtures and docs aren't sprinkled with bare <c>"KOR"</c>/<c>"JPN"</c> literals.
|
||||
/// </summary>
|
||||
public static class CountryCodes
|
||||
{
|
||||
public const string Korea = "KOR";
|
||||
public const string Japan = "JPN";
|
||||
}
|
||||
@@ -12,12 +12,25 @@ public sealed record MatchContext(
|
||||
IReadOnlyList<long> SelfDeckCardIds,
|
||||
|
||||
// Player class + leader (BattleStartSelfInfo)
|
||||
string ClassId, // "1".."8"
|
||||
string CharaId, // "1".."8" — equals ClassId when no leader skin chosen
|
||||
|
||||
/// <summary>The player's class. Rendered onto the wire <c>classId</c> as <c>"1".."8"</c> via
|
||||
/// <see cref="CardClassWire.ToWireValue"/>; a closed set, so it's typed, not stringly.</summary>
|
||||
CardClass ClassId,
|
||||
|
||||
/// <summary>Leader/skin id on the wire <c>charaId</c>. FREE-FORM, not a class enum: it's the
|
||||
/// equipped leader-skin id (e.g. <c>"5000123"</c>) when one is chosen, else the class ordinal
|
||||
/// (<c>"1".."8"</c>). Passed through verbatim — the node never interprets it.</summary>
|
||||
string CharaId,
|
||||
|
||||
string CardMasterName, // current card-master, e.g. "card_master_node_10015"
|
||||
|
||||
// Player cosmetics (MatchedSelfInfo)
|
||||
string CountryCode, // "KOR", "JPN", ...
|
||||
|
||||
/// <summary>Account region code, wire <c>country_code</c>. OPEN-ENDED account data (any value,
|
||||
/// possibly empty); the node never branches on it. <see cref="CountryCodes"/> names the values
|
||||
/// seen in captures.</summary>
|
||||
string CountryCode,
|
||||
|
||||
string UserName,
|
||||
string SleeveId,
|
||||
string EmblemId,
|
||||
|
||||
@@ -59,7 +59,7 @@ public static class ServerBattleFrames
|
||||
SelfInfo: new BattleStartSelfInfo(
|
||||
Rank: BattleFrameDefaults.PlayerRank,
|
||||
BattlePoint: BattleFrameDefaults.PlayerBattlePoint,
|
||||
ClassId: selfCtx.ClassId,
|
||||
ClassId: selfCtx.ClassId.ToWireValue(),
|
||||
CharaId: selfCtx.CharaId,
|
||||
CardMasterName: selfCtx.CardMasterName),
|
||||
OppoInfo: new BattleStartOppoInfo(
|
||||
@@ -69,7 +69,7 @@ public static class ServerBattleFrames
|
||||
IsMasterRank: "0",
|
||||
BattlePoint: 0,
|
||||
MasterPoint: "0",
|
||||
ClassId: oppoCtx.ClassId,
|
||||
ClassId: oppoCtx.ClassId.ToWireValue(),
|
||||
CharaId: oppoCtx.CharaId,
|
||||
CardMasterName: oppoCtx.CardMasterName)));
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public sealed class NoOpBotParticipant : IBattleParticipant
|
||||
public long ViewerId => ServerBattleFrames.FakeOpponentViewerId;
|
||||
public MatchContext Context { get; } = new(
|
||||
SelfDeckCardIds: Array.Empty<long>(),
|
||||
ClassId: "0", CharaId: "0", CardMasterName: BotCardMasterName,
|
||||
ClassId: CardClass.None, CharaId: "0", CardMasterName: BotCardMasterName,
|
||||
CountryCode: "", UserName: "Bot", SleeveId: "0",
|
||||
EmblemId: "0", DegreeId: "0", FieldId: 0, IsOfficial: 0,
|
||||
BattleModeId: 0);
|
||||
|
||||
Reference in New Issue
Block a user