feat(arena-colosseum): lobby + constructed entry (phase 1)

Closes 5 of arena-colosseum's 16 spec shapes (1/16 → 6/16). Lobby reads
(/top, /get_fee_info, /event_info) render an empty "no event scheduled"
payload by default; /entry + /register_deck activate via admin-flipped
ColosseumSeason + ColosseumRounds config sections.

* Schema: ViewerArenaColosseumRun standalone table (unique on ViewerId)
  with jsonb run-state columns mirroring ViewerArenaTwoPickRun.
* Config sections: ColosseumSeasonConfig (event-level), ColosseumRoundsConfig
  (the 3-round bracket). Empty defaults — IsColosseumPeriod=false.
* Migration AddArenaColosseumRun (DDL only; seed rows come from the section
  ShippedDefaults via EnsureSeedDataAsync).
* DTOs: ColosseumLobbyInfo (round-level, /top + /get_fee_info), ColosseumEventInfo
  (event-level, /event_info), ColosseumOwnStatus (shared status block),
  ColosseumEntryRef, ColosseumFeeList, ColosseumUserDeck, ColosseumBattleResults,
  ColosseumRoundDetail + ColosseumGroupRow. EventInfoResponse uses explicit
  [JsonPropertyName("1"|"2"|"3")] for the string-keyed rounds shape per spec.
* Controller: ArenaColosseumController replaces the 1-action stub with
  the five lifecycle endpoints. /top emits leader_skin_id even when 0
  (project_wire_null_policy override).
* Tests: 11 controller-level tests + 6 config round-trip tests covering
  empty-season payloads, run-seeded /top round-trip, crystal/rupy entry
  debits, now_round_id mismatch rejection, deck_no_list round-trip + reject.
This commit is contained in:
gamer147
2026-06-13 12:16:22 -04:00
parent a5fe484775
commit 110867358c
30 changed files with 6474 additions and 42 deletions

View File

@@ -0,0 +1,15 @@
using System.Text.Json.Serialization;
using MessagePack;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.ArenaColosseum;
[MessagePackObject]
public class ColosseumBattleResults
{
[JsonPropertyName("win_count")] [Key("win_count")]
public int WinCount { get; set; }
/// <summary>0 = loss, 1 = win. Client iterates as bool list.</summary>
[JsonPropertyName("result_list")] [Key("result_list")]
public List<int> ResultList { get; set; } = new();
}

View File

@@ -0,0 +1,16 @@
using System.Text.Json.Serialization;
using MessagePack;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.ArenaColosseum;
/// <summary>Wire <c>entry_info</c> object on <c>/top</c> and <c>/entry</c>. Reused across endpoints.</summary>
[MessagePackObject]
public class ColosseumEntryRef
{
[JsonPropertyName("id")] [Key("id")]
public long Id { get; set; }
/// <summary>Used by <c>/entry</c> only — Format enum integer. Top emits via colosseum_info.</summary>
[JsonPropertyName("deck_format")] [Key("deck_format")]
public int? DeckFormat { get; set; }
}

View File

