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:
dingo
2026-04-12 19:10:16 -04:00
co-authored by Claude Happy
parent 3ba138e4cd
commit 70df0e0b33
11 changed files with 1056 additions and 22 deletions
@@ -178,6 +178,11 @@
<i class="bi bi-sliders me-2"></i>Calibration
</NavLink>
</li>
<li class="nav-item">
<NavLink class="nav-link text-white-50 py-1" href="/ai/deck-config">
<i class="bi bi-collection-play me-2"></i>Deck Config
</NavLink>
</li>
</ul>
</li>
<li class="nav-item">
@@ -0,0 +1,179 @@
@page "/ai/deck-config"
@using Microsoft.EntityFrameworkCore
@using SOR.Database.Contexts
@using SOR.Database.Entities.Game
@using SOR.Database.Entities.Bazaar
@inject GameDbContext GameDb
@inject BazaarDbContext BazaarDb
<PageTitle>AI Deck Configuration – SOR Admin</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="mb-0">AI Deck Configuration</h1>
<div class="d-flex gap-2">
<button class="btn btn-primary btn-sm" @onclick="SaveAsync" disabled="@_saving">
@if (_saving) { <span class="spinner-border spinner-border-sm me-1"></span> }
<i class="bi bi-floppy me-1"></i>Save
</button>
<button class="btn btn-outline-secondary btn-sm" @onclick="LoadAsync">
<i class="bi bi-arrow-clockwise me-1"></i>Refresh
</button>
</div>
</div>
<p class="text-muted mb-4">
Configure which prebuilt deck each AI difficulty tier will use.
Leave blank to have the AI pick a random active starter deck.
</p>
@if (_error is not null)
{
<div class="alert alert-danger">@_error</div>
}
@if (_success is not null)
{
<div class="alert alert-success">@_success</div>
}
@if (_rows is null)
{
<p><span class="spinner-border spinner-border-sm"></span> Loading…</p>
}
else
{
<div class="card">
<div class="table-responsive">
<table class="table table-sm table-hover mb-0 align-middle">
<thead>
<tr>
<th style="width:100px">Difficulty</th>
<th>Label</th>
<th>Assigned Deck</th>
</tr>
</thead>
<tbody>
@foreach (var row in _rows)
{
<tr>
<td><strong>D@(row.Difficulty)</strong></td>
<td class="text-muted small">@DifficultyLabel(row.Difficulty)</td>
<td>
<select class="form-select form-select-sm"
@onchange="e => row.SelectedPrebuiltDeckId = ParseGuid(e.Value?.ToString())">
<option value="">— Random starter deck —</option>
@foreach (var deck in _prebuiltDecks)
{
<option value="@deck.Id"
selected="@(row.SelectedPrebuiltDeckId == deck.Id)">
@deck.Name @(deck.IsStarterDeck ? "(Starter)" : "")
</option>
}
</select>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
@code {
private sealed class DifficultyRow
{
public int Difficulty { get; set; }
public Guid? SelectedPrebuiltDeckId { get; set; }
}
private List<DifficultyRow>? _rows;
private List<PrebuiltDeck> _prebuiltDecks = new();
private bool _saving;
private string? _error;
private string? _success;
protected override async Task OnInitializedAsync() => await LoadAsync();
private async Task LoadAsync()
{
_error = null; _success = null;
// All active prebuilt decks (starter or shop).
_prebuiltDecks = await BazaarDb.PrebuiltDecks
.AsNoTracking()
.Where(d => d.IsActive)
.OrderBy(d => d.IsStarterDeck ? 0 : 1)
.ThenBy(d => d.Name)
.ToListAsync();
// Existing assignments.
var assignments = await GameDb.AiDeckAssignments
.AsNoTracking()
.ToDictionaryAsync(a => a.Difficulty);
_rows = Enumerable.Range(1, 10).Select(d => new DifficultyRow
{
Difficulty = d,
SelectedPrebuiltDeckId = assignments.TryGetValue(d, out var a) ? a.PrebuiltDeckId : null,
}).ToList();
StateHasChanged();
}
private async Task SaveAsync()
{
_saving = true; _error = null; _success = null; StateHasChanged();
try
{
// Upsert all 10 rows.
var existing = await GameDb.AiDeckAssignments.ToListAsync();
var byDiff = existing.ToDictionary(a => a.Difficulty);
foreach (var row in _rows!)
{
if (byDiff.TryGetValue(row.Difficulty, out var entity))
{
entity.PrebuiltDeckId = row.SelectedPrebuiltDeckId;
}
else
{
GameDb.AiDeckAssignments.Add(new AiDeckAssignment
{
Difficulty = row.Difficulty,
PrebuiltDeckId = row.SelectedPrebuiltDeckId,
});
}
}
await GameDb.SaveChangesAsync();
_success = "AI deck assignments saved.";
}
catch (Exception ex)
{
_error = ex.Message;
}
finally
{
_saving = false;
StateHasChanged();
}
}
private static string DifficultyLabel(int d) => d switch
{
1 => "Novice",
2 => "Apprentice",
3 => "Journeyman",
4 => "Adept",
5 => "Expert",
6 => "Master",
7 => "Grandmaster",
8 => "Champion",
9 => "Legend",
10 => "Mythic",
_ => $"Tier {d}",
};
private static Guid? ParseGuid(string? s)
=> Guid.TryParse(s, out var g) ? g : null;
}
+6 -14
View File
@@ -1,7 +1,6 @@
namespace SOR.Ai.Handlers;
using System.Text.Json;
using Microsoft.EntityFrameworkCore;
using SOR.Ai.Lobby;
using SOR.Ai.Seeding;
using SOR.Database.Contexts;
@@ -24,27 +23,27 @@ internal sealed class GameAddAiHandler : IMessageHandler
private readonly IMessageSerializer _serializer;
private readonly GameDbContext _gameDb;
private readonly SorIdentityDbContext _identityDb;
private readonly CollectionDbContext _collectionDb;
private readonly IClientPush _clientPush;
private readonly AiSlotAssigner _assigner;
private readonly AiLobbyService _lobbyService;
private readonly AiDeckResolver _deckResolver;
public GameAddAiHandler(
IMessageSerializer serializer,
GameDbContext gameDb,
SorIdentityDbContext identityDb,
CollectionDbContext collectionDb,
IClientPush clientPush,
AiSlotAssigner assigner,
AiLobbyService lobbyService)
AiLobbyService lobbyService,
AiDeckResolver deckResolver)
{
_serializer = serializer;
_gameDb = gameDb;
_identityDb = identityDb;
_collectionDb = collectionDb;
_clientPush = clientPush;
_assigner = assigner;
_lobbyService = lobbyService;
_deckResolver = deckResolver;
}
public string MessageType => "game.ai.add";
@@ -84,18 +83,11 @@ internal sealed class GameAddAiHandler : IMessageHandler
if (currentCount >= lobby.MaxPlayers)
throw new GameException("LOBBY_FULL");
// Resolve the AI account and its deck.
// Resolve the AI account, then pick (and sync) its deck from a prebuilt deck.
var aiAccount = await _assigner.GetAiAccountAsync(req.Difficulty, req.Strategy, ct);
var aiId = aiAccount.Id;
var deckId = await _collectionDb.Decks
.AsNoTracking()
.Where(d => d.AccountId == aiId)
.Select(d => d.Id)
.FirstOrDefaultAsync(ct);
if (deckId == Guid.Empty)
throw new GameException("AI_DECK_NOT_FOUND");
var deckId = await _deckResolver.ResolveAsync(aiId, req.Difficulty, ct);
// Assign the AI to the correct slot.
int seatIndex;
+146
View File
@@ -0,0 +1,146 @@
namespace SOR.Ai.Lobby;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using SOR.Database.Contexts;
using SOR.Database.Entities.Collection;
/// <summary>
/// Resolves which deck an AI account will use for a given difficulty level.
///
/// Resolution order:
/// 1. Admin-configured AiDeckAssignment for this difficulty → that PrebuiltDeck.
/// 2. Any PrebuiltDeck where IsStarterDeck = true (random pick).
/// 3. No deck available → throws GameException.
///
/// After picking a prebuilt deck, creates or updates a real Deck row in
/// CollectionDbContext for the AI account so GameReadyHandler can load it
/// via the standard LoadDeckCardsAsync path.
/// </summary>
internal sealed class AiDeckResolver
{
private readonly GameDbContext _gameDb;
private readonly BazaarDbContext _bazaarDb;
private readonly CollectionDbContext _collectionDb;
private readonly ILogger<AiDeckResolver> _logger;
public AiDeckResolver(
GameDbContext gameDb,
BazaarDbContext bazaarDb,
CollectionDbContext collectionDb,
ILogger<AiDeckResolver> logger)
{
_gameDb = gameDb;
_bazaarDb = bazaarDb;
_collectionDb = collectionDb;
_logger = logger;
}
/// <summary>
/// Returns a CollectionDb Deck ID for the AI account at the given difficulty.
/// Creates or refreshes the AI's deck from the configured prebuilt deck.
/// Throws GameException("AI_DECK_NOT_FOUND") if no prebuilt deck is available.
/// </summary>
public async Task<Guid> ResolveAsync(
Guid aiAccountId,
int difficulty,
CancellationToken ct)
{
// 1. Look up admin assignment for this difficulty.
var assignment = await _gameDb.AiDeckAssignments
.AsNoTracking()
.FirstOrDefaultAsync(a => a.Difficulty == difficulty, ct);
SOR.Database.Entities.Bazaar.PrebuiltDeck? prebuilt = null;
if (assignment?.PrebuiltDeckId is not null)
{
prebuilt = await _bazaarDb.PrebuiltDecks
.Include(d => d.Cards)
.AsNoTracking()
.FirstOrDefaultAsync(d => d.Id == assignment.PrebuiltDeckId.Value, ct);
}
// 2. Fallback: any active starter deck (random).
if (prebuilt is null)
{
var starters = await _bazaarDb.PrebuiltDecks
.Include(d => d.Cards)
.AsNoTracking()
.Where(d => d.IsStarterDeck && d.IsActive)
.ToListAsync(ct);
if (starters.Count == 0)
throw new SOR.Game.GameException("AI_DECK_NOT_FOUND");
prebuilt = starters[Random.Shared.Next(starters.Count)];
_logger.LogDebug(
"AiDeckResolver: no assignment for difficulty {D} — using random starter '{Name}'.",
difficulty, prebuilt.Name);
}
if (prebuilt.ArchSpiritCardDefinitionId is null)
throw new SOR.Game.GameException("AI_DECK_NOT_FOUND");
// 3. Create or replace the AI account's deck from the prebuilt deck.
return await SyncDeckAsync(aiAccountId, prebuilt, ct);
}
// ── Helpers ───────────────────────────────────────────────────────────────
private async Task<Guid> SyncDeckAsync(
Guid aiAccountId,
SOR.Database.Entities.Bazaar.PrebuiltDeck prebuilt,
CancellationToken ct)
{
// Find existing AI deck (there should be at most one).
var existing = await _collectionDb.Decks
.Include(d => d.Cards)
.FirstOrDefaultAsync(d => d.AccountId == aiAccountId, ct);
var now = DateTimeOffset.UtcNow;
if (existing is null)
{
// Create fresh.
var deck = new Deck
{
AccountId = aiAccountId,
Name = prebuilt.Name,
Description = prebuilt.Description,
ArchSpiritCardDefinitionId = prebuilt.ArchSpiritCardDefinitionId!.Value,
IsValid = true,
CreatedAt = now,
UpdatedAt = now,
Cards = prebuilt.Cards
.Select(c => new DeckCard
{
CardDefinitionId = c.CardDefinitionId,
Quantity = c.Quantity,
}).ToList(),
};
_collectionDb.Decks.Add(deck);
await _collectionDb.SaveChangesAsync(ct);
return deck.Id;
}
// Update in-place if the prebuilt changed.
existing.Name = prebuilt.Name;
existing.Description = prebuilt.Description;
existing.ArchSpiritCardDefinitionId = prebuilt.ArchSpiritCardDefinitionId!.Value;
existing.UpdatedAt = now;
// Replace card rows.
_collectionDb.RemoveRange(existing.Cards);
existing.Cards = prebuilt.Cards
.Select(c => new DeckCard
{
DeckId = existing.Id,
CardDefinitionId = c.CardDefinitionId,
Quantity = c.Quantity,
}).ToList();
await _collectionDb.SaveChangesAsync(ct);
return existing.Id;
}
}
@@ -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(
+2
View File
@@ -12,6 +12,7 @@ using SOR.Ai.Seeding;
using SOR.Ai.Training;
using SOR.Networking.Abstractions.Messaging;
using SOR.Shared;
using SOR.Database.Contexts;
/// <summary>
/// Registers all AI service components into the DI container.
@@ -44,6 +45,7 @@ public static class ServiceRegistration
// ── Lobby scoped services ─────────────────────────────────────────────
services.AddScoped<AiSlotAssigner>();
services.AddScoped<AiLobbyService>();
services.AddScoped<AiDeckResolver>();
// ── Decision engines (transient — each turn gets a fresh instance) ──────
// Engines are resolved directly by AiPlayerSession via ResolveEngine(),
@@ -32,6 +32,7 @@ public sealed class GameDbContext : DbContext
public DbSet<BoardTemplate> BoardTemplates => Set<BoardTemplate>();
public DbSet<AiEloRecord> AiEloRecords => Set<AiEloRecord>();
public DbSet<AiCalibrationRun> AiCalibrationRuns => Set<AiCalibrationRun>();
public DbSet<AiDeckAssignment> AiDeckAssignments => Set<AiDeckAssignment>();
protected override void OnModelCreating(ModelBuilder builder)
{
@@ -126,5 +127,11 @@ public sealed class GameDbContext : DbContext
e.HasKey(r => r.Id);
e.HasIndex(r => r.RunAt);
});
builder.Entity<AiDeckAssignment>(e =>
{
e.ToTable("ai_deck_assignments");
e.HasKey(a => a.Difficulty); // Difficulty IS the PK (1–10)
});
}
}
@@ -0,0 +1,20 @@
namespace SOR.Database.Entities.Game;
/// <summary>
/// Admin-configured mapping from AI difficulty tier to a PrebuiltDeck.
/// One row per difficulty (1–10). When an AI slot is added to a lobby,
/// AiDeckResolver looks up this table to decide which deck to give the AI.
///
/// Cross-schema: PrebuiltDeckId references the bazaar schema PrebuiltDeck.
/// No EF foreign key — bare Guid.
/// </summary>
public sealed class AiDeckAssignment
{
public int Difficulty { get; set; } // 1–10; also the primary key
/// <summary>
/// The prebuilt deck the AI will use at this difficulty.
/// Null means "pick any active starter deck at random".
/// </summary>
public Guid? PrebuiltDeckId { get; set; }
}
@@ -0,0 +1,632 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using SOR.Database.Contexts;
#nullable disable
namespace SOR.Database.Migrations.Game
{
[DbContext(typeof(GameDbContext))]
[Migration("20260412230253_AddAiDeckAssignment")]
partial class AddAiDeckAssignment
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("game")
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("SOR.Database.Entities.Game.AiCalibrationRun", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("DifficultyA")
.HasColumnType("integer");
b.Property<int>("DifficultyB")
.HasColumnType("integer");
b.Property<int>("GameCount")
.HasColumnType("integer");
b.Property<string>("Notes")
.HasColumnType("text");
b.Property<DateTimeOffset>("RunAt")
.HasColumnType("timestamp with time zone");
b.Property<float>("WinRateA")
.HasColumnType("real");
b.HasKey("Id");
b.HasIndex("RunAt");
b.ToTable("ai_calibration_runs", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.AiDeckAssignment", b =>
{
b.Property<int>("Difficulty")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Difficulty"));
b.Property<Guid?>("PrebuiltDeckId")
.HasColumnType("uuid");
b.HasKey("Difficulty");
b.ToTable("ai_deck_assignments", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.AiEloRecord", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("AiAccountId")
.HasColumnType("uuid");
b.Property<int>("EloScore")
.HasColumnType("integer");
b.Property<int>("Losses")
.HasColumnType("integer");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Wins")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("AiAccountId")
.IsUnique();
b.ToTable("ai_elo_records", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.BoardTemplate", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("GridType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Height")
.HasColumnType("integer");
b.Property<int>("HexPolygonSides")
.HasColumnType("integer");
b.Property<int>("HexSideLength")
.HasColumnType("integer");
b.Property<int>("HexSides")
.HasColumnType("integer");
b.Property<bool>("IsAvailableForCustom")
.HasColumnType("boolean");
b.Property<bool>("IsAvailableForRanked")
.HasColumnType("boolean");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<int>("MinPlayers")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StartingZonesJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<string>("TilesJson")
.IsRequired()
.HasColumnType("jsonb");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Width")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("IsEnabled");
b.ToTable("board_templates", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.CustomLobby", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AdditionalPlayersJson")
.HasColumnType("text")
.HasColumnName("additional_players_json");
b.Property<string>("AiSlotsJson")
.HasColumnType("text");
b.Property<int?>("BoardHeightOverride")
.HasColumnType("integer");
b.Property<string>("BoardShapeOverride")
.HasColumnType("text");
b.Property<Guid?>("BoardTemplateIdOverride")
.HasColumnType("uuid");
b.Property<int?>("BoardWidthOverride")
.HasColumnType("integer");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<bool?>("DiscardOnMaxHandOverride")
.HasColumnType("boolean");
b.Property<int?>("DrawPerTurnOverride")
.HasColumnType("integer");
b.Property<bool?>("FirstPlayerSkipsDrawOverride")
.HasColumnType("boolean");
b.Property<string>("GameMode")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("FFA")
.HasColumnName("game_mode");
b.Property<Guid?>("GameSessionId")
.HasColumnType("uuid");
b.Property<Guid?>("GuestAccountId")
.HasColumnType("uuid");
b.Property<Guid?>("GuestDeckId")
.HasColumnType("uuid");
b.Property<string>("GuestFirstTurnPref")
.HasColumnType("text");
b.Property<bool>("GuestReady")
.HasColumnType("boolean");
b.Property<int?>("HandSizeCapOverride")
.HasColumnType("integer");
b.Property<int?>("HexSidesOverride")
.HasColumnType("integer");
b.Property<Guid>("HostAccountId")
.HasColumnType("uuid");
b.Property<Guid>("HostDeckId")
.HasColumnType("uuid");
b.Property<string>("HostFirstTurnPref")
.HasColumnType("text");
b.Property<bool>("HostReady")
.HasColumnType("boolean");
b.Property<int?>("MaxArchTier1Override")
.HasColumnType("integer");
b.Property<int?>("MaxDeckSizeOverride")
.HasColumnType("integer");
b.Property<int>("MaxPlayers")
.HasColumnType("integer");
b.Property<int?>("MinDeckSizeOverride")
.HasColumnType("integer");
b.Property<int?>("MpBuffOverride")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("OpeningHandSizeOverride")
.HasColumnType("integer");
b.Property<string>("Password")
.HasColumnType("text");
b.Property<int?>("SpAccumulationPerTurnOverride")
.HasColumnType("integer");
b.Property<int?>("SpCapOverride")
.HasColumnType("integer");
b.Property<bool?>("SpHasCapOverride")
.HasColumnType("boolean");
b.Property<int?>("StartingRandomTilePctOverride")
.HasColumnType("integer");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.Property<string>("TeamAssignmentsJson")
.HasColumnType("text");
b.Property<int>("TeamCount")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValue(1)
.HasColumnName("team_count");
b.Property<int?>("TimeLimitMinutesOverride")
.HasColumnType("integer");
b.Property<int?>("TurnLimitOverride")
.HasColumnType("integer");
b.Property<int?>("TurnTimerSecondsOverride")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("HostAccountId");
b.HasIndex("Status", "CreatedAt");
b.ToTable("custom_lobbies", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameActionLog", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("ActionType")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("ActorAccountId")
.HasColumnType("uuid");
b.Property<Guid>("GameSessionId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("OccurredAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("PayloadJson")
.HasColumnType("jsonb")
.HasColumnName("payload");
b.Property<string>("ResultJson")
.HasColumnType("jsonb")
.HasColumnName("result");
b.Property<int>("SequenceNumber")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ActorAccountId");
b.HasIndex("GameSessionId", "SequenceNumber")
.IsUnique();
b.ToTable("action_logs", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameRuleSet", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("BoardHeight")
.HasColumnType("integer");
b.Property<Guid?>("BoardTemplateId")
.HasColumnType("uuid");
b.Property<int>("BoardWidth")
.HasColumnType("integer");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<bool>("DiscardOnMaxHand")
.HasColumnType("boolean");
b.Property<int>("DrawPerTurn")
.HasColumnType("integer");
b.Property<bool>("FirstPlayerSkipsDraw")
.HasColumnType("boolean");
b.Property<string>("GridType")
.IsRequired()
.HasColumnType("text");
b.Property<int>("HandSizeCap")
.HasColumnType("integer");
b.Property<int>("HexSides")
.HasColumnType("integer");
b.Property<bool>("IsCustomDefault")
.HasColumnType("boolean");
b.Property<bool>("IsRankedDefault")
.HasColumnType("boolean");
b.Property<int>("LoserOpReward")
.HasColumnType("integer");
b.Property<int>("MaxArchTier1")
.HasColumnType("integer");
b.Property<int>("MaxDeckSize")
.HasColumnType("integer");
b.Property<int>("MinDeckSize")
.HasColumnType("integer");
b.Property<int>("MpBuff")
.HasColumnType("integer");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<int>("OpeningHandSize")
.HasColumnType("integer");
b.Property<int>("RankDiffOpMultiplierPct")
.HasColumnType("integer");
b.Property<int>("SpAccumulationPerTurn")
.HasColumnType("integer");
b.Property<int>("SpCap")
.HasColumnType("integer");
b.Property<bool>("SpHasCap")
.HasColumnType("boolean");
b.Property<int>("StartingRandomTilePct")
.HasColumnType("integer");
b.Property<int>("TimeLimitMinutes")
.HasColumnType("integer");
b.Property<int>("TurnLimit")
.HasColumnType("integer");
b.Property<int>("TurnTimerSeconds")
.HasColumnType("integer");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("WinnerOpReward")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("IsCustomDefault");
b.HasIndex("IsRankedDefault");
b.ToTable("game_rule_sets", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameSession", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AdditionalPlayersJson")
.HasColumnType("text")
.HasColumnName("additional_players_json");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("EndedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("GameMode")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("FFA")
.HasColumnName("game_mode");
b.Property<DateTimeOffset?>("LastActionAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("PlayerCount")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValue(2)
.HasColumnName("player_count");
b.Property<Guid>("PlayerOneAccountId")
.HasColumnType("uuid");
b.Property<Guid>("PlayerOneDeckId")
.HasColumnType("uuid");
b.Property<bool>("PlayerOneReady")
.HasColumnType("boolean");
b.Property<int>("PlayerOneTeamIndex")
.HasColumnType("integer");
b.Property<Guid>("PlayerTwoAccountId")
.HasColumnType("uuid");
b.Property<Guid>("PlayerTwoDeckId")
.HasColumnType("uuid");
b.Property<bool>("PlayerTwoReady")
.HasColumnType("boolean");
b.Property<int>("PlayerTwoTeamIndex")
.HasColumnType("integer");
b.Property<string>("RuleSnapshotJson")
.HasColumnType("jsonb")
.HasColumnName("rule_snapshot");
b.Property<DateTimeOffset?>("StartedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("StateJson")
.HasColumnType("jsonb")
.HasColumnName("state");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.Property<int>("TeamCount")
.HasColumnType("integer");
b.Property<string>("WinCondition")
.HasColumnType("text");
b.Property<Guid?>("WinnerAccountId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("PlayerOneAccountId");
b.HasIndex("PlayerTwoAccountId");
b.HasIndex("Status", "CreatedAt");
b.ToTable("game_sessions", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.LobbyPreset", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<Guid>("OwnerAccountId")
.HasColumnType("uuid");
b.Property<string>("RulesJson")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("OwnerAccountId");
b.ToTable("lobby_presets", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.MatchmakingEntry", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid>("AccountId")
.HasColumnType("uuid");
b.Property<Guid>("DeckId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("JoinedAt")
.HasColumnType("timestamp with time zone");
b.Property<Guid?>("MatchedGameSessionId")
.HasColumnType("uuid");
b.Property<int>("RankScore")
.HasColumnType("integer");
b.Property<DateTimeOffset?>("ResolvedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AccountId", "Status");
b.HasIndex("Status", "RankScore");
b.ToTable("matchmaking_entries", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameActionLog", b =>
{
b.HasOne("SOR.Database.Entities.Game.GameSession", "Session")
.WithMany("ActionLog")
.HasForeignKey("GameSessionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Session");
});
modelBuilder.Entity("SOR.Database.Entities.Game.GameSession", b =>
{
b.Navigation("ActionLog");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,38 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace SOR.Database.Migrations.Game
{
/// <inheritdoc />
public partial class AddAiDeckAssignment : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "ai_deck_assignments",
schema: "game",
columns: table => new
{
Difficulty = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
PrebuiltDeckId = table.Column<Guid>(type: "uuid", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ai_deck_assignments", x => x.Difficulty);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ai_deck_assignments",
schema: "game");
}
}
}
@@ -54,6 +54,22 @@ namespace SOR.Database.Migrations.Game
b.ToTable("ai_calibration_runs", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.AiDeckAssignment", b =>
{
b.Property<int>("Difficulty")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Difficulty"));
b.Property<Guid?>("PrebuiltDeckId")
.HasColumnType("uuid");
b.HasKey("Difficulty");
b.ToTable("ai_deck_assignments", "game");
});
modelBuilder.Entity("SOR.Database.Entities.Game.AiEloRecord", b =>
{
b.Property<Guid>("Id")