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

View File

@@ -0,0 +1,130 @@
[
{
"ai_id": 1111,
"country_code": "JPN",
"user_name": "Forestcraft AI",
"sleeve_id": 704141010,
"emblem_id": 400001100,
"degree_id": 120027,
"field_id": 5,
"is_official": 0,
"class_id": 1,
"chara_id": 1,
"rank": 10,
"battle_point": 0,
"is_master_rank": 0,
"master_point": 0
},
{
"ai_id": 1121,
"country_code": "JPN",
"user_name": "Swordcraft AI",
"sleeve_id": 704141010,
"emblem_id": 400001100,
"degree_id": 120027,
"field_id": 5,
"is_official": 0,
"class_id": 2,
"chara_id": 2,
"rank": 10,
"battle_point": 0,
"is_master_rank": 0,
"master_point": 0
},
{
"ai_id": 1131,
"country_code": "JPN",
"user_name": "Runecraft AI",
"sleeve_id": 704141010,
"emblem_id": 400001100,
"degree_id": 120027,
"field_id": 5,
"is_official": 0,
"class_id": 3,
"chara_id": 3,
"rank": 10,
"battle_point": 0,
"is_master_rank": 0,
"master_point": 0
},
{
"ai_id": 1141,
"country_code": "JPN",
"user_name": "Dragoncraft AI",
"sleeve_id": 704141010,
"emblem_id": 400001100,
"degree_id": 120027,
"field_id": 5,
"is_official": 0,
"class_id": 4,
"chara_id": 4,
"rank": 10,
"battle_point": 0,
"is_master_rank": 0,
"master_point": 0
},
{
"ai_id": 1151,
"country_code": "JPN",
"user_name": "Shadowcraft AI",
"sleeve_id": 704141010,
"emblem_id": 400001100,
"degree_id": 120027,
"field_id": 5,
"is_official": 0,
"class_id": 5,
"chara_id": 5,
"rank": 10,
"battle_point": 0,
"is_master_rank": 0,
"master_point": 0
},
{
"ai_id": 1161,
"country_code": "JPN",
"user_name": "Bloodcraft AI",
"sleeve_id": 704141010,
"emblem_id": 400001100,
"degree_id": 120027,
"field_id": 5,
"is_official": 0,
"class_id": 6,
"chara_id": 6,
"rank": 10,
"battle_point": 0,
"is_master_rank": 0,
"master_point": 0
},
{
"ai_id": 1171,
"country_code": "JPN",
"user_name": "Havencraft AI",
"sleeve_id": 704141010,
"emblem_id": 400001100,
"degree_id": 120027,
"field_id": 5,
"is_official": 0,
"class_id": 7,
"chara_id": 7,
"rank": 10,
"battle_point": 0,
"is_master_rank": 0,
"master_point": 0
},
{
"ai_id": 1181,
"country_code": "JPN",
"user_name": "Portalcraft AI",
"sleeve_id": 704141010,
"emblem_id": 400001100,
"degree_id": 120027,
"field_id": 5,
"is_official": 0,
"class_id": 8,
"chara_id": 8,
"rank": 10,
"battle_point": 0,
"is_master_rank": 0,
"master_point": 0
}
]

View File

@@ -0,0 +1,62 @@
using Microsoft.EntityFrameworkCore;
using SVSim.Bootstrap.Models.Seed;
using SVSim.Database;
using SVSim.Database.Models;
namespace SVSim.Bootstrap.Importers;
/// <summary>
/// Idempotent upsert of AI bot opponents from <c>seeds/bot-roster.json</c>.
/// Rows missing from the seed are LEFT INTACT (consistent with PracticeOpponentImporter;
/// a partial seed shouldn't silently delete entries).
/// </summary>
public class BotRosterImporter
{
public async Task<int> ImportAsync(SVSimDbContext context, string seedDir)
{
string path = Path.Combine(seedDir, "bot-roster.json");
var seed = SeedLoader.LoadList<BotRosterSeed>(path);
if (seed.Count == 0)
{
Console.WriteLine("[BotRosterImporter] No seed rows; skipping.");
return 0;
}
var existing = await context.BotRoster.ToDictionaryAsync(e => e.Id);
int created = 0, updated = 0;
foreach (var s in seed)
{
if (s.AiId == 0) continue;
var entry = existing.TryGetValue(s.AiId, out var ex)
? ex : new BotRosterEntry { Id = s.AiId };
entry.CountryCode = s.CountryCode;
entry.UserName = s.UserName;
entry.SleeveId = s.SleeveId;
entry.EmblemId = s.EmblemId;
entry.DegreeId = s.DegreeId;
entry.FieldId = s.FieldId;
entry.IsOfficial = s.IsOfficial;
entry.ClassId = s.ClassId;
entry.CharaId = s.CharaId;
entry.Rank = s.Rank;
entry.BattlePoint = s.BattlePoint;
entry.IsMasterRank = s.IsMasterRank;
entry.MasterPoint = s.MasterPoint;
if (ex is null)
{
context.BotRoster.Add(entry);
existing[s.AiId] = entry;
created++;
}
else updated++;
}
await context.SaveChangesAsync();
Console.WriteLine($"[BotRosterImporter] +{created}/~{updated}");
return created + updated;
}
}

View File

@@ -0,0 +1,21 @@
using System.Text.Json.Serialization;
namespace SVSim.Bootstrap.Models.Seed;
public sealed class BotRosterSeed
{
[JsonPropertyName("ai_id")] public int AiId { get; set; }
[JsonPropertyName("country_code")] public string CountryCode { get; set; } = "";
[JsonPropertyName("user_name")] public string UserName { get; set; } = "";
[JsonPropertyName("sleeve_id")] public int SleeveId { get; set; }
[JsonPropertyName("emblem_id")] public int EmblemId { get; set; }
[JsonPropertyName("degree_id")] public int DegreeId { get; set; }
[JsonPropertyName("field_id")] public int FieldId { get; set; }
[JsonPropertyName("is_official")] public int IsOfficial { get; set; }
[JsonPropertyName("class_id")] public int ClassId { get; set; }
[JsonPropertyName("chara_id")] public int CharaId { get; set; }
[JsonPropertyName("rank")] public int Rank { get; set; }
[JsonPropertyName("battle_point")] public int BattlePoint { get; set; }
[JsonPropertyName("is_master_rank")] public int IsMasterRank { get; set; }
[JsonPropertyName("master_point")] public int MasterPoint { get; set; }
}

View File

@@ -97,6 +97,7 @@ public static class Program
await new RotationFlagUpdater().UpdateAsync(context);
await new PracticeOpponentImporter().ImportAsync(context, opts.SeedDir);
await new BotRosterImporter().ImportAsync(context, opts.SeedDir);
await new PaymentItemImporter().ImportAsync(context, opts.SeedDir);
await new ItemImporter().ImportAsync(context, opts.SeedDir);
await new SleeveShopImporter().ImportAsync(context, opts.SeedDir);