feat(item-purchase): /item_purchase/{info,purchase} + catalog
Schema: ItemPurchaseCatalogEntry (single table). Per-viewer quota tracked via existing ViewerEventCounter keyed by "item_purchase:<id>" with period JstPeriod.MonthKey when IsMonthlyReset else AllTime. Controller: - /info returns catalog + per-period rest (server-computed max(0, PurchaseLimit - counter)) + user_card_pack_ticket_list (every Items.Type==2 row joined to viewer count, zeros included — client unconditionally UpdateItemNum's each entry). - /purchase: sold_out check before currency check (no counter increment on currency failure), inline TryDebit covers RedEther/Crystal/Rupy/Item with post-state-total reward_list entry, grant via RewardGrantService. Request `rest` accepted but ignored (server counter is canonical). Importer mirrors PaymentItemImporter shape — idempotent find-or-create, seed-missing rows preserved. 3 entries from the prod capture. 486 tests pass (was 476; +10 item_purchase tests). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
38
SVSim.Bootstrap/Data/seeds/item-purchase.json
Normal file
38
SVSim.Bootstrap/Data/seeds/item-purchase.json
Normal file
@@ -0,0 +1,38 @@
|
||||
[
|
||||
{
|
||||
"purchase_id": 1,
|
||||
"require_item_type": 1,
|
||||
"require_item_id": 0,
|
||||
"require_item_num": 5000,
|
||||
"purchase_item_type": 4,
|
||||
"purchase_item_id": 1000,
|
||||
"purchase_item_num": 1,
|
||||
"purchase_name": "[b]One Time Only![/b] Seer's Globe x1",
|
||||
"is_monthly_reset": false,
|
||||
"purchase_limit": 1
|
||||
},
|
||||
{
|
||||
"purchase_id": 100002,
|
||||
"require_item_type": 4,
|
||||
"require_item_id": 1001,
|
||||
"require_item_num": 5,
|
||||
"purchase_item_type": 4,
|
||||
"purchase_item_id": 1000,
|
||||
"purchase_item_num": 1,
|
||||
"purchase_name": "",
|
||||
"is_monthly_reset": true,
|
||||
"purchase_limit": 3
|
||||
},
|
||||
{
|
||||
"purchase_id": 100003,
|
||||
"require_item_type": 1,
|
||||
"require_item_id": 0,
|
||||
"require_item_num": 30000,
|
||||
"purchase_item_type": 4,
|
||||
"purchase_item_id": 1000,
|
||||
"purchase_item_num": 1,
|
||||
"purchase_name": "",
|
||||
"is_monthly_reset": true,
|
||||
"purchase_limit": 10
|
||||
}
|
||||
]
|
||||
59
SVSim.Bootstrap/Importers/ItemPurchaseImporter.cs
Normal file
59
SVSim.Bootstrap/Importers/ItemPurchaseImporter.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SVSim.Bootstrap.Models.Seed;
|
||||
using SVSim.Database;
|
||||
using SVSim.Database.Models;
|
||||
|
||||
namespace SVSim.Bootstrap.Importers;
|
||||
|
||||
/// <summary>
|
||||
/// Idempotent upsert of the item-purchase catalog from <c>seeds/item-purchase.json</c>.
|
||||
/// Source is the wire <c>/item_purchase/info</c> response, extracted via
|
||||
/// <c>data_dumps/extract/extract-item-purchase.py</c>. Rows missing from the seed are LEFT INTACT.
|
||||
/// </summary>
|
||||
public class ItemPurchaseImporter
|
||||
{
|
||||
public async Task<int> ImportAsync(SVSimDbContext context, string seedDir)
|
||||
{
|
||||
string path = Path.Combine(seedDir, "item-purchase.json");
|
||||
var seed = SeedLoader.LoadList<ItemPurchaseSeed>(path);
|
||||
if (seed.Count == 0)
|
||||
{
|
||||
Console.WriteLine("[ItemPurchaseImporter] No seed rows; skipping.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
var existing = await context.ItemPurchaseCatalog.ToDictionaryAsync(e => e.Id);
|
||||
int created = 0, updated = 0;
|
||||
|
||||
foreach (var s in seed)
|
||||
{
|
||||
if (s.PurchaseId == 0) continue;
|
||||
|
||||
var entry = existing.TryGetValue(s.PurchaseId, out var ex)
|
||||
? ex : new ItemPurchaseCatalogEntry { Id = s.PurchaseId };
|
||||
|
||||
entry.RequireItemType = s.RequireItemType;
|
||||
entry.RequireItemId = s.RequireItemId;
|
||||
entry.RequireItemNum = s.RequireItemNum;
|
||||
entry.PurchaseItemType = s.PurchaseItemType;
|
||||
entry.PurchaseItemId = s.PurchaseItemId;
|
||||
entry.PurchaseItemNum = s.PurchaseItemNum;
|
||||
entry.PurchaseName = s.PurchaseName;
|
||||
entry.IsMonthlyReset = s.IsMonthlyReset;
|
||||
entry.PurchaseLimit = s.PurchaseLimit;
|
||||
entry.IsEnabled = true;
|
||||
|
||||
if (ex is null)
|
||||
{
|
||||
context.ItemPurchaseCatalog.Add(entry);
|
||||
existing[s.PurchaseId] = entry;
|
||||
created++;
|
||||
}
|
||||
else updated++;
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
Console.WriteLine($"[ItemPurchaseImporter] +{created}/~{updated}");
|
||||
return created + updated;
|
||||
}
|
||||
}
|
||||
17
SVSim.Bootstrap/Models/Seed/ItemPurchaseSeed.cs
Normal file
17
SVSim.Bootstrap/Models/Seed/ItemPurchaseSeed.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace SVSim.Bootstrap.Models.Seed;
|
||||
|
||||
public sealed class ItemPurchaseSeed
|
||||
{
|
||||
[JsonPropertyName("purchase_id")] public int PurchaseId { get; set; }
|
||||
[JsonPropertyName("require_item_type")] public int RequireItemType { get; set; }
|
||||
[JsonPropertyName("require_item_id")] public long RequireItemId { get; set; }
|
||||
[JsonPropertyName("require_item_num")] public int RequireItemNum { get; set; }
|
||||
[JsonPropertyName("purchase_item_type")] public int PurchaseItemType { get; set; }
|
||||
[JsonPropertyName("purchase_item_id")] public long PurchaseItemId { get; set; }
|
||||
[JsonPropertyName("purchase_item_num")] public int PurchaseItemNum { get; set; }
|
||||
[JsonPropertyName("purchase_name")] public string PurchaseName { get; set; } = "";
|
||||
[JsonPropertyName("is_monthly_reset")] public bool IsMonthlyReset { get; set; }
|
||||
[JsonPropertyName("purchase_limit")] public int PurchaseLimit { get; set; }
|
||||
}
|
||||
@@ -99,6 +99,7 @@ public static class Program
|
||||
await new PaymentItemImporter().ImportAsync(context, opts.SeedDir);
|
||||
await new ItemImporter().ImportAsync(context, opts.SeedDir);
|
||||
await new SleeveShopImporter().ImportAsync(context, opts.SeedDir);
|
||||
await new ItemPurchaseImporter().ImportAsync(context, opts.SeedDir);
|
||||
var puzzleImporter = new PuzzleImporter();
|
||||
await puzzleImporter.ImportGroupsAsync(context, opts.SeedDir);
|
||||
await puzzleImporter.ImportPuzzlesAsync(context, opts.SeedDir);
|
||||
|
||||
Reference in New Issue
Block a user