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 <mwarciel@gmail.com>
Co-committed-by: Leaves <mwarciel@gmail.com>
This commit is contained in:
Leaves 2024-03-30 12:55:18 +00:00 committed by chomp
parent 4bb5e3de43
commit efb69d7148
2 changed files with 8 additions and 3 deletions

View File

@ -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);

View File

@ -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;
}