From 2e021c8b9e3fc2fbeeff1150880e4d0a3c7f9672 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Fri, 29 May 2026 14:12:43 -0400 Subject: [PATCH] refactor(builddeck): route currency spend through CurrencySpendService Inject ICurrencySpendService and replace the inline crystal/rupee debit block in BuildDeckController.Buy with TrySpendAsync calls, so freeplay mode gets the no-deduct path automatically. All 18 BuildDeckController tests pass unchanged. Co-Authored-By: Claude Sonnet 4.6 --- .../Controllers/BuildDeckController.cs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/SVSim.EmulatedEntrypoint/Controllers/BuildDeckController.cs b/SVSim.EmulatedEntrypoint/Controllers/BuildDeckController.cs index 5fb3075..01e12df 100644 --- a/SVSim.EmulatedEntrypoint/Controllers/BuildDeckController.cs +++ b/SVSim.EmulatedEntrypoint/Controllers/BuildDeckController.cs @@ -22,15 +22,18 @@ public class BuildDeckController : SVSimController private readonly IBuildDeckRepository _repo; private readonly SVSimDbContext _db; private readonly RewardGrantService _rewards; + private readonly ICurrencySpendService _spend; public BuildDeckController( IBuildDeckRepository repo, SVSimDbContext db, - RewardGrantService rewards) + RewardGrantService rewards, + ICurrencySpendService spend) { _repo = repo; _db = db; _rewards = rewards; + _spend = spend; } /// @@ -200,19 +203,15 @@ public class BuildDeckController : SVSimController // Debit + post-state currency entry if (request.SalesType == 1) { - ulong cost = (ulong)priceCrystal!.Value; - if (viewer.Currency.Crystals < cost) - return BadRequest(new { error = "insufficient_crystals" }); - viewer.Currency.Crystals -= cost; - rewardList.Add(new RewardListEntry { RewardType = 2, RewardId = 0, RewardNum = (int)viewer.Currency.Crystals }); + var r = await _spend.TrySpendAsync(viewer, SpendCurrency.Crystal, priceCrystal!.Value); + if (!r.Success) return BadRequest(new { error = "insufficient_crystals" }); + rewardList.Add(new RewardListEntry { RewardType = 2, RewardId = 0, RewardNum = (int)r.PostStateTotal }); } else if (request.SalesType == 2) { - ulong cost = (ulong)priceRupy!.Value; - if (viewer.Currency.Rupees < cost) - return BadRequest(new { error = "insufficient_rupees" }); - viewer.Currency.Rupees -= cost; - rewardList.Add(new RewardListEntry { RewardType = 9, RewardId = 0, RewardNum = (int)viewer.Currency.Rupees }); + var r = await _spend.TrySpendAsync(viewer, SpendCurrency.Rupee, priceRupy!.Value); + if (!r.Success) return BadRequest(new { error = "insufficient_rupees" }); + rewardList.Add(new RewardListEntry { RewardType = 9, RewardId = 0, RewardNum = (int)r.PostStateTotal }); } // sales_type == 0 (free): no debit, no currency entry