From efb69d71488d91453161cd402a9352e63b19c625 Mon Sep 17 00:00:00 2001 From: Leaves Date: Sat, 30 Mar 2024 12:55:18 +0000 Subject: [PATCH] Actually fixed so that multiple profiles no longer share trader buy limits (!276) This fixes a bug I found that the server uses partially old logic when using the ``traderConfig.persistPurchaseDataInProfile`` Now it works fine for multiple profiles. How to test before and after ``` start server make dev account buy something trade limited like ASH12 ammo. (Buy all) make new dev account try to buy same thing ``` Before it gave the user the error that you've already reached the limit. Even when you had bought nothing on that profile. Now the trader properly sells you the stuff, with your own profile limit. Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/276 Co-authored-by: Leaves Co-committed-by: Leaves --- project/src/helpers/TradeHelper.ts | 6 +++--- project/src/helpers/TraderHelper.ts | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/project/src/helpers/TradeHelper.ts b/project/src/helpers/TradeHelper.ts index 4ac8148f..07be4b87 100644 --- a/project/src/helpers/TradeHelper.ts +++ b/project/src/helpers/TradeHelper.ts @@ -103,7 +103,7 @@ export class TradeHelper items: [{ itemId: buyRequestData.item_id, count: buyCount }], traderId: buyRequestData.tid, }; - this.traderHelper.addTraderPurchasesToPlayerProfile(sessionID, itemPurchaseDat); + this.traderHelper.addTraderPurchasesToPlayerProfile(sessionID, itemPurchaseDat, itemPurchased); } if (assortHasBuyRestrictions) @@ -176,10 +176,10 @@ export class TradeHelper items: [{ itemId: buyRequestData.item_id, count: buyCount }], traderId: buyRequestData.tid, }; - this.traderHelper.addTraderPurchasesToPlayerProfile(sessionID, itemPurchaseDat); + this.traderHelper.addTraderPurchasesToPlayerProfile(sessionID, itemPurchaseDat, itemPurchased); } - if (assortHasBuyRestrictions) + else if (assortHasBuyRestrictions) { // Increment non-fence trader item buy count this.incrementAssortBuyCount(itemPurchased, buyCount); diff --git a/project/src/helpers/TraderHelper.ts b/project/src/helpers/TraderHelper.ts index 7f391b75..6994c7e7 100644 --- a/project/src/helpers/TraderHelper.ts +++ b/project/src/helpers/TraderHelper.ts @@ -320,6 +320,7 @@ export class TraderHelper public addTraderPurchasesToPlayerProfile( sessionID: string, newPurchaseDetails: { items: { itemId: string; count: number; }[]; traderId: string; }, + itemPurchased: Item ): void { const profile = this.profileHelper.getFullProfile(sessionID); @@ -350,6 +351,10 @@ export class TraderHelper continue; } + if( profile.traderPurchases[traderId][purchasedItem.itemId].count + purchasedItem.count > itemPurchased.upd.BuyRestrictionMax ) + { + throw new Error("Unable to purchase item, Purchase limit reached"); + } profile.traderPurchases[traderId][purchasedItem.itemId].count += purchasedItem.count; profile.traderPurchases[traderId][purchasedItem.itemId].purchaseTimestamp = currentTime; }