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

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,69 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace SVSim.Database.Migrations
{
/// <inheritdoc />
public partial class AddArenaColosseumRun : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ViewerArenaColosseumRuns",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ViewerId = table.Column<long>(type: "bigint", nullable: false),
EntryId = table.Column<long>(type: "bigint", nullable: false),
SeasonId = table.Column<int>(type: "integer", nullable: false),
RoundId = table.Column<int>(type: "integer", nullable: false),
DeckFormat = table.Column<int>(type: "integer", nullable: false),
LeaderSkinId = table.Column<long>(type: "bigint", nullable: false),
ConsumeItemType = table.Column<int>(type: "integer", nullable: false),
CandidateClassIdsJson = table.Column<string>(type: "jsonb", nullable: false),
SelectTurn = table.Column<int>(type: "integer", nullable: false),
IsSelectCompleted = table.Column<bool>(type: "boolean", nullable: false),
SelectedCardIdsJson = table.Column<string>(type: "jsonb", nullable: false),
PendingPickSetsJson = table.Column<string>(type: "jsonb", nullable: false),
NextCandidateId = table.Column<long>(type: "bigint", nullable: false),
ClassId = table.Column<int>(type: "integer", nullable: false),
ChaosId = table.Column<int>(type: "integer", nullable: false),
ResultListJson = table.Column<string>(type: "jsonb", nullable: false),
WinCount = table.Column<int>(type: "integer", nullable: false),
LossCount = table.Column<int>(type: "integer", nullable: false),
BattleCountThisRound = table.Column<int>(type: "integer", nullable: false),
MaxBattleCountThisRound = table.Column<int>(type: "integer", nullable: false),
BreakthroughNumberThisRound = table.Column<int>(type: "integer", nullable: false),
RestEntryNum = table.Column<int>(type: "integer", nullable: false),
IsRankMatching = table.Column<bool>(type: "boolean", nullable: false),
IsChampion = table.Column<bool>(type: "boolean", nullable: false),
RegisteredDeckNoListJson = table.Column<string>(type: "jsonb", nullable: false),
IsPublished = table.Column<bool>(type: "boolean", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ViewerArenaColosseumRuns", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_ViewerArenaColosseumRuns_ViewerId",
table: "ViewerArenaColosseumRuns",
column: "ViewerId",
unique: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ViewerArenaColosseumRuns");
}
}
}

View File