@@ -0,0 +1,63 @@
using System.Text.Json.Serialization;
using MessagePack;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.ArenaColosseum;
/// <summary>
/// Event-level descriptor used by <c>/event_info</c> only — distinct shape from
/// <see cref="ColosseumInfo"/>: only <c>format</c>, the event window, the announce id,
/// and the final-round eliminate count. The client's <c>ColosseumDetailTask</c> reads
/// these five fields plus the three string-keyed rounds.
/// </summary>
[MessagePackObject]
public class ColosseumEventInfo
{
/// <summary>Event format. Mapped via <c>ApiRuleParseAndSet</c> on the client.</summary>
[JsonPropertyName("format")] [Key("format")]
public int Format { get; set; }
[JsonPropertyName("start_time")] [Key("start_time")]
public string StartTime { get; set; } = "";
[JsonPropertyName("end_time")] [Key("end_time")]
public string EndTime { get; set; } = "";
/// <summary>Optional — emit <c>null</c> when no announce content is configured.</summary>
[JsonPropertyName("announce_id")] [Key("announce_id")]
public string? AnnounceId { get; set; }
[JsonPropertyName("final_round_eliminate_count")] [Key("final_round_eliminate_count")]
public int FinalRoundEliminateCount { get; set; }
}
[MessagePackObject]
public class ColosseumRoundDetail
{
[JsonPropertyName("start_time")] [Key("start_time")]
public string StartTime { get; set; } = "";
[JsonPropertyName("end_time")] [Key("end_time")]
public string EndTime { get; set; } = "";
[JsonPropertyName("is_now_round")] [Key("is_now_round")]
public bool IsNowRound { get; set; }
[JsonPropertyName("round_detail")] [Key("round_detail")]
public List<ColosseumGroupRow> RoundDetail { get; set; } = new();
}
[MessagePackObject]
public class ColosseumGroupRow
{
[JsonPropertyName("group")] [Key("group")]
public string Group { get; set; } = "";
[JsonPropertyName("max_battle_count")] [Key("max_battle_count")]
public int MaxBattleCount { get; set; }
[JsonPropertyName("breakthrough_number")] [Key("breakthrough_number")]
public int BreakthroughNumber { get; set; }
[JsonPropertyName("entry_number")] [Key("entry_number")]
public int EntryNumber { get; set; }
}

View File

@@ -0,0 +1,17 @@
using System.Text.Json.Serialization;
using MessagePack;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.ArenaColosseum;
[MessagePackObject]
public class ColosseumFeeList
{
[JsonPropertyName("rupy_cost")] [Key("rupy_cost")]
public int RupyCost { get; set; }
[JsonPropertyName("ticket_cost")] [Key("ticket_cost")]
public int TicketCost { get; set; }
[JsonPropertyName("crystal_cost")] [Key("crystal_cost")]
public int CrystalCost { get; set; }
}

View File

@@ -0,0 +1,81 @@
using System.Text.Json.Serialization;
using MessagePack;
using SVSim.EmulatedEntrypoint.Models.Dtos;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.ArenaColosseum;
/// <summary>
/// Round-level Colosseum descriptor. Shared by <c>/top</c> and <c>/get_fee_info</c> via
/// the client's static <c>ColosseumEntryInfoTask.SetColosseumInfo</c> helper. When
/// <see cref="IsColosseumPeriod"/> is <c>false</c>, the client skips parsing every other
/// field — server still emits this minimal payload so the lobby renders cleanly.
/// <para>
/// Distinct from <see cref="SVSim.EmulatedEntrypoint.Models.Dtos.ColosseumInfo"/> (the
/// captured prod <c>/mypage/index</c> shape — stringly-typed and read-only). This is the
/// per-endpoint Colosseum-family shape. <c>/event_info</c> uses yet a third shape —
/// <see cref="ColosseumEventInfo"/>.
/// </para>
/// </summary>
[MessagePackObject]
public class ColosseumLobbyInfo
{
/// <summary>Master gate. <c>false</c> = lobby renders empty.</summary>
[JsonPropertyName("is_colosseum_period")] [Key("is_colosseum_period")]
public bool IsColosseumPeriod { get; set; }
/// <summary>Format enum (Rotation=0, Unlimited=1, TwoPick=10, HOF=31, ...).</summary>
[JsonPropertyName("deck_format")] [Key("deck_format")]
public int? DeckFormat { get; set; }
/// <summary>STRING wire shape: <c>"0"</c>/<c>"1"</c>. Client parses with
/// <c>jsonData.ToString() == "1"</c>.</summary>
[JsonPropertyName("is_normal_two_pick")] [Key("is_normal_two_pick")]
public string? IsNormalTwoPick { get; set; }
[JsonPropertyName("colosseum_name")] [Key("colosseum_name")]
public string? ColosseumName { get; set; }
[JsonPropertyName("is_round_period")] [Key("is_round_period")]
public bool? IsRoundPeriod { get; set; }
/// <summary>Wire STRING used by the client as a UI color/theme code.</summary>
[JsonPropertyName("is_special_mode")] [Key("is_special_mode")]
public string? IsSpecialMode { get; set; }
[JsonPropertyName("card_pool_name")] [Key("card_pool_name")]
public string? CardPoolName { get; set; }
/// <summary>Present during round period — current stage number (1..3).</summary>
[JsonPropertyName("now_round")] [Key("now_round")]
public int? NowRound { get; set; }
/// <summary>Present outside round period — next stage number.</summary>
[JsonPropertyName("next_round")] [Key("next_round")]
public int? NextRound { get; set; }
[JsonPropertyName("start_time")] [Key("start_time")]
public string? StartTime { get; set; }
[JsonPropertyName("end_time")] [Key("end_time")]
public string? EndTime { get; set; }
[JsonPropertyName("is_display_tips")] [Key("is_display_tips")]
public int? IsDisplayTips { get; set; }
[JsonPropertyName("colosseum_id")] [Key("colosseum_id")]
public int? ColosseumId { get; set; }
[JsonPropertyName("tips_id")] [Key("tips_id")]
public int? TipsId { get; set; }
[JsonPropertyName("is_all_card_enabled")] [Key("is_all_card_enabled")]
public int? IsAllCardEnabled { get; set; }
/// <summary>Reuses the captured <c>/mypage/index</c> shape — single
/// <c>sales_period_time</c> field per prod capture.</summary>
[JsonPropertyName("sales_period_info")] [Key("sales_period_info")]
public ColosseumSalesPeriodInfo? SalesPeriodInfo { get; set; }
[JsonPropertyName("strategy_pick_num")] [Key("strategy_pick_num")]
public int? StrategyPickNum { get; set; }
}

