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 <mwarciel@gmail.com>
Co-committed-by: Leaves <mwarciel@gmail.com>
This commit is contained in:
Leaves 2024-04-06 21:22:41 +00:00 committed by chomp
parent 35e48add20
commit 3be1768672

View File

@ -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 // Decrement trader item count
itemPurchased.upd.StackObjectsCount -= buyCount; itemPurchased.upd.StackObjectsCount -= buyCount;