From 1eaf0d0bc47a00442412c0aa38503963ccd90003 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Thu, 28 May 2026 23:42:32 -0400 Subject: [PATCH] refactor(pack): collapse null-forgive in gacha-point exchange balance guard --- SVSim.EmulatedEntrypoint/Services/GachaPointService.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/SVSim.EmulatedEntrypoint/Services/GachaPointService.cs b/SVSim.EmulatedEntrypoint/Services/GachaPointService.cs index 9ab0eb4..a8a07df 100644 --- a/SVSim.EmulatedEntrypoint/Services/GachaPointService.cs +++ b/SVSim.EmulatedEntrypoint/Services/GachaPointService.cs @@ -160,8 +160,7 @@ public sealed class GachaPointService : IGachaPointService int threshold = pack.GachaPointConfig.ExchangeablePoint; var balance = viewer.GachaPointBalances.FirstOrDefault(b => b.PackId == packId); - int currentPoints = balance?.Points ?? 0; - if (currentPoints < threshold) + if (balance is null || balance.Points < threshold) return ExchangeOutcome.Fail("insufficient_gacha_points"); // Validate the card is in the catalog by re-running GetRewardsAsync. This re-uses the @@ -176,8 +175,8 @@ public sealed class GachaPointService : IGachaPointService if (viewer.GachaPointReceived.Any(r => r.PackId == packId && r.CardId == cardId)) return ExchangeOutcome.Fail("already_received"); - // Debit balance + mark received. - balance!.Points -= threshold; + // Debit balance + mark received. (`balance` is non-null past the earlier guard.) + balance.Points -= threshold; viewer.GachaPointReceived.Add(new ViewerGachaPointReceived { PackId = packId, CardId = cardId, ReceivedAt = DateTime.UtcNow,