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:
4761
SVSim.Database/Migrations/20260613155613_AddArenaColosseumRun.Designer.cs
generated
Normal file
4761
SVSim.Database/Migrations/20260613155613_AddArenaColosseumRun.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
47
SVSim.Database/Models/Config/ColosseumRoundsConfig.cs
Normal file
47
SVSim.Database/Models/Config/ColosseumRoundsConfig.cs
Normal 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; }
|
||||
}
|
||||
}
|
||||
68
SVSim.Database/Models/Config/ColosseumSeasonConfig.cs
Normal file
68
SVSim.Database/Models/Config/ColosseumSeasonConfig.cs
Normal 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,
|
||||
};
|
||||
}
|
||||
105
SVSim.Database/Models/ViewerArenaColosseumRun.cs
Normal file
105
SVSim.Database/Models/ViewerArenaColosseumRun.cs
Normal 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; }
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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>();
|
||||
|
||||
@@ -1,22 +1,372 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SVSim.Database.Enums;
|
||||
using SVSim.Database.Models;
|
||||
using SVSim.Database.Models.Config;
|
||||
using SVSim.Database.Repositories.Deck;
|
||||
using SVSim.Database.Repositories.Viewer;
|
||||
using SVSim.Database.Services;
|
||||
using SVSim.Database.Services.Inventory;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.ArenaColosseum;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Common.ArenaTwoPick;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Requests.ArenaColosseum;
|
||||
using SVSim.EmulatedEntrypoint.Models.Dtos.Responses.ArenaColosseum;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Stub controller for the Colosseum arena family. Currently only emits a "no Colosseum
|
||||
/// period" /get_fee_info response so the home/arena screen doesn't 404. The full Colosseum
|
||||
/// flow (top, entry, register_deck, event_info, retire, finish, class_choose, card_choose,
|
||||
/// matchmaking) is deferred — see Wizard/ColosseumEntryInfoTask.cs for the parser surface.
|
||||
/// Arena Colosseum (Grand Prix) lobby. Phase 1 covers the three read endpoints (<c>/top</c>,
|
||||
/// <c>/get_fee_info</c>, <c>/event_info</c>) plus the entry/register-deck pair. Defaults to
|
||||
/// "no event scheduled" via <see cref="ColosseumSeasonConfig.IsColosseumPeriod"/> — flipping
|
||||
/// the event on is an admin operation per <c>docs/operations/grand-prix-event-setup.md</c>.
|
||||
/// </summary>
|
||||
[Route("arena_colosseum")]
|
||||
public class ArenaColosseumController : SVSimController
|
||||
{
|
||||
[HttpPost("get_fee_info")]
|
||||
public IActionResult GetFeeInfo([FromBody] GetFeeInfoRequest req)
|
||||
private readonly IGameConfigService _config;
|
||||
private readonly IArenaColosseumRunRepository _runs;
|
||||
private readonly IInventoryService _inventory;
|
||||
private readonly IDeckRepository _decks;
|
||||
|
||||
public ArenaColosseumController(
|
||||
IGameConfigService config,
|
||||
IArenaColosseumRunRepository runs,
|
||||
IInventoryService inventory,
|
||||
IDeckRepository decks)
|
||||
{
|
||||
if (!TryGetViewerId(out _)) return Unauthorized();
|
||||
return Ok(new GetFeeInfoResponseDto());
|
||||
_config = config;
|
||||
_runs = runs;
|
||||
_inventory = inventory;
|
||||
_decks = decks;
|
||||
}
|
||||
|
||||
[HttpPost("top")]
|
||||
public async Task<IActionResult> Top([FromBody] BaseRequest _)
|
||||
{
|
||||
if (!TryGetViewerId(out var vid)) return Unauthorized();
|
||||
|
||||
var season = _config.Get<ColosseumSeasonConfig>();
|
||||
var run = await _runs.GetByViewerIdAsync(vid);
|
||||
|
||||
var response = new TopResponse
|
||||
{
|
||||
ColosseumInfo = BuildColosseumInfo(season),
|
||||
ColosseumStatus = BuildOwnStatus(run),
|
||||
LeaderSkinId = run?.LeaderSkinId ?? 0,
|
||||
};
|
||||
|
||||
if (run is not null)
|
||||
{
|
||||
response.EntryInfo = new ColosseumEntryRef { Id = run.EntryId };
|
||||
response.NowRoundId = run.RoundId;
|
||||
response.MaxBattleCount = run.MaxBattleCountThisRound;
|
||||
response.IsFinish = run.IsChampion;
|
||||
response.FinalRoundEliminateCount = season.FinalRoundEliminateCount;
|
||||
response.EndTime = FormatTime(season.EventEndTime);
|
||||
response.BattleResults = new ColosseumBattleResults
|
||||
{
|
||||
WinCount = run.WinCount,
|
||||
ResultList = ParseIntList(run.ResultListJson),
|
||||
};
|
||||
response.BreakthroughNumber = run.BreakthroughNumberThisRound > 0 ? run.BreakthroughNumberThisRound : null;
|
||||
}
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpPost("get_fee_info")]
|
||||
public async Task<IActionResult> GetFeeInfo([FromBody] BaseRequest _)
|
||||
{
|
||||
if (!TryGetViewerId(out var vid)) return Unauthorized();
|
||||
|
||||
var season = _config.Get<ColosseumSeasonConfig>();
|
||||
var run = await _runs.GetByViewerIdAsync(vid);
|
||||
|
||||
var response = new GetFeeInfoResponseDto
|
||||
{
|
||||
ColosseumInfo = BuildColosseumInfo(season),
|
||||
ColosseumStatus = BuildOwnStatus(run),
|
||||
};
|
||||
|
||||
if (!season.IsColosseumPeriod)
|
||||
{
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
response.IsUnfinishedEntryExists = run is not null;
|
||||
response.IsAllowedFreeEntry = season.IsAllowedFreeEntry;
|
||||
response.FeeList = new ColosseumFeeList
|
||||
{
|
||||
RupyCost = season.RupyCost,
|
||||
TicketCost = season.TicketCost,
|
||||
CrystalCost = season.CrystalCost,
|
||||
};
|
||||
|
||||
if (run is not null)
|
||||
{
|
||||
response.DeckFormat = (int)run.DeckFormat;
|
||||
}
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
[HttpPost("event_info")]
|
||||
public async Task<IActionResult> EventInfo([FromBody] BaseRequest _)
|
||||
{
|
||||
if (!TryGetViewerId(out var vid)) return Unauthorized();
|
||||
|
||||
var season = _config.Get<ColosseumSeasonConfig>();
|
||||
var rounds = _config.Get<ColosseumRoundsConfig>();
|
||||
var run = await _runs.GetByViewerIdAsync(vid);
|
||||
|
||||
return Ok(new EventInfoResponse
|
||||
{
|
||||
ColosseumInfo = new ColosseumEventInfo
|
||||
{
|
||||
Format = (int)season.DeckFormat,
|
||||
StartTime = FormatTime(season.EventStartTime),
|
||||
EndTime = FormatTime(season.EventEndTime),
|
||||
AnnounceId = season.AnnounceId,
|
||||
FinalRoundEliminateCount = season.FinalRoundEliminateCount,
|
||||
},
|
||||
Round1 = BuildRoundDetail(rounds, 1),
|
||||
Round2 = BuildRoundDetail(rounds, 2),
|
||||
Round3 = BuildRoundDetail(rounds, 3),
|
||||
ColosseumStatus = BuildOwnStatus(run),
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("entry")]
|
||||
public async Task<IActionResult> Entry([FromBody] ArenaColosseumEntryRequest req)
|
||||
{
|
||||
if (!TryGetViewerId(out var vid)) return Unauthorized();
|
||||
|
||||
var season = _config.Get<ColosseumSeasonConfig>();
|
||||
if (!season.IsColosseumPeriod)
|
||||
{
|
||||
return BadRequest(new { error = "colosseum_period_closed" });
|
||||
}
|
||||
|
||||
var serverRoundId = ResolveServerRoundId(season);
|
||||
if (req.NowRoundId != serverRoundId)
|
||||
{
|
||||
return BadRequest(new { error = "now_round_id_mismatch", server_round_id = serverRoundId });
|
||||
}
|
||||
|
||||
if (await _runs.GetByViewerIdAsync(vid) is not null)
|
||||
{
|
||||
return BadRequest(new { error = "arena_colosseum_already_in_progress" });
|
||||
}
|
||||
|
||||
await using var tx = await _inventory.BeginAsync(vid);
|
||||
|
||||
RewardEntryDto? feeEntry = req.ConsumeItemType switch
|
||||
{
|
||||
1 => await DebitCrystalAsync(tx, season.CrystalCost),
|
||||
3 => await DebitTicketAsync(tx, season.TicketCost),
|
||||
4 => await DebitRupyAsync(tx, season.RupyCost),
|
||||
5 when season.IsAllowedFreeEntry => null,
|
||||
_ => throw new InvalidOperationException($"invalid consume_item_type {req.ConsumeItemType}"),
|
||||
};
|
||||
|
||||
var rounds = _config.Get<ColosseumRoundsConfig>();
|
||||
var roundConfig = rounds.Rounds.FirstOrDefault(r => r.RoundId == serverRoundId);
|
||||
var group = roundConfig?.Groups.FirstOrDefault();
|
||||
|
||||
var run = new ViewerArenaColosseumRun
|
||||
{
|
||||
ViewerId = vid,
|
||||
EntryId = 0,
|
||||
SeasonId = season.SeasonId,
|
||||
RoundId = serverRoundId,
|
||||
DeckFormat = season.DeckFormat,
|
||||
LeaderSkinId = 0,
|
||||
ConsumeItemType = req.ConsumeItemType,
|
||||
MaxBattleCountThisRound = group?.MaxBattleCount ?? 0,
|
||||
BreakthroughNumberThisRound = group?.BreakthroughNumber ?? 0,
|
||||
RestEntryNum = 0,
|
||||
};
|
||||
await _runs.UpsertAsync(run);
|
||||
run.EntryId = run.Id;
|
||||
await _runs.UpsertAsync(run);
|
||||
await tx.CommitAsync();
|
||||
|
||||
return Ok(new EntryResponse
|
||||
{
|
||||
RewardList = feeEntry is null ? new() : new() { feeEntry },
|
||||
EntryInfo = new ColosseumEntryRef
|
||||
{
|
||||
Id = run.EntryId,
|
||||
DeckFormat = (int)season.DeckFormat,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("register_deck")]
|
||||
public async Task<IActionResult> RegisterDeck([FromBody] ArenaColosseumRegisterDeckRequest req)
|
||||
{
|
||||
if (!TryGetViewerId(out var vid)) return Unauthorized();
|
||||
|
||||
var run = await _runs.GetByViewerIdAsync(vid);
|
||||
if (run is null)
|
||||
{
|
||||
return BadRequest(new { error = "no_active_run" });
|
||||
}
|
||||
|
||||
List<int> deckNos;
|
||||
try
|
||||
{
|
||||
deckNos = JsonSerializer.Deserialize<List<int>>(req.DeckNoList) ?? new();
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
return BadRequest(new { error = "deck_no_list_malformed" });
|
||||
}
|
||||
|
||||
if (deckNos.Count == 0)
|
||||
{
|
||||
return BadRequest(new { error = "deck_no_list_empty" });
|
||||
}
|
||||
|
||||
// GetDeck filters by (viewerId, format, deckNo) — a slot that exists under a different
|
||||
// format returns null here, which is the format-mismatch case from the spec.
|
||||
foreach (var no in deckNos)
|
||||
{
|
||||
var deck = await _decks.GetDeck(vid, run.DeckFormat, no);
|
||||
if (deck is null)
|
||||
{
|
||||
return BadRequest(new { error = "deck_not_found", deck_no = no });
|
||||
}
|
||||
}
|
||||
|
||||
run.RegisteredDeckNoListJson = JsonSerializer.Serialize(deckNos);
|
||||
run.IsPublished = req.IsPublished;
|
||||
await _runs.UpsertAsync(run);
|
||||
|
||||
return Ok(new { });
|
||||
}
|
||||
|
||||
private static int ResolveServerRoundId(ColosseumSeasonConfig season) => 1;
|
||||
|
||||
private async Task<RewardEntryDto> DebitCrystalAsync(IInventoryTransaction tx, int cost)
|
||||
{
|
||||
var result = await tx.TrySpendAsync(SpendCurrency.Crystal, cost);
|
||||
if (!result.Success)
|
||||
throw new InvalidOperationException("insufficient_crystal");
|
||||
return new RewardEntryDto
|
||||
{
|
||||
RewardType = (int)UserGoodsType.Crystal,
|
||||
RewardId = 0,
|
||||
RewardNum = (int)result.PostStateTotal,
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<RewardEntryDto> DebitRupyAsync(IInventoryTransaction tx, int cost)
|
||||
{
|
||||
var result = await tx.TrySpendAsync(SpendCurrency.Rupee, cost);
|
||||
if (!result.Success)
|
||||
throw new InvalidOperationException("insufficient_rupy");
|
||||
return new RewardEntryDto
|
||||
{
|
||||
RewardType = (int)UserGoodsType.Rupy,
|
||||
RewardId = 0,
|
||||
RewardNum = (int)result.PostStateTotal,
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<RewardEntryDto> DebitTicketAsync(IInventoryTransaction tx, int cost)
|
||||
{
|
||||
// Colosseum's ticket id is server-internal — using ArenaTwoPick's TicketItemId convention
|
||||
// (item id 1) until a per-season override is captured.
|
||||
const int ticketItemId = 1;
|
||||
var result = await tx.TryDebitAsync(UserGoodsType.Item, ticketItemId, cost);
|
||||
if (!result.Success)
|
||||
throw new InvalidOperationException("insufficient_ticket");
|
||||
return new RewardEntryDto
|
||||
{
|
||||
RewardType = (int)UserGoodsType.Item,
|
||||
RewardId = ticketItemId,
|
||||
RewardNum = (int)result.PostStateTotal,
|
||||
};
|
||||
}
|
||||
|
||||
// --- helpers ---
|
||||
|
||||
private static ColosseumLobbyInfo BuildColosseumInfo(ColosseumSeasonConfig season)
|
||||
{
|
||||
if (!season.IsColosseumPeriod)
|
||||
{
|
||||
return new ColosseumLobbyInfo { IsColosseumPeriod = false };
|
||||
}
|
||||
|
||||
return new ColosseumLobbyInfo
|
||||
{
|
||||
IsColosseumPeriod = true,
|
||||
DeckFormat = (int)season.DeckFormat,
|
||||
IsNormalTwoPick = season.IsNormalTwoPick ? "1" : "0",
|
||||
ColosseumName = season.ColosseumName,
|
||||
IsRoundPeriod = true,
|
||||
IsSpecialMode = season.IsSpecialMode,
|
||||
CardPoolName = string.IsNullOrEmpty(season.CardPoolName) ? null : season.CardPoolName,
|
||||
NowRound = 1,
|
||||
StartTime = FormatTime(season.EventStartTime),
|
||||
EndTime = FormatTime(season.EventEndTime),
|
||||
IsAllCardEnabled = season.IsAllCardEnabled ? 1 : 0,
|
||||
SalesPeriodInfo = new SVSim.EmulatedEntrypoint.Models.Dtos.ColosseumSalesPeriodInfo
|
||||
{
|
||||
SalesPeriodTime = FormatTime(season.SalesPeriodEnd),
|
||||
},
|
||||
StrategyPickNum = season.StrategyPickNum > 0 ? season.StrategyPickNum : null,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Builds the <c>colosseum_status</c> block. When the viewer has no run, every
|
||||
/// property is null and global WhenWritingNull renders <c>{}</c> — the client
|
||||
/// (<c>SetColosseumOwnStatus</c>) short-circuits on <c>status.Count == 0</c>.</summary>
|
||||
private static ColosseumOwnStatus BuildOwnStatus(ViewerArenaColosseumRun? run)
|
||||
{
|
||||
if (run is null) return new ColosseumOwnStatus();
|
||||
|
||||
return new ColosseumOwnStatus
|
||||
{
|
||||
RestEntryNum = run.RestEntryNum,
|
||||
NowRoundId = run.RoundId,
|
||||
IsChampion = run.IsChampion ? true : null,
|
||||
};
|
||||
}
|
||||
|
||||
private static ColosseumRoundDetail BuildRoundDetail(ColosseumRoundsConfig rounds, int roundId)
|
||||
{
|
||||
var match = rounds.Rounds.FirstOrDefault(r => r.RoundId == roundId);
|
||||
if (match is null) return new ColosseumRoundDetail();
|
||||
|
||||
return new ColosseumRoundDetail
|
||||
{
|
||||
StartTime = FormatTime(match.StartTime),
|
||||
EndTime = FormatTime(match.EndTime),
|
||||
IsNowRound = IsNowRound(match),
|
||||
RoundDetail = match.Groups.Select(g => new ColosseumGroupRow
|
||||
{
|
||||
Group = g.Group,
|
||||
MaxBattleCount = g.MaxBattleCount,
|
||||
BreakthroughNumber = g.BreakthroughNumber,
|
||||
EntryNumber = g.EntryNumber,
|
||||
}).ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
private static bool IsNowRound(ColosseumRoundsConfig.RoundEntry round)
|
||||
{
|
||||
var now = DateTime.UtcNow;
|
||||
return now >= round.StartTime && now <= round.EndTime;
|
||||
}
|
||||
|
||||
private static string FormatTime(DateTime t) =>
|
||||
t == default ? "" : t.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
private static List<int> ParseIntList(string json) =>
|
||||
string.IsNullOrEmpty(json)
|
||||
? new()
|
||||
: System.Text.Json.JsonSerializer.Deserialize<List<int>>(json) ?? new();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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<int>)</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; }
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
using MessagePack;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Models.Dtos.Requests.ArenaColosseum;
|
||||
|
||||
[MessagePackObject]
|
||||
public class GetFeeInfoRequest : BaseRequest { }
|
||||
@@ -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();
|
||||
}
|
||||
@@ -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 <= 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();
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -106,6 +106,7 @@ public class Program
|
||||
builder.Services.AddScoped<IStoryMasterRepository, StoryMasterRepository>();
|
||||
builder.Services.AddScoped<IViewerStoryProgressRepository, ViewerStoryProgressRepository>();
|
||||
builder.Services.AddScoped<IArenaTwoPickRunRepository, ArenaTwoPickRunRepository>();
|
||||
builder.Services.AddScoped<IArenaColosseumRunRepository, ArenaColosseumRunRepository>();
|
||||
builder.Services.AddScoped<IArenaTwoPickCardPoolService, ArenaTwoPickCardPoolService>();
|
||||
builder.Services.AddScoped<IArenaTwoPickService, ArenaTwoPickService>();
|
||||
builder.Services.AddScoped<IMatchContextBuilder, MatchContextBuilder>();
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SVSim.Database;
|
||||
using SVSim.Database.Enums;
|
||||
using SVSim.Database.Models;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
namespace SVSim.UnitTests.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Phase 1 entry + register-deck coverage. Activating the Colosseum season requires writing
|
||||
/// a <c>ColosseumSeason</c> + <c>ColosseumRounds</c> row to <c>GameConfigs</c> — see
|
||||
/// <see cref="ActivateSeasonAsync"/> for the test-only equivalent of the admin flow.
|
||||
/// </summary>
|
||||
public class ArenaColosseumControllerEntryTests
|
||||
{
|
||||
private static readonly object Envelope =
|
||||
new { viewer_id = "0", steam_id = 0, steam_session_ticket = "" };
|
||||
|
||||
private static async Task ActivateSeasonAsync(SVSimTestFactory factory, int crystalCost = 300)
|
||||
{
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
|
||||
var seasonJson = JsonSerializer.Serialize(new
|
||||
{
|
||||
IsColosseumPeriod = true,
|
||||
SeasonId = 42,
|
||||
ColosseumName = "Test Cup",
|
||||
DeckFormat = (int)Format.Rotation,
|
||||
CrystalCost = crystalCost,
|
||||
RupyCost = 3000,
|
||||
TicketCost = 1,
|
||||
IsAllowedFreeEntry = false,
|
||||
});
|
||||
await UpsertConfigAsync(db, "ColosseumSeason", seasonJson);
|
||||
|
||||
var roundsJson = JsonSerializer.Serialize(new
|
||||
{
|
||||
Rounds = new[]
|
||||
{
|
||||
new
|
||||
{
|
||||
RoundId = 1,
|
||||
StartTime = DateTime.UtcNow.AddDays(-1),
|
||||
EndTime = DateTime.UtcNow.AddDays(7),
|
||||
Groups = new[]
|
||||
{
|
||||
new { Group = "", MaxBattleCount = 5, BreakthroughNumber = 4, EntryNumber = 100_000 },
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
await UpsertConfigAsync(db, "ColosseumRounds", roundsJson);
|
||||
}
|
||||
|
||||
private static async Task UpsertConfigAsync(SVSimDbContext db, string section, string json)
|
||||
{
|
||||
var existing = await db.GameConfigs.FirstOrDefaultAsync(s => s.SectionName == section);
|
||||
if (existing is null)
|
||||
db.GameConfigs.Add(new GameConfigSection { SectionName = section, ValueJson = json });
|
||||
else
|
||||
existing.ValueJson = json;
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private static async Task SetViewerCurrencyAsync(SVSimTestFactory factory, long viewerId, ulong crystals = 0, ulong rupees = 0)
|
||||
{
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
var viewer = await db.Viewers.FirstAsync(v => v.Id == viewerId);
|
||||
viewer.Currency.Crystals = crystals;
|
||||
viewer.Currency.Rupees = rupees;
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Entry_debits_crystal_and_creates_run()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
await ActivateSeasonAsync(factory, crystalCost: 300);
|
||||
var viewerId = await factory.SeedViewerAsync();
|
||||
await SetViewerCurrencyAsync(factory, viewerId, crystals: 1000);
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var resp = await client.PostAsync("/arena_colosseum/entry",
|
||||
JsonContent.Create(new { consume_item_type = 1, now_round_id = 1, viewer_id = "0", steam_id = 0, steam_session_ticket = "" }));
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
using var doc = JsonDocument.Parse(body);
|
||||
var root = doc.RootElement;
|
||||
Assert.That(root.GetProperty("reward_list").GetArrayLength(), Is.EqualTo(1));
|
||||
Assert.That(root.GetProperty("reward_list")[0].GetProperty("reward_type").GetInt32(), Is.EqualTo((int)UserGoodsType.Crystal));
|
||||
Assert.That(root.GetProperty("entry_info").GetProperty("deck_format").GetInt32(), Is.EqualTo((int)Format.Rotation));
|
||||
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
var run = await db.ViewerArenaColosseumRuns.FirstOrDefaultAsync(r => r.ViewerId == viewerId);
|
||||
Assert.That(run, Is.Not.Null);
|
||||
Assert.That(run!.SeasonId, Is.EqualTo(42));
|
||||
Assert.That(run.MaxBattleCountThisRound, Is.EqualTo(5));
|
||||
Assert.That(run.BreakthroughNumberThisRound, Is.EqualTo(4));
|
||||
|
||||
var viewerAfter = await db.Viewers.FirstAsync(v => v.Id == viewerId);
|
||||
Assert.That(viewerAfter.Currency.Crystals, Is.EqualTo(700UL), "1000 - 300 cost");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Entry_rejects_when_season_inactive()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
var viewerId = await factory.SeedViewerAsync();
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var resp = await client.PostAsync("/arena_colosseum/entry",
|
||||
JsonContent.Create(new { consume_item_type = 1, now_round_id = 1, viewer_id = "0", steam_id = 0, steam_session_ticket = "" }));
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
StringAssert.Contains("colosseum_period_closed", body);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Entry_rejects_when_already_in_run()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
await ActivateSeasonAsync(factory);
|
||||
var viewerId = await factory.SeedViewerAsync();
|
||||
await SetViewerCurrencyAsync(factory, viewerId, crystals: 1000);
|
||||
|
||||
using (var scope = factory.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
db.ViewerArenaColosseumRuns.Add(new ViewerArenaColosseumRun
|
||||
{
|
||||
ViewerId = viewerId,
|
||||
EntryId = 999,
|
||||
SeasonId = 42,
|
||||
RoundId = 1,
|
||||
DeckFormat = Format.Rotation,
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
var resp = await client.PostAsync("/arena_colosseum/entry",
|
||||
JsonContent.Create(new { consume_item_type = 1, now_round_id = 1, viewer_id = "0", steam_id = 0, steam_session_ticket = "" }));
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
StringAssert.Contains("arena_colosseum_already_in_progress", body);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Entry_rejects_when_now_round_id_mismatch()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
await ActivateSeasonAsync(factory);
|
||||
var viewerId = await factory.SeedViewerAsync();
|
||||
await SetViewerCurrencyAsync(factory, viewerId, crystals: 1000);
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var resp = await client.PostAsync("/arena_colosseum/entry",
|
||||
JsonContent.Create(new { consume_item_type = 1, now_round_id = 7, viewer_id = "0", steam_id = 0, steam_session_ticket = "" }));
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
StringAssert.Contains("now_round_id_mismatch", body);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RegisterDeck_round_trips_deck_no_list()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
await ActivateSeasonAsync(factory);
|
||||
var viewerId = await factory.SeedViewerAsync();
|
||||
await factory.SeedDeckAsync(viewerId, Format.Rotation, number: 3, name: "Colo Deck 3");
|
||||
|
||||
using (var scope = factory.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
db.ViewerArenaColosseumRuns.Add(new ViewerArenaColosseumRun
|
||||
{
|
||||
ViewerId = viewerId,
|
||||
EntryId = 999,
|
||||
SeasonId = 42,
|
||||
RoundId = 1,
|
||||
DeckFormat = Format.Rotation,
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
var resp = await client.PostAsync("/arena_colosseum/register_deck",
|
||||
JsonContent.Create(new { deck_no_list = "[3]", is_published = true, viewer_id = "0", steam_id = 0, steam_session_ticket = "" }));
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
|
||||
using var verifyScope = factory.Services.CreateScope();
|
||||
var verifyDb = verifyScope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
var run = await verifyDb.ViewerArenaColosseumRuns.FirstAsync(r => r.ViewerId == viewerId);
|
||||
Assert.That(run.RegisteredDeckNoListJson, Is.EqualTo("[3]"));
|
||||
Assert.That(run.IsPublished, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task RegisterDeck_rejects_when_deck_not_found()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
await ActivateSeasonAsync(factory);
|
||||
var viewerId = await factory.SeedViewerAsync();
|
||||
|
||||
using (var scope = factory.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
db.ViewerArenaColosseumRuns.Add(new ViewerArenaColosseumRun
|
||||
{
|
||||
ViewerId = viewerId,
|
||||
EntryId = 999,
|
||||
SeasonId = 42,
|
||||
RoundId = 1,
|
||||
DeckFormat = Format.Rotation,
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
var resp = await client.PostAsync("/arena_colosseum/register_deck",
|
||||
JsonContent.Create(new { deck_no_list = "[99]", is_published = false, viewer_id = "0", steam_id = 0, steam_session_ticket = "" }));
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
StringAssert.Contains("deck_not_found", body);
|
||||
}
|
||||
}
|
||||
138
SVSim.UnitTests/Controllers/ArenaColosseumControllerTests.cs
Normal file
138
SVSim.UnitTests/Controllers/ArenaColosseumControllerTests.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SVSim.Database;
|
||||
using SVSim.Database.Enums;
|
||||
using SVSim.Database.Models;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
namespace SVSim.UnitTests.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Phase 1 lobby read coverage: /arena_colosseum/{top, get_fee_info, event_info}.
|
||||
/// Defaults (no <c>ColosseumSeason</c> override) must render an empty "no event scheduled"
|
||||
/// payload — flipping the season on is an admin operation.
|
||||
/// </summary>
|
||||
public class ArenaColosseumControllerTests
|
||||
{
|
||||
private static readonly object Envelope =
|
||||
new { viewer_id = "0", steam_id = 0, steam_session_ticket = "" };
|
||||
|
||||
[Test]
|
||||
public async Task Top_unauthenticated_returns_401()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using var client = factory.CreateClient();
|
||||
var resp = await client.PostAsync("/arena_colosseum/top", JsonContent.Create(Envelope));
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.Unauthorized));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Top_returns_no_period_when_no_season_active()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
var viewerId = await factory.SeedViewerAsync();
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var resp = await client.PostAsync("/arena_colosseum/top", JsonContent.Create(Envelope));
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
StringAssert.Contains("\"is_colosseum_period\":false", body);
|
||||
// leader_skin_id must always be emitted (even when 0) per project_wire_null_policy.
|
||||
StringAssert.Contains("\"leader_skin_id\":0", body);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetFeeInfo_returns_no_period_when_no_season_active()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
var viewerId = await factory.SeedViewerAsync();
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var resp = await client.PostAsync("/arena_colosseum/get_fee_info", JsonContent.Create(Envelope));
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
StringAssert.Contains("\"is_colosseum_period\":false", body);
|
||||
// fee_list, is_unfinished_entry_exists, deck_format must be ABSENT when no event.
|
||||
StringAssert.DoesNotContain("\"fee_list\"", body);
|
||||
StringAssert.DoesNotContain("\"is_unfinished_entry_exists\"", body);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task EventInfo_returns_empty_rounds_when_default_config()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
var viewerId = await factory.SeedViewerAsync();
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
var resp = await client.PostAsync("/arena_colosseum/event_info", JsonContent.Create(Envelope));
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
|
||||
// The rounds object MUST be string-keyed "1"/"2"/"3" — locking the wire shape per
|
||||
// event_info.md. Custom STJ converter avoided; explicit [JsonPropertyName("1"|"2"|"3")]
|
||||
// produces the same on-the-wire bytes.
|
||||
using var doc = JsonDocument.Parse(body);
|
||||
var root = doc.RootElement;
|
||||
Assert.That(root.TryGetProperty("1", out var r1), Is.True, "round '1' must be present");
|
||||
Assert.That(root.TryGetProperty("2", out var r2), Is.True, "round '2' must be present");
|
||||
Assert.That(root.TryGetProperty("3", out var r3), Is.True, "round '3' must be present");
|
||||
|
||||
// Default config → no schedule → is_now_round false on all three.
|
||||
Assert.That(r1.GetProperty("is_now_round").GetBoolean(), Is.False);
|
||||
Assert.That(r2.GetProperty("is_now_round").GetBoolean(), Is.False);
|
||||
Assert.That(r3.GetProperty("is_now_round").GetBoolean(), Is.False);
|
||||
|
||||
Assert.That(r1.GetProperty("round_detail").GetArrayLength(), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Top_round_trips_after_entry_seeded()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
var viewerId = await factory.SeedViewerAsync();
|
||||
|
||||
// Seed an active run directly — Task 3's /entry endpoint will own creation, but
|
||||
// /top must reflect the row's identity when one exists.
|
||||
const long entryId = 12_345L;
|
||||
using (var scope = factory.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
db.ViewerArenaColosseumRuns.Add(new ViewerArenaColosseumRun
|
||||
{
|
||||
ViewerId = viewerId,
|
||||
EntryId = entryId,
|
||||
SeasonId = 1,
|
||||
RoundId = 1,
|
||||
DeckFormat = Format.Rotation,
|
||||
LeaderSkinId = 0,
|
||||
ConsumeItemType = 2,
|
||||
MaxBattleCountThisRound = 5,
|
||||
BreakthroughNumberThisRound = 4,
|
||||
RestEntryNum = 0,
|
||||
WinCount = 1,
|
||||
LossCount = 0,
|
||||
ResultListJson = "[1]",
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
var resp = await client.PostAsync("/arena_colosseum/top", JsonContent.Create(Envelope));
|
||||
Assert.That(resp.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
using var doc = JsonDocument.Parse(body);
|
||||
var root = doc.RootElement;
|
||||
|
||||
Assert.That(root.GetProperty("entry_info").GetProperty("id").GetInt64(), Is.EqualTo(entryId));
|
||||
Assert.That(root.GetProperty("now_round_id").GetInt32(), Is.EqualTo(1));
|
||||
Assert.That(root.GetProperty("max_battle_count").GetInt32(), Is.EqualTo(5));
|
||||
Assert.That(root.GetProperty("battle_results").GetProperty("win_count").GetInt32(), Is.EqualTo(1));
|
||||
Assert.That(root.GetProperty("battle_results").GetProperty("result_list").GetArrayLength(), Is.EqualTo(1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NUnit.Framework;
|
||||
using SVSim.Database;
|
||||
using SVSim.Database.Models.Config;
|
||||
using SVSim.EmulatedEntrypoint.Services;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
namespace SVSim.UnitTests.Database.Config;
|
||||
|
||||
[TestFixture]
|
||||
public class ColosseumRoundsConfigTests
|
||||
{
|
||||
[Test]
|
||||
public void ShippedDefaults_emits_empty_rounds()
|
||||
{
|
||||
var cfg = ColosseumRoundsConfig.ShippedDefaults();
|
||||
Assert.That(cfg.Rounds, Is.Empty,
|
||||
"default ship state has no rounds — /event_info renders a benign empty payload");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Has_ConfigSection_attribute_with_name_ColosseumRounds()
|
||||
{
|
||||
var attr = typeof(ColosseumRoundsConfig)
|
||||
.GetCustomAttributes(typeof(ConfigSectionAttribute), false)
|
||||
.Cast<ConfigSectionAttribute>()
|
||||
.FirstOrDefault();
|
||||
Assert.That(attr, Is.Not.Null);
|
||||
Assert.That(attr!.Name, Is.EqualTo("ColosseumRounds"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_through_GameConfigService_round_trips_shipped_defaults()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
var svc = new GameConfigService(db, new ConfigurationBuilder().Build());
|
||||
|
||||
var cfg = svc.Get<ColosseumRoundsConfig>();
|
||||
|
||||
Assert.That(cfg.Rounds, Is.Empty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NUnit.Framework;
|
||||
using SVSim.Database;
|
||||
using SVSim.Database.Models.Config;
|
||||
using SVSim.EmulatedEntrypoint.Services;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
namespace SVSim.UnitTests.Database.Config;
|
||||
|
||||
[TestFixture]
|
||||
public class ColosseumSeasonConfigTests
|
||||
{
|
||||
[Test]
|
||||
public void ShippedDefaults_emits_no_period()
|
||||
{
|
||||
var cfg = ColosseumSeasonConfig.ShippedDefaults();
|
||||
Assert.That(cfg.IsColosseumPeriod, Is.False,
|
||||
"default ship state is no event scheduled — lobby reads must render the empty payload");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Has_ConfigSection_attribute_with_name_ColosseumSeason()
|
||||
{
|
||||
var attr = typeof(ColosseumSeasonConfig)
|
||||
.GetCustomAttributes(typeof(ConfigSectionAttribute), false)
|
||||
.Cast<ConfigSectionAttribute>()
|
||||
.FirstOrDefault();
|
||||
Assert.That(attr, Is.Not.Null);
|
||||
Assert.That(attr!.Name, Is.EqualTo("ColosseumSeason"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_through_GameConfigService_round_trips_shipped_defaults()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
var svc = new GameConfigService(db, new ConfigurationBuilder().Build());
|
||||
|
||||
var cfg = svc.Get<ColosseumSeasonConfig>();
|
||||
|
||||
Assert.That(cfg.IsColosseumPeriod, Is.False);
|
||||
Assert.That(cfg.PoolCardSetIds, Is.Empty);
|
||||
}
|
||||
}
|
||||
@@ -25,14 +25,14 @@ public class GameConfigurationJsonbTests
|
||||
var rows = await db.GameConfigs.AsNoTracking().ToListAsync();
|
||||
var byName = rows.ToDictionary(r => r.SectionName);
|
||||
|
||||
// One row per [ConfigSection]-marked POCO (13 sections today: Player, DefaultGrants,
|
||||
// One row per [ConfigSection]-marked POCO (15 sections today: Player, DefaultGrants,
|
||||
// DefaultLoadout, Challenge, Rotation, PackRates, MyRotationSchedule, Story, ResourceConfig,
|
||||
// Freeplay, ArenaTwoPick, Matching, CardMasterConfig).
|
||||
// Freeplay, ArenaTwoPick, Matching, CardMasterConfig, ColosseumSeason, ColosseumRounds).
|
||||
Assert.That(byName.Keys, Is.EquivalentTo(new[]
|
||||
{
|
||||
"Player", "DefaultGrants", "DefaultLoadout", "Challenge", "Rotation", "PackRates",
|
||||
"MyRotationSchedule", "Story", "ResourceConfig", "Freeplay", "ArenaTwoPick", "Matching",
|
||||
"CardMasterConfig",
|
||||
"CardMasterConfig", "ColosseumSeason", "ColosseumRounds",
|
||||
}));
|
||||
|
||||
var resources = JsonSerializer.Deserialize<ResourceConfig>(byName["ResourceConfig"].ValueJson)!;
|
||||
|
||||
Reference in New Issue
Block a user