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(
|
this.checkPurchaseIsWithinTraderItemLimit(
|
||||||
sessionID,
|
sessionID,
|
||||||
|
pmcData,
|
||||||
buyRequestData.tid,
|
buyRequestData.tid,
|
||||||
itemPurchased,
|
itemPurchased,
|
||||||
buyRequestData.item_id,
|
buyRequestData.item_id,
|
||||||
@ -151,6 +152,7 @@ export class TradeHelper
|
|||||||
// Will throw error if check fails
|
// Will throw error if check fails
|
||||||
this.checkPurchaseIsWithinTraderItemLimit(
|
this.checkPurchaseIsWithinTraderItemLimit(
|
||||||
sessionID,
|
sessionID,
|
||||||
|
pmcData,
|
||||||
buyRequestData.tid,
|
buyRequestData.tid,
|
||||||
itemPurchased,
|
itemPurchased,
|
||||||
buyRequestData.item_id,
|
buyRequestData.item_id,
|
||||||
@ -293,6 +295,7 @@ export class TradeHelper
|
|||||||
/**
|
/**
|
||||||
* Traders allow a limited number of purchases per refresh cycle (default 60 mins)
|
* Traders allow a limited number of purchases per refresh cycle (default 60 mins)
|
||||||
* @param sessionId Session id
|
* @param sessionId Session id
|
||||||
|
* @param pmcData Profile making the purchase
|
||||||
* @param traderId Trader assort is purchased from
|
* @param traderId Trader assort is purchased from
|
||||||
* @param assortBeingPurchased the item from trader being bought
|
* @param assortBeingPurchased the item from trader being bought
|
||||||
* @param assortId Id of assort being purchased
|
* @param assortId Id of assort being purchased
|
||||||
@ -300,21 +303,27 @@ export class TradeHelper
|
|||||||
*/
|
*/
|
||||||
protected checkPurchaseIsWithinTraderItemLimit(
|
protected checkPurchaseIsWithinTraderItemLimit(
|
||||||
sessionId: string,
|
sessionId: string,
|
||||||
|
pmcData: IPmcData,
|
||||||
traderId: string,
|
traderId: string,
|
||||||
assortBeingPurchased: Item,
|
assortBeingPurchased: Item,
|
||||||
assortId: string,
|
assortId: string,
|
||||||
count: number,
|
count: number,
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
const traderPurchaseData = this.traderPurchasePersisterService.getProfileTraderPurchase(
|
const traderPurchaseData
|
||||||
|
= this.traderPurchasePersisterService.getProfileTraderPurchase(
|
||||||
sessionId,
|
sessionId,
|
||||||
traderId,
|
traderId,
|
||||||
assortBeingPurchased._id,
|
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(
|
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
|
// Iterate over assorts bought and add to profile
|
||||||
for (const purchasedItem of newPurchaseDetails.items)
|
for (const purchasedItem of newPurchaseDetails.items)
|
||||||
{
|
{
|
||||||
if (!profile.traderPurchases)
|
const currentTime = this.timeUtil.getTimestamp();
|
||||||
{
|
|
||||||
profile.traderPurchases = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!profile.traderPurchases[traderId])
|
// Nullguard traderPurchases
|
||||||
{
|
profile.traderPurchases ||= {};
|
||||||
profile.traderPurchases[traderId] = {};
|
// Nullguard traderPurchases for this trader
|
||||||
}
|
profile.traderPurchases[traderId] ||= {};
|
||||||
|
|
||||||
// Null guard when dict doesnt exist
|
// Null guard when dict doesnt exist
|
||||||
const currentTime = this.timeUtil.getTimestamp();
|
|
||||||
if (!profile.traderPurchases[traderId][purchasedItem.itemId])
|
if (!profile.traderPurchases[traderId][purchasedItem.itemId])
|
||||||
{
|
{
|
||||||
profile.traderPurchases[traderId][purchasedItem.itemId] = {
|
profile.traderPurchases[traderId][purchasedItem.itemId] = {
|
||||||
@ -434,7 +431,9 @@ export class TraderHelper
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
profile.traderPurchases[traderId][purchasedItem.itemId].count + purchasedItem.count
|
profile.traderPurchases[traderId][purchasedItem.itemId].count + purchasedItem.count
|
||||||
> itemPurchased.upd!.BuyRestrictionMax!
|
> this.getAccountTypeAdjustedTraderPurchaseLimit(
|
||||||
|
itemPurchased.upd!.BuyRestrictionMax!,
|
||||||
|
profile.characters.pmc.Info.GameVersion)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
throw new Error(
|
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
|
* Get the highest rouble price for an item from traders
|
||||||
* UNUSED
|
* UNUSED
|
||||||
|
Loading…
x
Reference in New Issue
Block a user