feat(battle-node): BattleResult enum for BattleFinish.result wire codes

This commit is contained in:
gamer147
2026-06-01 11:41:16 -04:00
parent eaf6d7160b
commit 677b1f1392
5 changed files with 39 additions and 7 deletions

View File

@@ -66,7 +66,4 @@ internal static class ScriptedProfiles
// display state. v1 doesn't simulate the opponent — once this lands,
// the client sits there indefinitely.
public const int OpponentTurnStartSpin = 100;
// BattleFinish result code for v1 no-contest finishes (player wins).
public const int BattleResultPlayerWins = 1;
}

View File

@@ -0,0 +1,19 @@
namespace SVSim.BattleNode.Protocol;
/// <summary>
/// Wire value of <c>result</c> on a BattleFinish frame. The client's
/// <c>BattleFinishResponsProcessing</c> switch maps these as:
/// 0 → LOSE, 1 → WIN, 2 → CONSISTENCY (desync / action-list mismatch).
/// </summary>
/// <remarks>
/// This is NOT the same as the client's in-memory <c>BATTLE_RESULT_TYPE</c> enum
/// (NONE=0, WIN=1, LOSE=2, CONSISTENCY=3) — the wire codes shift LOSE down to 0.
/// Always serialize as the int value, not the name; see the
/// <c>JsonNumberEnumConverter</c> on <see cref="Bodies.BattleFinishBody.Result"/>.
/// </remarks>
public enum BattleResult
{
Lose = 0,
Win = 1,
Consistency = 2,
}

View File

@@ -3,5 +3,7 @@ using System.Text.Json.Serialization;
namespace SVSim.BattleNode.Protocol.Bodies;
public sealed record BattleFinishBody(
[property: JsonPropertyName("result")] int Result,
[property: JsonPropertyName("result")]
[property: JsonConverter(typeof(JsonNumberEnumConverter<BattleResult>))]
BattleResult Result,
[property: JsonPropertyName("resultCode")] int ResultCode = 1) : IMsgBody;

View File

@@ -289,7 +289,7 @@ public sealed class BattleSession
Cat: EmitCategory.Battle,
PubSeq: null,
PlaySeq: null,
Body: new BattleFinishBody(Result: ScriptedProfiles.BattleResultPlayerWins));
Body: new BattleFinishBody(Result: BattleResult.Win));
private static IReadOnlyList<long> ExtractIdxList(MsgEnvelope env)
{