Files
SVSimServer/SVSim.Bootstrap/Importers/ArenaTwoPickRewardImporter.cs
gamer147 fc504af496 feat(tk2): weighted-group reward picking
Replaces the all-rows-granted reward model with per-group weighted
pick. Each ArenaTwoPickReward row now belongs to a RewardGroup with a
Weight; finish/retire groups the WinCount's rows by RewardGroup and
picks exactly one row per group, weighted by Weight (excluding
Weight==0). A RewardNum==0 outcome skips both the grant and the
rewards[] emission. Empty WinCount catalogs emit empty arrays.

Existing seed entries preserve deterministic behavior by living in
single-option groups (each with weight 1). Future seasons can expand
groups to multi-option for true randomized rewards (e.g. 200-280
rupies).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 13:44:33 -04:00

54 lines
1.8 KiB
C#

using Microsoft.EntityFrameworkCore;
using SVSim.Bootstrap.Models.Seed;
using SVSim.Database;
using SVSim.Database.Models;
namespace SVSim.Bootstrap.Importers;
/// <summary>
/// Idempotent upsert of <see cref="ArenaTwoPickReward"/> rows from
/// <c>arena-two-pick-rewards.json</c>. Key = (WinCount, RewardGroup, RewardType, RewardId, RewardNum).
/// </summary>
public class ArenaTwoPickRewardImporter
{
public async Task<int> ImportAsync(SVSimDbContext context, string seedDir)
{
var path = Path.Combine(seedDir, "arena-two-pick-rewards.json");
if (!File.Exists(path))
{
Console.WriteLine($"[ArenaTwoPickRewardImporter] missing {path}; skipping.");
return 0;
}
var seeds = SeedLoader.LoadList<ArenaTwoPickRewardSeed>(path);
var existing = await context.ArenaTwoPickRewards
.ToDictionaryAsync(r => (r.WinCount, r.RewardGroup, r.RewardType, r.RewardId, r.RewardNum));
int upserted = 0;
foreach (var s in seeds)
{
if (existing.TryGetValue((s.WinCount, s.RewardGroup, s.RewardType, s.RewardId, s.RewardNum), out var row))
{
row.Weight = s.Weight;
}
else
{
context.ArenaTwoPickRewards.Add(new ArenaTwoPickReward
{
WinCount = s.WinCount,
RewardGroup = s.RewardGroup,
Weight = s.Weight,
RewardType = s.RewardType,
RewardId = s.RewardId,
RewardNum = s.RewardNum,
});
}
upserted++;
}
await context.SaveChangesAsync();
Console.WriteLine($"[ArenaTwoPickRewardImporter] upserted={upserted}");
return upserted;
}
}