From 3be17686721bfcde0202a96c95f14d7858384ea8 Mon Sep 17 00:00:00 2001 From: Leaves Date: Sat, 6 Apr 2024 21:22:41 +0000 Subject: [PATCH] Make sure trader has enough stock before selling (!278) Make sure trader has enough stock before selling Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/278 Co-authored-by: Leaves Co-committed-by: Leaves --- project/src/helpers/TradeHelper.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/project/src/helpers/TradeHelper.ts b/project/src/helpers/TradeHelper.ts index 59d9bd1c..358860e0 100644 --- a/project/src/helpers/TradeHelper.ts +++ b/project/src/helpers/TradeHelper.ts @@ -158,6 +158,14 @@ export class TradeHelper ); } + // Check if trader has enough stock + if (itemPurchased.upd.StackObjectsCount < buyCount) + { + throw new Error( + `Unable to purchase ${buyCount} items, this would exceed the remaining stock left ${itemPurchased.upd.StackObjectsCount} from the traders assort: ${buyRequestData.tid} this refresh`, + ); + } + // Decrement trader item count itemPurchased.upd.StackObjectsCount -= buyCount;