Files
SVSimServer/SVSim.Database/Repositories/Globals/GlobalsRepository.cs
gamer147 24f9b2240e 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>
2026-06-02 11:58:19 -04:00

111 lines
4.5 KiB
C#

using Microsoft.EntityFrameworkCore;
using SVSim.Database.Models;
namespace SVSim.Database.Repositories.Globals;
public class GlobalsRepository : IGlobalsRepository
{
private readonly SVSimDbContext _dbContext;
public GlobalsRepository(SVSimDbContext dbContext)
{
_dbContext = dbContext;
}
public async Task<List<ClassExpEntry>> GetClassExpCurve()
{
return await _dbContext.Set<ClassExpEntry>().ToListAsync();
}
public async Task<List<BattlefieldEntry>> GetBattlefields(bool onlyOpen)
{
return await _dbContext.Set<BattlefieldEntry>().Where(bf => !onlyOpen || bf.IsOpen).ToListAsync();
}
public async Task<List<RankInfoEntry>> GetRankInfo()
{
return await _dbContext.Set<RankInfoEntry>().ToListAsync();
}
// ---------- Prod-captured globals ----------
public Task<List<MyRotationSettingEntry>> GetMyRotationSettings() =>
_dbContext.MyRotationSettings.AsNoTracking().ToListAsync();
public Task<List<MyRotationAbilityEntry>> GetMyRotationAbilities() =>
_dbContext.MyRotationAbilities.AsNoTracking().ToListAsync();
public Task<List<AvatarAbilityEntry>> GetAvatarAbilities() =>
_dbContext.AvatarAbilities.AsNoTracking().ToListAsync();
public Task<List<DefaultDeckEntry>> GetDefaultDecks() =>
_dbContext.DefaultDecks.AsNoTracking().ToListAsync();
public Task<ArenaSeasonConfig?> GetCurrentArenaSeason() =>
_dbContext.ArenaSeasons.AsNoTracking().FirstOrDefaultAsync(e => e.Id == 1);
public Task<List<SpotCardEntry>> GetSpotCards() =>
_dbContext.SpotCards.AsNoTracking().ToListAsync();
public Task<List<ReprintedCardEntry>> GetReprintedCards() =>
_dbContext.ReprintedCards.AsNoTracking().ToListAsync();
public Task<List<UnlimitedRestrictionEntry>> GetUnlimitedRestrictions() =>
_dbContext.UnlimitedRestrictions.AsNoTracking().ToListAsync();
public Task<List<LoadingExclusionCardEntry>> GetLoadingExclusionCards() =>
_dbContext.LoadingExclusionCards.AsNoTracking().ToListAsync();
public Task<List<BattlePassLevelEntry>> GetBattlePassLevels() =>
_dbContext.BattlePassLevels.AsNoTracking().ToListAsync();
public Task<List<DailyLoginBonusEntry>> GetDailyLoginBonus() =>
_dbContext.DailyLoginBonuses.AsNoTracking().ToListAsync();
public Task<List<BannerEntry>> GetBanners() =>
_dbContext.Banners.AsNoTracking().OrderBy(b => b.Id).ToListAsync();
public Task<ColosseumConfig?> GetCurrentColosseum() =>
_dbContext.Colosseums.AsNoTracking().FirstOrDefaultAsync(e => e.Id == 1);
public Task<SealedConfig?> GetCurrentSealedSeason() =>
_dbContext.SealedSeasons.AsNoTracking().FirstOrDefaultAsync(e => e.Id == 1);
/// <summary>Returns the master-point ranking period whose EndTime is in the future, or the latest by EndTime as fallback.</summary>
public async Task<MasterPointRankingPeriodEntry?> GetCurrentMasterPointPeriod()
{
var now = DateTime.UtcNow;
return await _dbContext.MasterPointRankingPeriods.AsNoTracking()
.Where(p => p.EndTime >= now)
.OrderBy(p => p.EndTime)
.FirstOrDefaultAsync()
?? await _dbContext.MasterPointRankingPeriods.AsNoTracking()
.OrderByDescending(p => p.EndTime)
.FirstOrDefaultAsync();
}
public Task<List<SpecialDeckFormatEntry>> GetActiveSpecialDeckFormats() =>
_dbContext.SpecialDeckFormats.AsNoTracking().OrderBy(e => e.Id).ToListAsync();
public Task<List<PaymentItemEntry>> GetPaymentItems() =>
_dbContext.PaymentItems.AsNoTracking().OrderBy(e => e.Id).ToListAsync();
public Task<List<MaintenanceCardEntry>> GetMaintenanceCards() =>
_dbContext.MaintenanceCards.AsNoTracking().ToListAsync();
public Task<List<FeatureMaintenanceEntry>> GetFeatureMaintenances() =>
_dbContext.FeatureMaintenances.AsNoTracking().ToListAsync();
public Task<PreReleaseInfo?> GetPreReleaseInfo() =>
_dbContext.PreReleaseInfos.AsNoTracking().FirstOrDefaultAsync(e => e.Id == 1);
public Task<List<ShadowverseCardSetEntry>> GetRotationCardSets() =>
_dbContext.CardSets.AsNoTracking().Where(s => s.IsInRotation).ToListAsync();
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();
}