View File

@@ -0,0 +1,33 @@
using System.Text.Json.Serialization;
using MessagePack;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.ArenaColosseum;
/// <summary>
/// Per-viewer Colosseum state. All fields optional — when the viewer has no run, ALL fields
/// are null and the global <c>WhenWritingNull</c> policy renders this as <c>{}</c>, which
/// the client's <c>SetColosseumOwnStatus</c> short-circuits with <c>status.Count != 0</c>.
/// </summary>
[MessagePackObject]
public class ColosseumOwnStatus
{
[JsonPropertyName("rest_entry_num")] [Key("rest_entry_num")]
public int? RestEntryNum { get; set; }
[JsonPropertyName("now_round_id")] [Key("now_round_id")]
public int? NowRoundId { get; set; }
[JsonPropertyName("next_round_id")] [Key("next_round_id")]
public int? NextRoundId { get; set; }
[JsonPropertyName("is_last_day")] [Key("is_last_day")]
public bool? IsLastDay { get; set; }
[JsonPropertyName("is_champion")] [Key("is_champion")]
public bool? IsChampion { get; set; }
/// <summary>Only present when <see cref="IsChampion"/> is true — client uses it to overwrite
/// <c>ColosseumData.Name</c> for the champion screen.</summary>
[JsonPropertyName("colosseum_name")] [Key("colosseum_name")]
public string? ColosseumName { get; set; }
}

View File

@@ -0,0 +1,26 @@
using System.Text.Json.Serialization;
using MessagePack;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.ArenaColosseum;
/// <summary>Lightweight deck-info shape for <c>/top</c>'s <c>user_deck[0]</c>. The client's
/// <c>DeckData.Initialize</c> consumes the canonical deck shape; this is the minimum needed
/// to render the deck preview in Phase 1.</summary>
[MessagePackObject]
public class ColosseumUserDeck
{
[JsonPropertyName("deck_id")] [Key("deck_id")]
public long DeckId { get; set; }
[JsonPropertyName("class_id")] [Key("class_id")]
public int ClassId { get; set; }
[JsonPropertyName("card_list")] [Key("card_list")]
public List<long> CardList { get; set; } = new();
[JsonPropertyName("sleeve_id")] [Key("sleeve_id")]
public long? SleeveId { get; set; }
[JsonPropertyName("skin_id")] [Key("skin_id")]
public long? SkinId { get; set; }
}

