diff --git a/SVSim.EmulatedEntrypoint/Controllers/SpotCardExchangeController.cs b/SVSim.EmulatedEntrypoint/Controllers/SpotCardExchangeController.cs index 584cbc7..d5d8ec9 100644 --- a/SVSim.EmulatedEntrypoint/Controllers/SpotCardExchangeController.cs +++ b/SVSim.EmulatedEntrypoint/Controllers/SpotCardExchangeController.cs @@ -30,12 +30,14 @@ public class SpotCardExchangeController : SVSimController private readonly SVSimDbContext _db; private readonly RewardGrantService _rewards; private readonly TimeProvider _time; + private readonly ICurrencySpendService _spend; - public SpotCardExchangeController(SVSimDbContext db, RewardGrantService rewards, TimeProvider time) + public SpotCardExchangeController(SVSimDbContext db, RewardGrantService rewards, TimeProvider time, ICurrencySpendService spend) { _db = db; _rewards = rewards; _time = time; + _spend = spend; } [HttpPost("top")] @@ -131,14 +133,14 @@ public class SpotCardExchangeController : SVSimController // Debit spot points. Client-supplied exchange_point isn't authoritative — server uses // catalog price. Mirroring the build_deck/sleeve convention: post-state currency entry // first, then grants. - if (viewer.Currency.SpotPoints < (ulong)entry.ExchangePoint) + var spotRes = await _spend.TrySpendAsync(viewer, SpendCurrency.SpotPoint, entry.ExchangePoint); + if (!spotRes.Success) return BadRequest(new { error = "insufficient_spot_points" }); - viewer.Currency.SpotPoints -= (ulong)entry.ExchangePoint; rewardList.Add(new RewardListEntry { RewardType = (int)UserGoodsType.SpotCardPoint, RewardId = 0, - RewardNum = checked((int)viewer.Currency.SpotPoints), + RewardNum = checked((int)spotRes.PostStateTotal), }); // Grant the card itself via the existing card dispatcher (handles cosmetic cascade).