@@ -2766,6 +2766,111 @@ namespace SVSim.Database.Migrations
b.ToTable("ViewerAcquireHistory");
});
modelBuilder.Entity("SVSim.Database.Models.ViewerArenaColosseumRun", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<int>("BattleCountThisRound")
.HasColumnType("integer");
b.Property<int>("BreakthroughNumberThisRound")
.HasColumnType("integer");
b.Property<string>("CandidateClassIdsJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("ChaosId")
.HasColumnType("integer");
b.Property<int>("ClassId")
.HasColumnType("integer");
b.Property<int>("ConsumeItemType")
.HasColumnType("integer");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("DeckFormat")
.HasColumnType("integer");
b.Property<long>("EntryId")
.HasColumnType("bigint");
b.Property<bool>("IsChampion")
.HasColumnType("boolean");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<bool>("IsRankMatching")
.HasColumnType("boolean");
b.Property<bool>("IsSelectCompleted")
.HasColumnType("boolean");
b.Property<long>("LeaderSkinId")
.HasColumnType("bigint");
b.Property<int>("LossCount")
.HasColumnType("integer");
b.Property<int>("MaxBattleCountThisRound")
.HasColumnType("integer");
b.Property<long>("NextCandidateId")
.HasColumnType("bigint");
b.Property<string>("PendingPickSetsJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("RegisteredDeckNoListJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("RestEntryNum")
.HasColumnType("integer");
b.Property<string>("ResultListJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<int>("RoundId")
.HasColumnType("integer");
b.Property<int>("SeasonId")
.HasColumnType("integer");
b.Property<int>("SelectTurn")
.HasColumnType("integer");
b.Property<string>("SelectedCardIdsJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<DateTime>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<long>("ViewerId")
.HasColumnType("bigint");
b.Property<int>("WinCount")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ViewerId")
.IsUnique();
b.ToTable("ViewerArenaColosseumRuns");
});
modelBuilder.Entity("SVSim.Database.Models.ViewerArenaTwoPickRun", b =>
{
b.Property<long>("Id")

View File

@@ -0,0 +1,47 @@
namespace SVSim.Database.Models.Config;
/// <summary>
/// The 3-round bracket schedule for an active Colosseum season. Empty <see cref="Rounds"/>
/// is the default shipped state — lobby <c>/event_info</c> renders a benign payload with
/// no rounds active. Collection default is in <see cref="ShippedDefaults"/> per
/// feedback_config_defaults (property-initializer collection defaults silently empty out
/// under the tier merge).
/// </summary>
[ConfigSection("ColosseumRounds")]
public class ColosseumRoundsConfig
{
public List<RoundEntry> Rounds { get; set; } = new();
public static ColosseumRoundsConfig ShippedDefaults() => new()
{
Rounds = new(),
};
public class RoundEntry
{
/// <summary>1, 2, or 3 in the canonical 3-round schedule.</summary>
public int RoundId { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
/// <summary>Bracket groups within the round (e.g. distinct breakthrough thresholds
/// for late-joiners). The first entry is the canonical lookup used by
/// <c>ColosseumProgressionService</c> for the v1 single-bracket case.</summary>
public List<GroupEntry> Groups { get; set; } = new();
}
public class GroupEntry
{
public string Group { get; set; } = "";
/// <summary>Max battles a viewer can play in this round before bracket termination.</summary>
public int MaxBattleCount { get; set; }
/// <summary>Wins required to promote out of this round.</summary>
public int BreakthroughNumber { get; set; }
/// <summary>Total bracket entries allotted to this group.</summary>
public int EntryNumber { get; set; }
}
}

View File

@@ -0,0 +1,68 @@
using SVSim.Database.Enums;
namespace SVSim.Database.Models.Config;
/// <summary>
/// Event-level configuration for an active Arena Colosseum (Grand Prix) season. Default
/// <see cref="ShippedDefaults"/> emits <c>IsColosseumPeriod = false</c> so the lobby read
/// endpoints render an empty "no event scheduled" payload without crashing the client.
/// Flipping the event on is an admin operation per
/// <c>docs/operations/grand-prix-event-setup.md</c> — write a row to <c>GameConfigs</c>.
/// </summary>
[ConfigSection("ColosseumSeason")]
public class ColosseumSeasonConfig
{
/// <summary>Master gate. <c>false</c> = lobby reads render an empty info block and
/// entry rejects. The client (<c>Wizard/ColosseumEntryInfoTask.cs</c>) reads this and
/// skips parsing the rest of the colosseum_info object.</summary>
public bool IsColosseumPeriod { get; set; }
/// <summary>Stamped onto every <see cref="ViewerArenaColosseumRun"/> at entry time.</summary>
public int SeasonId { get; set; }
public string ColosseumName { get; set; } = "";
/// <summary>Bracket format. Stamped onto the run at entry time.</summary>
public Format DeckFormat { get; set; } = Format.Rotation;
/// <summary>Server stores bool; the wire shape is the STRING "0"/"1" per Wizard/ColosseumEntryInfoTask.cs's
/// <c>jsonData.ToString() == "1"</c> parse. The response DTO converts at serialization time.</summary>
public bool IsNormalTwoPick { get; set; }
/// <summary>Wire string used by the client as a theme/color code. Empty when not in special mode.</summary>
public string IsSpecialMode { get; set; } = "";
public string? AnnounceId { get; set; }
public DateTime EventStartTime { get; set; }
public DateTime EventEndTime { get; set; }
/// <summary>How many bracket entries get eliminated in the final round before champion-determination.</summary>
public int FinalRoundEliminateCount { get; set; }
public string CardPoolName { get; set; } = "";
/// <summary>Card-set ids used as the 2-Pick / Chaos draft pool override for this season.
/// Phase 3 reads this through <c>ArenaTwoPickCardPoolService</c> instead of
/// <c>ChallengeConfig.PoolCardSetIds</c>.</summary>
public List<int> PoolCardSetIds { get; set; } = new();
public int RupyCost { get; set; }
public int TicketCost { get; set; }
public int CrystalCost { get; set; }
public bool IsAllowedFreeEntry { get; set; }
public bool IsAllCardEnabled { get; set; }
/// <summary>Number of strategies offered per pick in 2-Pick Chaos mode.</summary>
public int StrategyPickNum { get; set; }
public DateTime SalesPeriodStart { get; set; }
public DateTime SalesPeriodEnd { get; set; }
public static ColosseumSeasonConfig ShippedDefaults() => new()
{
IsColosseumPeriod = false,
};
}

View File

@@ -0,0 +1,105 @@
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using SVSim.Database.Enums;
namespace SVSim.Database.Models;
/// <summary>
/// One active Grand Prix (Arena Colosseum) bracket run per viewer. Mirrors
/// <see cref="ViewerArenaTwoPickRun"/> in shape so the 2-Pick draft state machine can be
/// lifted onto it in Phase 3 — the schema is the union of constructed-mode lifecycle
/// (registered decks, bracket counts, rank-match promotion flag) and TK2-style draft
/// state. Standalone (not a Viewer owned collection) per
/// project_ef_nav_include_pitfall, with a unique index on ViewerId to enforce
/// "one active run per viewer". Row is deleted on /finish or /retire.
/// </summary>
[Index(nameof(ViewerId), IsUnique = true)]
public class ViewerArenaColosseumRun
{
public long Id { get; set; }
public long ViewerId { get; set; }
/// <summary>Wire <c>entry_info.id</c>. Set to <see cref="Id"/> on insert.</summary>
public long EntryId { get; set; }
/// <summary>Stamped from <see cref="Config.ColosseumSeasonConfig.SeasonId"/> at entry time so
/// mid-run season-config edits don't shift the run's identity.</summary>
public int SeasonId { get; set; }
/// <summary>Current bracket round (1..3 in the canonical 3-round schedule). Indexes
/// <see cref="Config.ColosseumRoundsConfig.Rounds"/> at entry time, advances on bracket
/// promotion via <c>ColosseumProgressionService</c>.</summary>
public int RoundId { get; set; }
/// <summary>Format the bracket plays in (Rotation/Unlimited/TwoPick/HOF/WindFall/Avatar/...).
/// Stamped from season config at entry time.</summary>
public Format DeckFormat { get; set; }
public long LeaderSkinId { get; set; }
/// <summary>eARENA_PAY: 1 = ticket, 2 = crystal, 3 = rupy, 0 = free entry. Stamped at entry.</summary>
public int ConsumeItemType { get; set; }
// --- 2-Pick / Chaos draft state (lifted from ViewerArenaTwoPickRun for Phase 3) ---
[Column(TypeName = "jsonb")]
public string CandidateClassIdsJson { get; set; } = "[]";
/// <summary>Stored as 0 in constructed mode (no draft turn machinery).</summary>
public int SelectTurn { get; set; }
public bool IsSelectCompleted { get; set; }
[Column(TypeName = "jsonb")]
public string SelectedCardIdsJson { get; set; } = "[]";
[Column(TypeName = "jsonb")]
public string PendingPickSetsJson { get; set; } = "[]";
/// <summary>Monotonic counter for CandidatePair.Id; advances by 2 each draft turn.</summary>
public long NextCandidateId { get; set; } = 1;
/// <summary>Selected class for 2-Pick / Chaos modes; 0 in constructed mode.</summary>
public int ClassId { get; set; }
/// <summary>Optional Chaos sub-mode replay id. 0 when not in Chaos.</summary>
public int ChaosId { get; set; }
// --- Per-round bracket state ---
[Column(TypeName = "jsonb")]
public string ResultListJson { get; set; } = "[]";
public int WinCount { get; set; }
public int LossCount { get; set; }
public int BattleCountThisRound { get; set; }
/// <summary>Cap copied from the matching <c>ColosseumRoundsConfig.Rounds[RoundId-1].Groups[0]</c>
/// at entry — stamped so mid-run round-config edits don't shift the cap.</summary>
public int MaxBattleCountThisRound { get; set; }
/// <summary>Wins required to break through to the next round. Same stamping rule as
/// <see cref="MaxBattleCountThisRound"/>.</summary>
public int BreakthroughNumberThisRound { get; set; }
/// <summary>Remaining attempts in the current entry. Decremented per battle finish until
/// 0 or breakthrough.</summary>
public int RestEntryNum { get; set; }
/// <summary>Flipped exactly once when the node signals <c>matching_state == 3008</c>.
/// Subsequent battle URLs use the <c>colosseum_rank_battle/*</c> prefix.</summary>
public bool IsRankMatching { get; set; }
public bool IsChampion { get; set; }
// --- Registered deck slot (constructed mode) ---
[Column(TypeName = "jsonb")]
public string RegisteredDeckNoListJson { get; set; } = "[]";
public bool IsPublished { get; set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
}

View File

@@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore;
using SVSim.Database.Models;
namespace SVSim.Database.Repositories.Viewer;
public class ArenaColosseumRunRepository : IArenaColosseumRunRepository
{
private readonly SVSimDbContext _db;
public ArenaColosseumRunRepository(SVSimDbContext db) => _db = db;
public Task<ViewerArenaColosseumRun?> GetByViewerIdAsync(long viewerId) =>
_db.ViewerArenaColosseumRuns.FirstOrDefaultAsync(r => r.ViewerId == viewerId);
public async Task UpsertAsync(ViewerArenaColosseumRun run)
{
run.UpdatedAt = DateTime.UtcNow;
if (run.Id == 0)
{
run.CreatedAt = DateTime.UtcNow;
_db.ViewerArenaColosseumRuns.Add(run);
}
else
{
_db.ViewerArenaColosseumRuns.Update(run);
}
await _db.SaveChangesAsync();
}
public async Task DeleteAsync(long viewerId)
{
var row = await _db.ViewerArenaColosseumRuns.FirstOrDefaultAsync(r => r.ViewerId == viewerId);
if (row is null) return;
_db.ViewerArenaColosseumRuns.Remove(row);
await _db.SaveChangesAsync();
}
}

View File

@@ -0,0 +1,10 @@
using SVSim.Database.Models;
namespace SVSim.Database.Repositories.Viewer;
public interface IArenaColosseumRunRepository
{
Task<ViewerArenaColosseumRun?> GetByViewerIdAsync(long viewerId);
Task UpsertAsync(ViewerArenaColosseumRun run);
Task DeleteAsync(long viewerId);
}

View File

@@ -107,6 +107,7 @@ public class SVSimDbContext : DbContext
public DbSet<ArenaTwoPickReward> ArenaTwoPickRewards { get; set; } = null!;
public DbSet<ViewerArenaTwoPickRun> ViewerArenaTwoPickRuns { get; set; } = null!;
public DbSet<ViewerArenaColosseumRun> ViewerArenaColosseumRuns { get; set; } = null!;
public DbSet<SerialCodeEntry> SerialCodes => Set<SerialCodeEntry>();
public DbSet<SerialCodeRewardEntry> SerialCodeRewards => Set<SerialCodeRewardEntry>();