View File

@@ -0,0 +1,22 @@
using System.Text.Json.Serialization;
using MessagePack;
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests.ArenaColosseum;
/// <summary>
/// <c>POST /arena_colosseum/entry</c> — pay the entry cost and start a Colosseum bracket
/// attempt. Maps to <c>Wizard/ColosseumEntryTask.ColosseumEntryTaskParam</c>.
/// </summary>
[MessagePackObject(keyAsPropertyName: false)]
public class ArenaColosseumEntryRequest : BaseRequest
{
/// <summary>Currency selector — eARENA_PAY enum. 1=Crystal, 3=Ticket, 4=Rupy, 5=Free.</summary>
[JsonPropertyName("consume_item_type")] [Key("consume_item_type")]
public int ConsumeItemType { get; set; }
/// <summary>Client-echoed round id from the most recent <c>/get_fee_info</c> or <c>/top</c>.
/// Server rejects if it disagrees with the current server-decided round.</summary>
[JsonPropertyName("now_round_id")] [Key("now_round_id")]
public int NowRoundId { get; set; }
}

View File

@@ -0,0 +1,22 @@
using System.Text.Json.Serialization;
using MessagePack;
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests.ArenaColosseum;
/// <summary>
/// <c>POST /arena_colosseum/register_deck</c> — submit deck slot(s) for a constructed-format
/// entry. Same wire gotcha as <c>arena_competition/register_deck</c> et al — <see cref="DeckNoList"/>
/// is a JSON-encoded STRING like <c>"[3,4,5]"</c>, not an array. The server parses it.
/// </summary>
[MessagePackObject(keyAsPropertyName: false)]
public class ArenaColosseumRegisterDeckRequest : BaseRequest
{
/// <summary>JSON-encoded list of deck slot numbers. Client does <c>JsonMapper.ToJson(List&lt;int&gt;)</c>.</summary>
[JsonPropertyName("deck_no_list")] [Key("deck_no_list")]
public string DeckNoList { get; set; } = "[]";
/// <summary>Server-stored visibility flag — does not affect bracket play.</summary>
[JsonPropertyName("is_published")] [Key("is_published")]
public bool IsPublished { get; set; }
}

View File

@@ -1,6 +0,0 @@
using MessagePack;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests.ArenaColosseum;
[MessagePackObject]
public class GetFeeInfoRequest : BaseRequest { }

View File

@@ -0,0 +1,22 @@
using System.Text.Json.Serialization;
using MessagePack;
using SVSim.EmulatedEntrypoint.Models.Dtos.ArenaColosseum;
using SVSim.EmulatedEntrypoint.Models.Dtos.Common.ArenaTwoPick;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaColosseum;
/// <summary>
/// <c>POST /arena_colosseum/entry</c>. Sparse — only <c>reward_list</c> (wallet debit) +
/// <c>entry_info.deck_format</c>. Client refreshes full lobby state via the next <c>/top</c>.
/// Reuses <see cref="RewardEntryDto"/> from arena-two-pick — the wire shape is identical
/// (<c>reward_type/reward_id/reward_num</c> per <c>UpdateHaveUserGoodsNumByJsonData</c>).
/// </summary>
[MessagePackObject]
public class EntryResponse
{
[JsonPropertyName("reward_list")] [Key("reward_list")]
public List<RewardEntryDto> RewardList { get; set; } = new();
[JsonPropertyName("entry_info")] [Key("entry_info")]
public ColosseumEntryRef EntryInfo { get; set; } = new();
}

View File

