AI picks prebuilt starter deck; admin deck-per-difficulty config
- AiDeckResolver: resolves which prebuilt deck an AI uses for a given difficulty. Checks AiDeckAssignment table first (admin-configured), then falls back to a random active starter deck. Creates/updates a real Deck row in CollectionDb so GameReadyHandler's standard path works unchanged. - AiDeckAssignment entity + EF migration (ai_deck_assignments table): admin maps Difficulty 1-10 → PrebuiltDeckId; null = "random starter". - GameAddAiHandler: replaced direct Deck lookup with AiDeckResolver.ResolveAsync. - AiSeedStartupService: removed AiDeckSeeder call — decks are resolved per-game from prebuilt decks, not pre-seeded with placeholder cards. - ServiceRegistration: registers AiDeckResolver as Scoped. - Admin: new /ai/deck-config page (AiDeckConfigPage) showing a D1-D10 table with prebuilt deck dropdowns; saved via upsert. Added to AI nav section. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -4,7 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SOR.Ai.Core;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Database.Contexts; // SorIdentityDbContext
|
||||
|
||||
/// <summary>
|
||||
/// One-shot IHostedService that runs at startup before the server accepts traffic.
|
||||
@@ -32,17 +32,14 @@ internal sealed class AiSeedStartupService : IHostedService
|
||||
await using var scope = _scopeFactory.CreateAsyncScope();
|
||||
var sp = scope.ServiceProvider;
|
||||
|
||||
var identityDb = sp.GetRequiredService<SorIdentityDbContext>();
|
||||
var collectionDb = sp.GetRequiredService<CollectionDbContext>();
|
||||
var catalogDb = sp.GetRequiredService<CatalogDbContext>();
|
||||
var identityDb = sp.GetRequiredService<SorIdentityDbContext>();
|
||||
|
||||
// 1. Seed AI accounts (idempotent).
|
||||
await AiAccountSeeder.SeedAsync(identityDb, _logger, cancellationToken);
|
||||
|
||||
// 2. Seed AI decks (idempotent; skips gracefully if catalog cards missing).
|
||||
await AiDeckSeeder.SeedAsync(identityDb, collectionDb, catalogDb, _logger, cancellationToken);
|
||||
|
||||
// 3. Populate in-memory registry for O(1) IsAi checks.
|
||||
// 2. Populate in-memory registry for O(1) IsAi checks.
|
||||
// Decks are no longer pre-seeded — AiDeckResolver picks a prebuilt deck
|
||||
// per-game based on admin-configured AiDeckAssignments.
|
||||
_registry.Load(identityDb);
|
||||
|
||||
_logger.LogInformation(
|
||||
|
||||
Reference in New Issue
Block a user