From 990fe1cd7f692c739f3c715f4b0310a964db5e19 Mon Sep 17 00:00:00 2001 From: CWX Date: Tue, 29 Apr 2025 21:41:26 +0100 Subject: [PATCH] Fix: taking the wrong amount --- .../Services/PaymentService.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Services/PaymentService.cs b/Libraries/SPTarkov.Server.Core/Services/PaymentService.cs index 71cc491f..5469f2a0 100644 --- a/Libraries/SPTarkov.Server.Core/Services/PaymentService.cs +++ b/Libraries/SPTarkov.Server.Core/Services/PaymentService.cs @@ -69,7 +69,12 @@ public class PaymentService( else { // If the item is money, add its count to the currencyAmounts object. - currencyAmounts.TryAdd(item.Template, currencyAmounts.GetValueOrDefault(item.Template, 0) + itemRequest.Count); + // sometimes the currency can be in two parts, so it fails to tryadd the second part + if (!currencyAmounts.TryAdd(item.Template, currencyAmounts.GetValueOrDefault(item.Template, 0) + itemRequest.Count)) + { + // if it fails, add the amount to the existing amount + currencyAmounts[item.Template] += itemRequest.Count; + } } } else @@ -77,7 +82,12 @@ public class PaymentService( // Used by `SptInsure` // Handle differently, `id` is the money type tpl var currencyTpl = itemRequest.Id; - currencyAmounts.TryAdd(currencyTpl, currencyAmounts.GetValueOrDefault(currencyTpl, 0) + itemRequest.Count); + // sometimes the currency can be in two parts, so it fails to tryadd the second part + if (!currencyAmounts.TryAdd(currencyTpl, currencyAmounts.GetValueOrDefault(currencyTpl, 0) + itemRequest.Count)) + { + // if it fails, add the amount to the existing amount + currencyAmounts[currencyTpl] += itemRequest.Count; + } } }