Added implementation of BSG feature Increased personal trader item limits by 20% for Edge of Darkness and The Unheard edition owners who upgraded from Edge of Darkness
This fixes EoD/UH/DEV profiles throwing errors when purchasing items near their trader BuyRestrictionMax limits
This commit is contained in:
parent
5d3ea2ef83
commit
f263f8b0cb
@ -88,6 +88,7 @@ export class TradeHelper
|
||||
{
|
||||
this.checkPurchaseIsWithinTraderItemLimit(
|
||||
sessionID,
|
||||
pmcData,
|
||||
buyRequestData.tid,
|
||||
itemPurchased,
|
||||
buyRequestData.item_id,
|
||||
@ -151,6 +152,7 @@ export class TradeHelper
|
||||
// Will throw error if check fails
|
||||
this.checkPurchaseIsWithinTraderItemLimit(
|
||||
sessionID,
|
||||
pmcData,
|
||||
buyRequestData.tid,
|
||||
itemPurchased,
|
||||
buyRequestData.item_id,
|
||||
@ -293,6 +295,7 @@ export class TradeHelper
|
||||
/**
|
||||
* Traders allow a limited number of purchases per refresh cycle (default 60 mins)
|
||||
* @param sessionId Session id
|
||||
* @param pmcData Profile making the purchase
|
||||
* @param traderId Trader assort is purchased from
|
||||
* @param assortBeingPurchased the item from trader being bought
|
||||
* @param assortId Id of assort being purchased
|
||||
@ -300,21 +303,27 @@ export class TradeHelper
|
||||
*/
|
||||
protected checkPurchaseIsWithinTraderItemLimit(
|
||||
sessionId: string,
|
||||
pmcData: IPmcData,
|
||||
traderId: string,
|
||||
assortBeingPurchased: Item,
|
||||
assortId: string,
|
||||
count: number,
|
||||
): void
|
||||
{
|
||||
const traderPurchaseData = this.traderPurchasePersisterService.getProfileTraderPurchase(
|
||||
const traderPurchaseData
|
||||
= this.traderPurchasePersisterService.getProfileTraderPurchase(
|
||||
sessionId,
|
||||
traderId,
|
||||
assortBeingPurchased._id,
|
||||
);
|
||||
if ((traderPurchaseData?.count ?? 0 + count) > assortBeingPurchased.upd?.BuyRestrictionMax)
|
||||
const traderItemPurchaseLimit
|
||||
= this.traderHelper.getAccountTypeAdjustedTraderPurchaseLimit(
|
||||
assortBeingPurchased.upd?.BuyRestrictionMax,
|
||||
pmcData.Info.GameVersion);
|
||||
if ((traderPurchaseData?.count ?? 0 + count) > traderItemPurchaseLimit)
|
||||
{
|
||||
throw new Error(
|
||||
`Unable to purchase ${count} items, this would exceed your purchase limit of ${assortBeingPurchased.upd.BuyRestrictionMax} from the traders assort: ${assortId} this refresh`,
|
||||
`Unable to purchase: ${count} items, this would exceed your purchase limit of ${traderItemPurchaseLimit} from the trader: ${traderId} assort: ${assortId} this refresh`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -410,18 +410,15 @@ export class TraderHelper
|
||||
// Iterate over assorts bought and add to profile
|
||||
for (const purchasedItem of newPurchaseDetails.items)
|
||||
{
|
||||
if (!profile.traderPurchases)
|
||||
{
|
||||
profile.traderPurchases = {};
|
||||
}
|
||||
const currentTime = this.timeUtil.getTimestamp();
|
||||
|
||||
if (!profile.traderPurchases[traderId])
|
||||
{
|
||||
profile.traderPurchases[traderId] = {};
|
||||
}
|
||||
// Nullguard traderPurchases
|
||||
profile.traderPurchases ||= {};
|
||||
// Nullguard traderPurchases for this trader
|
||||
profile.traderPurchases[traderId] ||= {};
|
||||
|
||||
// Null guard when dict doesnt exist
|
||||
const currentTime = this.timeUtil.getTimestamp();
|
||||
|
||||
if (!profile.traderPurchases[traderId][purchasedItem.itemId])
|
||||
{
|
||||
profile.traderPurchases[traderId][purchasedItem.itemId] = {
|
||||
@ -434,7 +431,9 @@ export class TraderHelper
|
||||
|
||||
if (
|
||||
profile.traderPurchases[traderId][purchasedItem.itemId].count + purchasedItem.count
|
||||
> itemPurchased.upd!.BuyRestrictionMax!
|
||||
> this.getAccountTypeAdjustedTraderPurchaseLimit(
|
||||
itemPurchased.upd!.BuyRestrictionMax!,
|
||||
profile.characters.pmc.Info.GameVersion)
|
||||
)
|
||||
{
|
||||
throw new Error(
|
||||
@ -450,6 +449,22 @@ export class TraderHelper
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* EoD and Unheard get a 20% bonus to personal trader limit purchases
|
||||
* @param buyRestrictionMax Existing value from trader item
|
||||
* @param gameVersion Profiles game version
|
||||
* @returns buyRestrictionMax value
|
||||
*/
|
||||
public getAccountTypeAdjustedTraderPurchaseLimit(buyRestrictionMax: number, gameVersion: string): number
|
||||
{
|
||||
if (["edge_of_darkness", "unheard"].includes(gameVersion))
|
||||
{
|
||||
return Math.floor(buyRestrictionMax * 1.2);
|
||||
}
|
||||
|
||||
return buyRestrictionMax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the highest rouble price for an item from traders
|
||||
* UNUSED
|
||||
|
Loading…
x
Reference in New Issue
Block a user