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:
130
SVSim.Bootstrap/Data/seeds/bot-roster.json
Normal file
130
SVSim.Bootstrap/Data/seeds/bot-roster.json
Normal 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
|
||||
}
|
||||
]
|
||||
62
SVSim.Bootstrap/Importers/BotRosterImporter.cs
Normal file
62
SVSim.Bootstrap/Importers/BotRosterImporter.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
21
SVSim.Bootstrap/Models/Seed/BotRosterSeed.cs
Normal file
21
SVSim.Bootstrap/Models/Seed/BotRosterSeed.cs
Normal 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; }
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
4103
SVSim.Database/Migrations/20260602155321_AddBotRoster.Designer.cs
generated
Normal file
4103
SVSim.Database/Migrations/20260602155321_AddBotRoster.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
49
SVSim.Database/Migrations/20260602155321_AddBotRoster.cs
Normal file
49
SVSim.Database/Migrations/20260602155321_AddBotRoster.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
39
SVSim.Database/Models/BotRosterEntry.cs
Normal file
39
SVSim.Database/Models/BotRosterEntry.cs
Normal 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; }
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -31,4 +31,5 @@ public interface IGlobalsRepository
|
||||
Task<PreReleaseInfo?> GetPreReleaseInfo();
|
||||
Task<List<ShadowverseCardSetEntry>> GetRotationCardSets();
|
||||
Task<List<PracticeOpponentEntry>> GetPracticeOpponents();
|
||||
Task<List<BotRosterEntry>> GetBotRoster();
|
||||
}
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -180,7 +180,7 @@ public sealed class RankBattleController : ControllerBase
|
||||
return Ok(new AiBattleStartResponseDto { AiId = -1 });
|
||||
}
|
||||
|
||||
var bot = _botRoster.Pick(selfCtx);
|
||||
var bot = await _botRoster.PickAsync(selfCtx, ct);
|
||||
|
||||
// Per spec, ai-start.md TODO: turnState semantics unclear. Default 0 (player first).
|
||||
return Ok(new AiBattleStartResponseDto
|
||||
|
||||
@@ -1,98 +1,55 @@
|
||||
using SVSim.BattleNode.Bridge;
|
||||
using SVSim.Database.Models;
|
||||
using SVSim.Database.Repositories.Globals;
|
||||
|
||||
namespace SVSim.EmulatedEntrypoint.Matching;
|
||||
|
||||
/// <summary>
|
||||
/// Phase 3 hardcoded fixture: one stub bot per class (1..8). <c>ai_id</c> values are
|
||||
/// the "series 1" tier from the client's <c>rm_ai_setting.csv</c> master table
|
||||
/// (<c>1111</c>=Forest, <c>1121</c>=Sword, … <c>1181</c>=Portal). The client's
|
||||
/// <c>RankMatchAISettingList.GetSettingData(aiId)</c> calls <c>.First(...)</c> against
|
||||
/// this table and throws <c>InvalidOperationException</c> if the id is absent — so the
|
||||
/// ids MUST match. See <c>data_dumps/client-assets/rm_ai_setting.csv</c> for the full
|
||||
/// catalog (32 rows: classes 1-8 × tiers 1-2 × deck variants 1-2).
|
||||
/// DB-backed bot roster. Reads <c>BotRoster</c> rows (seeded from
|
||||
/// <c>seeds/bot-roster.json</c>) and picks one deterministically per
|
||||
/// <see cref="MatchContext"/>. See <see cref="IBotRoster"/> for the contract.
|
||||
/// </summary>
|
||||
public sealed class BotRoster : IBotRoster
|
||||
{
|
||||
// Cosmetic ids (sleeve / emblem / degree / field) intentionally use safe
|
||||
// default values that match the master tables shipped in the project.
|
||||
// The client-side AI catalog reads ai_id but renders cosmetics from the
|
||||
// sleeveId/emblemId/etc returned here.
|
||||
private static readonly IReadOnlyList<AIBotProfile> Roster = new[]
|
||||
{
|
||||
new AIBotProfile(AiId: 1111, CountryCode: "JPN", UserName: "Forestcraft AI",
|
||||
// Cosmetic ids mirror the Scripted bot's prod-verified values
|
||||
// (ScriptedProfiles / ScriptedBotParticipant.Context). Placeholder
|
||||
// ids of 1 failed to resolve in ResourcesManager.LoadAssetGroupSync —
|
||||
// LoadOpponentAssets (SBattleLoad.cs:933) hangs forever waiting for
|
||||
// missing assets and the "Waiting for opponent" UI never closes.
|
||||
SleeveId: 704141010, EmblemId: 400001100, DegreeId: 120027, FieldId: 5, IsOfficial: 0,
|
||||
ClassId: 1, CharaId: 1, Rank: 10, BattlePoint: 0, IsMasterRank: 0, MasterPoint: 0),
|
||||
new AIBotProfile(AiId: 1121, CountryCode: "JPN", UserName: "Swordcraft AI",
|
||||
// Cosmetic ids mirror the Scripted bot's prod-verified values
|
||||
// (ScriptedProfiles / ScriptedBotParticipant.Context). Placeholder
|
||||
// ids of 1 failed to resolve in ResourcesManager.LoadAssetGroupSync —
|
||||
// LoadOpponentAssets (SBattleLoad.cs:933) hangs forever waiting for
|
||||
// missing assets and the "Waiting for opponent" UI never closes.
|
||||
SleeveId: 704141010, EmblemId: 400001100, DegreeId: 120027, FieldId: 5, IsOfficial: 0,
|
||||
ClassId: 2, CharaId: 2, Rank: 10, BattlePoint: 0, IsMasterRank: 0, MasterPoint: 0),
|
||||
new AIBotProfile(AiId: 1131, CountryCode: "JPN", UserName: "Runecraft AI",
|
||||
// Cosmetic ids mirror the Scripted bot's prod-verified values
|
||||
// (ScriptedProfiles / ScriptedBotParticipant.Context). Placeholder
|
||||
// ids of 1 failed to resolve in ResourcesManager.LoadAssetGroupSync —
|
||||
// LoadOpponentAssets (SBattleLoad.cs:933) hangs forever waiting for
|
||||
// missing assets and the "Waiting for opponent" UI never closes.
|
||||
SleeveId: 704141010, EmblemId: 400001100, DegreeId: 120027, FieldId: 5, IsOfficial: 0,
|
||||
ClassId: 3, CharaId: 3, Rank: 10, BattlePoint: 0, IsMasterRank: 0, MasterPoint: 0),
|
||||
new AIBotProfile(AiId: 1141, CountryCode: "JPN", UserName: "Dragoncraft AI",
|
||||
// Cosmetic ids mirror the Scripted bot's prod-verified values
|
||||
// (ScriptedProfiles / ScriptedBotParticipant.Context). Placeholder
|
||||
// ids of 1 failed to resolve in ResourcesManager.LoadAssetGroupSync —
|
||||
// LoadOpponentAssets (SBattleLoad.cs:933) hangs forever waiting for
|
||||
// missing assets and the "Waiting for opponent" UI never closes.
|
||||
SleeveId: 704141010, EmblemId: 400001100, DegreeId: 120027, FieldId: 5, IsOfficial: 0,
|
||||
ClassId: 4, CharaId: 4, Rank: 10, BattlePoint: 0, IsMasterRank: 0, MasterPoint: 0),
|
||||
new AIBotProfile(AiId: 1151, CountryCode: "JPN", UserName: "Shadowcraft AI",
|
||||
// Cosmetic ids mirror the Scripted bot's prod-verified values
|
||||
// (ScriptedProfiles / ScriptedBotParticipant.Context). Placeholder
|
||||
// ids of 1 failed to resolve in ResourcesManager.LoadAssetGroupSync —
|
||||
// LoadOpponentAssets (SBattleLoad.cs:933) hangs forever waiting for
|
||||
// missing assets and the "Waiting for opponent" UI never closes.
|
||||
SleeveId: 704141010, EmblemId: 400001100, DegreeId: 120027, FieldId: 5, IsOfficial: 0,
|
||||
ClassId: 5, CharaId: 5, Rank: 10, BattlePoint: 0, IsMasterRank: 0, MasterPoint: 0),
|
||||
new AIBotProfile(AiId: 1161, CountryCode: "JPN", UserName: "Bloodcraft AI",
|
||||
// Cosmetic ids mirror the Scripted bot's prod-verified values
|
||||
// (ScriptedProfiles / ScriptedBotParticipant.Context). Placeholder
|
||||
// ids of 1 failed to resolve in ResourcesManager.LoadAssetGroupSync —
|
||||
// LoadOpponentAssets (SBattleLoad.cs:933) hangs forever waiting for
|
||||
// missing assets and the "Waiting for opponent" UI never closes.
|
||||
SleeveId: 704141010, EmblemId: 400001100, DegreeId: 120027, FieldId: 5, IsOfficial: 0,
|
||||
ClassId: 6, CharaId: 6, Rank: 10, BattlePoint: 0, IsMasterRank: 0, MasterPoint: 0),
|
||||
new AIBotProfile(AiId: 1171, CountryCode: "JPN", UserName: "Havencraft AI",
|
||||
// Cosmetic ids mirror the Scripted bot's prod-verified values
|
||||
// (ScriptedProfiles / ScriptedBotParticipant.Context). Placeholder
|
||||
// ids of 1 failed to resolve in ResourcesManager.LoadAssetGroupSync —
|
||||
// LoadOpponentAssets (SBattleLoad.cs:933) hangs forever waiting for
|
||||
// missing assets and the "Waiting for opponent" UI never closes.
|
||||
SleeveId: 704141010, EmblemId: 400001100, DegreeId: 120027, FieldId: 5, IsOfficial: 0,
|
||||
ClassId: 7, CharaId: 7, Rank: 10, BattlePoint: 0, IsMasterRank: 0, MasterPoint: 0),
|
||||
new AIBotProfile(AiId: 1181, CountryCode: "JPN", UserName: "Portalcraft AI",
|
||||
// Cosmetic ids mirror the Scripted bot's prod-verified values
|
||||
// (ScriptedProfiles / ScriptedBotParticipant.Context). Placeholder
|
||||
// ids of 1 failed to resolve in ResourcesManager.LoadAssetGroupSync —
|
||||
// LoadOpponentAssets (SBattleLoad.cs:933) hangs forever waiting for
|
||||
// missing assets and the "Waiting for opponent" UI never closes.
|
||||
SleeveId: 704141010, EmblemId: 400001100, DegreeId: 120027, FieldId: 5, IsOfficial: 0,
|
||||
ClassId: 8, CharaId: 8, Rank: 10, BattlePoint: 0, IsMasterRank: 0, MasterPoint: 0),
|
||||
};
|
||||
private readonly IGlobalsRepository _globals;
|
||||
|
||||
public AIBotProfile Pick(MatchContext selfCtx)
|
||||
public BotRoster(IGlobalsRepository globals)
|
||||
{
|
||||
_globals = globals;
|
||||
}
|
||||
|
||||
public async Task<AIBotProfile> PickAsync(MatchContext selfCtx, CancellationToken ct = default)
|
||||
{
|
||||
var roster = await _globals.GetBotRoster();
|
||||
if (roster.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"BotRoster is empty. Run SVSim.Bootstrap to import seeds/bot-roster.json.");
|
||||
}
|
||||
|
||||
// Deterministic: hash the ctx and pick from the roster. Same ctx →
|
||||
// same bot so a mid-flight retry of /ai_<fmt>/start returns the same
|
||||
// opponent (no fresh roster pick on each call).
|
||||
var hash = StringComparer.Ordinal.GetHashCode(selfCtx.UserName)
|
||||
^ StringComparer.Ordinal.GetHashCode(selfCtx.ClassId);
|
||||
var index = (int)((uint)hash % Roster.Count);
|
||||
return Roster[index];
|
||||
var index = (int)((uint)hash % roster.Count);
|
||||
var row = roster[index];
|
||||
return ToProfile(row);
|
||||
}
|
||||
|
||||
private static AIBotProfile ToProfile(BotRosterEntry row) => new(
|
||||
AiId: row.AiId,
|
||||
CountryCode: row.CountryCode,
|
||||
UserName: row.UserName,
|
||||
SleeveId: row.SleeveId,
|
||||
EmblemId: row.EmblemId,
|
||||
DegreeId: row.DegreeId,
|
||||
FieldId: row.FieldId,
|
||||
IsOfficial: row.IsOfficial,
|
||||
ClassId: row.ClassId,
|
||||
CharaId: row.CharaId,
|
||||
Rank: row.Rank,
|
||||
BattlePoint: row.BattlePoint,
|
||||
IsMasterRank: row.IsMasterRank,
|
||||
MasterPoint: row.MasterPoint);
|
||||
}
|
||||
|
||||
@@ -7,15 +7,16 @@ namespace SVSim.EmulatedEntrypoint.Matching;
|
||||
/// <c>RankBattleController.AiStart</c> to compose <c>oppo_info</c>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Phase 3 ships a hardcoded fixture; future improvement is to migrate the roster
|
||||
/// to <c>SVSim.Bootstrap/Data/seeds/bot-roster.json</c> for editability without
|
||||
/// rebuilds. See spec § Future improvements.
|
||||
/// Backed by the <c>BotRoster</c> table (seeded from
|
||||
/// <c>SVSim.Bootstrap/Data/seeds/bot-roster.json</c>). Edit the seed + re-run
|
||||
/// <c>SVSim.Bootstrap</c> to change the pool without recompiling.
|
||||
/// </remarks>
|
||||
public interface IBotRoster
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a bot profile for the calling viewer. Deterministic per
|
||||
/// <see cref="MatchContext"/> — the same context value returns the same bot.
|
||||
/// <see cref="MatchContext"/> — the same context value returns the same bot, so a
|
||||
/// mid-flight retry of <c>/ai_<fmt>/start</c> picks the same opponent.
|
||||
/// </summary>
|
||||
AIBotProfile Pick(MatchContext selfCtx);
|
||||
Task<AIBotProfile> PickAsync(MatchContext selfCtx, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
@@ -138,8 +138,9 @@ public class Program
|
||||
new ModePolicy("unlimited_rank_battle", PolicyKind.PvpFirstThenAiFallback),
|
||||
}));
|
||||
builder.Services.AddSingleton<IMatchingPairUpService, InProcessPairUp>();
|
||||
// Phase 3: bot fixture used by RankBattleController.AiStart to compose oppo_info.
|
||||
builder.Services.AddSingleton<IBotRoster, BotRoster>();
|
||||
// Phase 3: bot roster used by RankBattleController.AiStart to compose oppo_info.
|
||||
// Transient because BotRoster depends on the transient IGlobalsRepository.
|
||||
builder.Services.AddTransient<IBotRoster, BotRoster>();
|
||||
|
||||
builder.Services.AddTransient<ShadowverseTranslationMiddleware>();
|
||||
builder.Services.AddTransient<SessionidMappingMiddleware>();
|
||||
|
||||
94
SVSim.UnitTests/Importers/BotRosterImporterTests.cs
Normal file
94
SVSim.UnitTests/Importers/BotRosterImporterTests.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SVSim.Bootstrap.Importers;
|
||||
using SVSim.Database;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
namespace SVSim.UnitTests.Importers;
|
||||
|
||||
public class BotRosterImporterTests
|
||||
{
|
||||
private static string SeedDir => Path.Combine(AppContext.BaseDirectory, "Data", "seeds");
|
||||
|
||||
[Test]
|
||||
public async Task Imports_bots_from_seed_file()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
|
||||
await new BotRosterImporter().ImportAsync(db, SeedDir);
|
||||
|
||||
var bots = await db.BotRoster.OrderBy(b => b.Id).ToListAsync();
|
||||
Assert.That(bots.Count, Is.GreaterThan(0), "seed file must contain bots");
|
||||
Assert.That(bots.All(b => b.ClassId is >= 1 and <= 8), Is.True);
|
||||
Assert.That(bots.All(b => !string.IsNullOrEmpty(b.UserName)), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Is_idempotent_on_rerun()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
|
||||
await new BotRosterImporter().ImportAsync(db, SeedDir);
|
||||
int before = await db.BotRoster.CountAsync();
|
||||
await new BotRosterImporter().ImportAsync(db, SeedDir);
|
||||
int after = await db.BotRoster.CountAsync();
|
||||
|
||||
Assert.That(after, Is.EqualTo(before));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Leaves_existing_rows_untouched_when_missing_from_seed()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
|
||||
const int legacyAiId = 99999;
|
||||
db.BotRoster.Add(new SVSim.Database.Models.BotRosterEntry
|
||||
{
|
||||
Id = legacyAiId,
|
||||
CountryCode = "ZZ",
|
||||
UserName = "legacy",
|
||||
SleeveId = 1,
|
||||
EmblemId = 1,
|
||||
DegreeId = 1,
|
||||
FieldId = 1,
|
||||
ClassId = 1,
|
||||
CharaId = 1,
|
||||
Rank = 1,
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await new BotRosterImporter().ImportAsync(db, SeedDir);
|
||||
|
||||
var legacy = await db.BotRoster.FindAsync(legacyAiId);
|
||||
Assert.That(legacy, Is.Not.Null, "seed-missing row must be left intact");
|
||||
Assert.That(legacy!.UserName, Is.EqualTo("legacy"), "pre-existing values must not be wiped");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Skips_rows_with_zero_ai_id()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
|
||||
string tmp = Path.Combine(Path.GetTempPath(), $"seed-{Guid.NewGuid()}");
|
||||
Directory.CreateDirectory(tmp);
|
||||
try
|
||||
{
|
||||
File.WriteAllText(Path.Combine(tmp, "bot-roster.json"),
|
||||
"[{\"ai_id\":0,\"user_name\":\"junk\",\"class_id\":1}]");
|
||||
|
||||
await new BotRosterImporter().ImportAsync(db, tmp);
|
||||
|
||||
int count = await db.BotRoster.CountAsync();
|
||||
Assert.That(count, Is.EqualTo(0), "rows with ai_id=0 must not be inserted");
|
||||
}
|
||||
finally { Directory.Delete(tmp, true); }
|
||||
}
|
||||
}
|
||||
@@ -258,6 +258,7 @@ internal sealed class SVSimTestFactory : WebApplicationFactory<Program>
|
||||
await new RotationFlagUpdater().UpdateAsync(ctx);
|
||||
|
||||
await new PracticeOpponentImporter().ImportAsync(ctx, seedDir);
|
||||
await new BotRosterImporter().ImportAsync(ctx, seedDir);
|
||||
await new PaymentItemImporter().ImportAsync(ctx, seedDir);
|
||||
await new ItemImporter().ImportAsync(ctx, seedDir);
|
||||
await new SleeveShopImporter().ImportAsync(ctx, seedDir);
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NUnit.Framework;
|
||||
using SVSim.BattleNode.Bridge;
|
||||
using SVSim.Database.Repositories.Globals;
|
||||
using SVSim.EmulatedEntrypoint.Matching;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
namespace SVSim.UnitTests.Matching;
|
||||
|
||||
@@ -13,11 +16,21 @@ public class BotRosterTests
|
||||
CountryCode: "JP", UserName: userName, SleeveId: "0",
|
||||
EmblemId: "0", DegreeId: "0", FieldId: 0, IsOfficial: 0, BattleType: 11);
|
||||
|
||||
[Test]
|
||||
public void Pick_returns_a_bot_with_valid_ai_id_from_rm_ai_setting()
|
||||
private static async Task<BotRoster> NewRosterAsync(SVSimTestFactory factory)
|
||||
{
|
||||
var roster = new BotRoster();
|
||||
var bot = roster.Pick(Ctx("PlayerA", "1"));
|
||||
await factory.SeedGlobalsAsync();
|
||||
var scope = factory.Services.CreateScope();
|
||||
var globals = scope.ServiceProvider.GetRequiredService<IGlobalsRepository>();
|
||||
return new BotRoster(globals);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PickAsync_returns_a_bot_with_valid_ai_id_from_rm_ai_setting()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
var roster = await NewRosterAsync(factory);
|
||||
|
||||
var bot = await roster.PickAsync(Ctx("PlayerA", "1"));
|
||||
|
||||
// Series-1 enemy_ai_id values from data_dumps/client-assets/rm_ai_setting.csv —
|
||||
// one per class (1=Forest, 2=Sword, 3=Rune, 4=Dragon, 5=Shadow, 6=Blood, 7=Haven, 8=Portal).
|
||||
@@ -26,10 +39,12 @@ public class BotRosterTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Pick_returns_bot_with_class_metadata_set()
|
||||
public async Task PickAsync_returns_bot_with_class_metadata_set()
|
||||
{
|
||||
var roster = new BotRoster();
|
||||
var bot = roster.Pick(Ctx("PlayerA", "1"));
|
||||
using var factory = new SVSimTestFactory();
|
||||
var roster = await NewRosterAsync(factory);
|
||||
|
||||
var bot = await roster.PickAsync(Ctx("PlayerA", "1"));
|
||||
|
||||
Assert.That(bot.ClassId, Is.InRange(1, 8));
|
||||
Assert.That(bot.CharaId, Is.InRange(1, 8));
|
||||
@@ -38,14 +53,28 @@ public class BotRosterTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Pick_is_deterministic_per_match_context()
|
||||
public async Task PickAsync_is_deterministic_per_match_context()
|
||||
{
|
||||
var roster = new BotRoster();
|
||||
using var factory = new SVSimTestFactory();
|
||||
var roster = await NewRosterAsync(factory);
|
||||
var ctx = Ctx("PlayerA", "3");
|
||||
|
||||
var a = roster.Pick(ctx);
|
||||
var b = roster.Pick(ctx);
|
||||
var a = await roster.PickAsync(ctx);
|
||||
var b = await roster.PickAsync(ctx);
|
||||
|
||||
Assert.That(a, Is.EqualTo(b), "Same ctx → same bot, so mid-flight retries get the same opponent.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task PickAsync_throws_when_roster_empty()
|
||||
{
|
||||
// Empty DB (no SeedGlobalsAsync call) → no rows → invariant violated.
|
||||
using var factory = new SVSimTestFactory();
|
||||
var scope = factory.Services.CreateScope();
|
||||
var globals = scope.ServiceProvider.GetRequiredService<IGlobalsRepository>();
|
||||
var roster = new BotRoster(globals);
|
||||
|
||||
Assert.That(async () => await roster.PickAsync(Ctx("PlayerA", "1")),
|
||||
Throws.InvalidOperationException);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user