refactor(pack): collapse null-forgive in gacha-point exchange balance guard
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user