feat(matching): move BotRoster from hardcoded fixture to DB-backed seed

Phase 3 shipped the AI rank battle bot pool as a hardcoded 8-entry list
inlined in SVSim.EmulatedEntrypoint/Matching/BotRoster.cs — editing meant
recompiling. Per PLAN.md 2026-06-02 item (d), move it to a Bootstrap
importer so the roster lives in seeds/bot-roster.json and the DB.

Shape mirrors PracticeOpponent end-to-end:
- BotRosterEntry (SVSim.Database/Models) — PK = AiId via the Id passthrough
  pattern. DbSet<BotRosterEntry> BotRoster on SVSimDbContext.
- AddBotRoster migration (DDL only, per migrations-are-DDL-only rule).
- seeds/bot-roster.json — 8 rows preserving the current prod-verified
  cosmetic ids (sleeve 704141010 / emblem 400001100 / degree 120027 /
  field 5) and series-1 ai_ids from rm_ai_setting.csv (1111..1181).
- BotRosterSeed POCO + BotRosterImporter (idempotent upsert keyed by AiId,
  leaves seed-missing rows intact). Wired into SVSim.Bootstrap/Program.cs
  next to PracticeOpponentImporter.
- IGlobalsRepository.GetBotRoster() + impl.

IBotRoster.Pick → PickAsync because BotRoster now depends on the transient
IGlobalsRepository. RankBattleController awaits the new signature. The
deterministic hash-on-ctx invariant (same ctx → same bot, so /ai_<fmt>/start
retries pick the same opponent) is preserved.

DI: AddSingleton<IBotRoster> → AddTransient (matches IGlobalsRepository's
lifetime). Test fixture's SeedGlobalsAsync also runs the importer so
RankBattleControllerTests + the rewritten BotRosterTests both see seeded
rows.

Tests: 931 → 936 passing. Existing 3 BotRosterTests reshaped for the DB
backing + 1 new "throws on empty roster" guard; 4 new
BotRosterImporterTests mirror PracticeOpponentImporterTests
(round-trip / idempotent / seed-missing-row-intact / ai_id=0 skip).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-02 11:58:19 -04:00
parent 8aead62116
commit 24f9b2240e
18 changed files with 4653 additions and 100 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,49 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace SVSim.Database.Migrations
{
/// <inheritdoc />
public partial class AddBotRoster : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "BotRoster",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false),
AiId = table.Column<int>(type: "integer", nullable: false),
CountryCode = table.Column<string>(type: "text", nullable: false),
UserName = table.Column<string>(type: "text", nullable: false),
SleeveId = table.Column<int>(type: "integer", nullable: false),
EmblemId = table.Column<int>(type: "integer", nullable: false),
DegreeId = table.Column<int>(type: "integer", nullable: false),
FieldId = table.Column<int>(type: "integer", nullable: false),
IsOfficial = table.Column<int>(type: "integer", nullable: false),
ClassId = table.Column<int>(type: "integer", nullable: false),
CharaId = table.Column<int>(type: "integer", nullable: false),
Rank = table.Column<int>(type: "integer", nullable: false),
BattlePoint = table.Column<int>(type: "integer", nullable: false),
IsMasterRank = table.Column<int>(type: "integer", nullable: false),
MasterPoint = table.Column<int>(type: "integer", nullable: false),
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DateUpdated = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_BotRoster", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "BotRoster");
}
}
}

View File