@@ -0,0 +1,31 @@
using System.Text.Json.Serialization;
using MessagePack;
using SVSim.EmulatedEntrypoint.Models.Dtos.ArenaColosseum;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaColosseum;
/// <summary>
/// <c>POST /arena_colosseum/event_info</c>. The 3-round Colosseum bracket descriptor — note
/// the rounds are STRING-keyed (<c>"1"</c>, <c>"2"</c>, <c>"3"</c>), NOT an array. The
/// client iterates <c>for (i = 1; i &lt;= 3; i++) jsonData[i.ToString()]</c>. Using three
/// explicit <c>[JsonPropertyName("1"|"2"|"3")]</c> properties is simpler than a custom STJ
/// converter and round-trips cleanly through MessagePack via matching <c>[Key("1"|...)]</c>.
/// </summary>
[MessagePackObject]
public class EventInfoResponse
{
[JsonPropertyName("colosseum_info")] [Key("colosseum_info")]
public ColosseumEventInfo ColosseumInfo { get; set; } = new();
[JsonPropertyName("1")] [Key("1")]
public ColosseumRoundDetail Round1 { get; set; } = new();
[JsonPropertyName("2")] [Key("2")]
public ColosseumRoundDetail Round2 { get; set; } = new();
[JsonPropertyName("3")] [Key("3")]
public ColosseumRoundDetail Round3 { get; set; } = new();
[JsonPropertyName("colosseum_status")] [Key("colosseum_status")]
public ColosseumOwnStatus ColosseumStatus { get; set; } = new();
}

View File

@@ -1,39 +1,46 @@
using System.Text.Json.Serialization;
using MessagePack;
using SVSim.EmulatedEntrypoint.Models.Dtos.ArenaColosseum;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaColosseum;
/// <summary>
/// Minimum-viable stub for /arena_colosseum/get_fee_info — emits is_colosseum_period:false
/// so the client (Wizard/ColosseumEntryInfoTask.cs:99) skips the rest of the parse and the
/// home/arena screen renders without 404ing. TODO: implement the full Colosseum entry flow
/// when the Colosseum format is brought online.
/// <c>POST /arena_colosseum/get_fee_info</c> — pre-entry oracle. Most fields are optional;
/// presence drives the lobby state machine on the client side
/// (<c>Wizard/ColosseumEntryInfoTask.cs</c>). When no season is active, only
/// <see cref="ColosseumInfo"/> + <see cref="ColosseumStatus"/> are emitted (the former with
/// <c>is_colosseum_period:false</c>, the latter as <c>{}</c> via WhenWritingNull stripping).
/// </summary>
[MessagePackObject]
public class GetFeeInfoResponseDto
{
/// <summary>
/// Per-viewer Colosseum entry status (rest_entry_num, now_round_id, is_last_day, etc.).
/// Empty object — client (ColosseumEntryInfoTask.cs:146) guards with `if (status.Count != 0)`,
/// so an empty dict short-circuits cleanly.
/// </summary>
[JsonPropertyName("colosseum_status")] [Key("colosseum_status")]
public ColosseumStatusDto ColosseumStatus { get; set; } = new();
[JsonPropertyName("colosseum_info")] [Key("colosseum_info")]
public ColosseumInfoDto ColosseumInfo { get; set; } = new();
}
public ColosseumLobbyInfo ColosseumInfo { get; set; } = new();
[MessagePackObject]
public class ColosseumStatusDto { }
[JsonPropertyName("colosseum_status")] [Key("colosseum_status")]
public ColosseumOwnStatus ColosseumStatus { get; set; } = new();
[MessagePackObject]
public class ColosseumInfoDto
{
/// <summary>
/// false = no Colosseum event running. Client (ColosseumEntryInfoTask.cs:100) gates every
/// other field on this — emitting false is what lets us ship an otherwise-empty info block.
/// </summary>
[JsonPropertyName("is_colosseum_period")] [Key("is_colosseum_period")]
public bool IsColosseumPeriod { get; set; } = false;
[JsonPropertyName("is_unfinished_entry_exists")] [Key("is_unfinished_entry_exists")]
public bool? IsUnfinishedEntryExists { get; set; }
[JsonPropertyName("is_allowed_free_entry")] [Key("is_allowed_free_entry")]
public bool? IsAllowedFreeEntry { get; set; }
[JsonPropertyName("fee_list")] [Key("fee_list")]
public ColosseumFeeList? FeeList { get; set; }
[JsonPropertyName("deck_format")] [Key("deck_format")]
public int? DeckFormat { get; set; }
[JsonPropertyName("is_able_to_join_round_3")] [Key("is_able_to_join_round_3")]
public bool? IsAbleToJoinRound3 { get; set; }
[JsonPropertyName("is_already_entry_final_round")] [Key("is_already_entry_final_round")]
public bool? IsAlreadyEntryFinalRound { get; set; }
[JsonPropertyName("is_deck_deleted")] [Key("is_deck_deleted")]
public bool? IsDeckDeleted { get; set; }
[JsonPropertyName("two_pick_status")] [Key("two_pick_status")]
public int? TwoPickStatus { get; set; }
}