@@ -756,6 +756,66 @@ namespace SVSim.Database.Migrations
b.ToTable("Battlefields");
});
modelBuilder.Entity("SVSim.Database.Models.BotRosterEntry", b =>
{
b.Property<int>("Id")
.HasColumnType("integer");
b.Property<int>("AiId")
.HasColumnType("integer");
b.Property<int>("BattlePoint")
.HasColumnType("integer");
b.Property<int>("CharaId")
.HasColumnType("integer");
b.Property<int>("ClassId")
.HasColumnType("integer");
b.Property<string>("CountryCode")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateUpdated")
.HasColumnType("timestamp with time zone");
b.Property<int>("DegreeId")
.HasColumnType("integer");
b.Property<int>("EmblemId")
.HasColumnType("integer");
b.Property<int>("FieldId")
.HasColumnType("integer");
b.Property<int>("IsMasterRank")
.HasColumnType("integer");
b.Property<int>("IsOfficial")
.HasColumnType("integer");
b.Property<int>("MasterPoint")
.HasColumnType("integer");
b.Property<int>("Rank")
.HasColumnType("integer");
b.Property<int>("SleeveId")
.HasColumnType("integer");
b.Property<string>("UserName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("BotRoster");
});
modelBuilder.Entity("SVSim.Database.Models.BuildDeckProductEntry", b =>
{
b.Property<int>("Id")

View File

@@ -0,0 +1,39 @@
using SVSim.Database.Common;
namespace SVSim.Database.Models;
/// <summary>
/// One row per AI bot opponent the rank-battle AI-fallback path can pick. Populated
/// from seeds/bot-roster.json by SVSim.Bootstrap.BotRosterImporter.
///
/// The Id (= AiId) MUST match a row in the client's baked-in master CSV
/// <c>data_dumps/client-assets/rm_ai_setting.csv</c>; if it doesn't, the client's
/// <c>RankMatchAISettingList.GetSettingData(aiId)</c> throws
/// <c>InvalidOperationException</c> at battle-start.
///
/// Cosmetic ids (sleeve / emblem / degree / field) MUST resolve in
/// <c>SBattleLoad.LoadOpponentAssets</c>; placeholder 1s left the client hanging on
/// "Waiting for opponent". Prod-verified values come from the Scripted bot fixture.
/// </summary>
public class BotRosterEntry : BaseEntity<int>
{
/// <summary>Client AI catalog id (rm_ai_setting.csv enemy_ai_id). Also the PK.</summary>
public int AiId { get => Id; set => Id = value; }
public string CountryCode { get; set; } = string.Empty;
public string UserName { get; set; } = string.Empty;
public int SleeveId { get; set; }
public int EmblemId { get; set; }
public int DegreeId { get; set; }
public int FieldId { get; set; }
public int IsOfficial { get; set; }
public int ClassId { get; set; }
public int CharaId { get; set; }
public int Rank { get; set; }
public int BattlePoint { get; set; }
public int IsMasterRank { get; set; }
public int MasterPoint { get; set; }
}

View File

@@ -104,4 +104,7 @@ public class GlobalsRepository : IGlobalsRepository
public Task<List<PracticeOpponentEntry>> GetPracticeOpponents() =>
_dbContext.PracticeOpponents.AsNoTracking().OrderBy(e => e.ClassId).ThenBy(e => e.Id).ToListAsync();
public Task<List<BotRosterEntry>> GetBotRoster() =>
_dbContext.BotRoster.AsNoTracking().OrderBy(e => e.ClassId).ThenBy(e => e.Id).ToListAsync();
}

View File

@@ -31,4 +31,5 @@ public interface IGlobalsRepository
Task<PreReleaseInfo?> GetPreReleaseInfo();
Task<List<ShadowverseCardSetEntry>> GetRotationCardSets();
Task<List<PracticeOpponentEntry>> GetPracticeOpponents();
Task<List<BotRosterEntry>> GetBotRoster();
}

View File

@@ -86,6 +86,7 @@ public class SVSimDbContext : DbContext
public DbSet<FeatureMaintenanceEntry> FeatureMaintenances => Set<FeatureMaintenanceEntry>();
public DbSet<PreReleaseInfo> PreReleaseInfos => Set<PreReleaseInfo>();
public DbSet<PracticeOpponentEntry> PracticeOpponents => Set<PracticeOpponentEntry>();
public DbSet<BotRosterEntry> BotRoster => Set<BotRosterEntry>();
public DbSet<PuzzleGroupEntry> PuzzleGroups => Set<PuzzleGroupEntry>();
public DbSet<PuzzleEntry> Puzzles => Set<PuzzleEntry>();
public DbSet<PuzzleMissionEntry> PuzzleMissions => Set<PuzzleMissionEntry>();