View File

@@ -0,0 +1,61 @@
using System.Text.Json.Serialization;
using MessagePack;
using SVSim.EmulatedEntrypoint.Models.Dtos.ArenaColosseum;
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaColosseum;
/// <summary>
/// <c>POST /arena_colosseum/top</c> — lobby state for an in-progress run. When no season is
/// active <see cref="ColosseumInfo.IsColosseumPeriod"/> is <c>false</c> and most other
/// fields are absent (the client guards on that flag before reading anything else).
/// </summary>
[MessagePackObject]
public class TopResponse
{
[JsonPropertyName("entry_info")] [Key("entry_info")]
public ColosseumEntryRef EntryInfo { get; set; } = new();
[JsonPropertyName("colosseum_info")] [Key("colosseum_info")]
public ColosseumLobbyInfo ColosseumInfo { get; set; } = new();
[JsonPropertyName("colosseum_status")] [Key("colosseum_status")]
public ColosseumOwnStatus ColosseumStatus { get; set; } = new();
[JsonPropertyName("now_round_id")] [Key("now_round_id")]
public int NowRoundId { get; set; }
[JsonPropertyName("user_deck")] [Key("user_deck")]
public List<ColosseumUserDeck> UserDeck { get; set; } = new();
[JsonPropertyName("max_battle_count")] [Key("max_battle_count")]
public int MaxBattleCount { get; set; }
[JsonPropertyName("is_finish")] [Key("is_finish")]
public bool IsFinish { get; set; }
[JsonPropertyName("final_round_eliminate_count")] [Key("final_round_eliminate_count")]
public int FinalRoundEliminateCount { get; set; }
[JsonPropertyName("end_time")] [Key("end_time")]
public string EndTime { get; set; } = "";
[JsonPropertyName("battle_results")] [Key("battle_results")]
public ColosseumBattleResults BattleResults { get; set; } = new();
[JsonPropertyName("breakthrough_number")] [Key("breakthrough_number")]
public int? BreakthroughNumber { get; set; }
[JsonPropertyName("box_grade_list")] [Key("box_grade_list")]
public List<int>? BoxGradeList { get; set; }
[JsonPropertyName("selected_chaos_id")] [Key("selected_chaos_id")]
public int? SelectedChaosId { get; set; }
/// <summary>ALWAYS emitted, even when 0. <c>WhenWritingNull</c> would strip this otherwise —
/// see <c>project_wire_null_policy</c>: client does <c>jsonData["leader_skin_id"].ToInt()</c>
/// unguarded, which throws a KeyNotFoundException if absent.</summary>
[JsonPropertyName("leader_skin_id")]
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
[Key("leader_skin_id")]
public long LeaderSkinId { get; set; }
}