Perform currency conversion at end of getDynamicOfferPriceForOffer()
if necessary instead of for each item in loop
linting
This commit is contained in:
parent
f2254b150a
commit
b5565f3901
@ -129,7 +129,7 @@ export class RagfairOfferGenerator
|
|||||||
// Add cartridges to offers for ammo boxes
|
// Add cartridges to offers for ammo boxes
|
||||||
if (this.itemHelper.isOfBaseclass(itemsClone[0]._tpl, BaseClasses.AMMO_BOX))
|
if (this.itemHelper.isOfBaseclass(itemsClone[0]._tpl, BaseClasses.AMMO_BOX))
|
||||||
{
|
{
|
||||||
// On offer refresh dont re-add cartidges to ammobox that already has cartidges
|
// On offer refresh dont re-add cartridges to ammo box that already has cartridges
|
||||||
if (Object.keys(itemsClone).length === 1)
|
if (Object.keys(itemsClone).length === 1)
|
||||||
{
|
{
|
||||||
this.itemHelper.addCartridgesToAmmoBox(itemsClone, this.itemHelper.getItem(items[0]._tpl)[1]);
|
this.itemHelper.addCartridgesToAmmoBox(itemsClone, this.itemHelper.getItem(items[0]._tpl)[1]);
|
||||||
@ -154,9 +154,9 @@ export class RagfairOfferGenerator
|
|||||||
},
|
},
|
||||||
root: items[0]._id,
|
root: items[0]._id,
|
||||||
items: itemsClone,
|
items: itemsClone,
|
||||||
|
itemsCost: Math.round(this.handbookHelper.getTemplatePrice(items[0]._tpl)), // Handbook price
|
||||||
requirements: offerRequirements,
|
requirements: offerRequirements,
|
||||||
requirementsCost: roublePrice,
|
requirementsCost: roublePrice,
|
||||||
itemsCost: Math.round(this.handbookHelper.getTemplatePrice(items[0]._tpl)), // Handbook price
|
|
||||||
summaryCost: roublePrice,
|
summaryCost: roublePrice,
|
||||||
startTime: time,
|
startTime: time,
|
||||||
endTime: this.getOfferEndTime(userID, time),
|
endTime: this.getOfferEndTime(userID, time),
|
||||||
|
@ -216,14 +216,14 @@ export class RagfairPriceService implements OnLoad
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a currency cost for an item and its mods
|
* Generate a currency cost for an item and its mods
|
||||||
* @param items Item with mods to get price for
|
* @param offerItems Item with mods to get price for
|
||||||
* @param desiredCurrency Currency price desired in
|
* @param desiredCurrency Currency price desired in
|
||||||
* @param isPackOffer Price is for a pack type offer
|
* @param isPackOffer Price is for a pack type offer
|
||||||
* @returns cost of item in desired currency
|
* @returns cost of item in desired currency
|
||||||
*/
|
*/
|
||||||
public getDynamicOfferPriceForOffer(items: Item[], desiredCurrency: string, isPackOffer: boolean): number
|
public getDynamicOfferPriceForOffer(offerItems: Item[], desiredCurrency: string, isPackOffer: boolean): number
|
||||||
{
|
{
|
||||||
const rootItem = items[0];
|
const rootItem = offerItems[0];
|
||||||
|
|
||||||
// Price to return
|
// Price to return
|
||||||
let price = 0;
|
let price = 0;
|
||||||
@ -231,8 +231,9 @@ export class RagfairPriceService implements OnLoad
|
|||||||
let endLoop = false;
|
let endLoop = false;
|
||||||
let isPreset = false;
|
let isPreset = false;
|
||||||
let manuallyAdjusted = false;
|
let manuallyAdjusted = false;
|
||||||
for (const item of items)
|
for (const item of offerItems)
|
||||||
{
|
{
|
||||||
|
// Armor insert, skip - we dont factor these into an items price
|
||||||
if (this.itemHelper.isOfBaseclass(item._tpl, BaseClasses.BUILT_IN_INSERTS))
|
if (this.itemHelper.isOfBaseclass(item._tpl, BaseClasses.BUILT_IN_INSERTS))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@ -260,11 +261,12 @@ export class RagfairPriceService implements OnLoad
|
|||||||
const itemDetails = this.itemHelper.getItem(item._tpl);
|
const itemDetails = this.itemHelper.getItem(item._tpl);
|
||||||
if (this.presetHelper.isPreset(item.upd?.sptPresetId) && itemDetails[1]._props.weapFireType)
|
if (this.presetHelper.isPreset(item.upd?.sptPresetId) && itemDetails[1]._props.weapFireType)
|
||||||
{
|
{
|
||||||
itemPrice = this.getWeaponPresetPrice(item, items, itemPrice);
|
itemPrice = this.getWeaponPresetPrice(item, offerItems, itemPrice);
|
||||||
endLoop = true;
|
endLoop = true;
|
||||||
isPreset = true;
|
isPreset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for existance of manual price adjustment multiplier
|
||||||
const manualPriceMultipler = this.ragfairConfig.dynamic.itemPriceMultiplier[item._tpl];
|
const manualPriceMultipler = this.ragfairConfig.dynamic.itemPriceMultiplier[item._tpl];
|
||||||
if (manualPriceMultipler)
|
if (manualPriceMultipler)
|
||||||
{
|
{
|
||||||
@ -272,12 +274,6 @@ export class RagfairPriceService implements OnLoad
|
|||||||
itemPrice *= manualPriceMultipler;
|
itemPrice *= manualPriceMultipler;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to different currency if desiredCurrency param is not roubles
|
|
||||||
if (desiredCurrency !== Money.ROUBLES)
|
|
||||||
{
|
|
||||||
itemPrice = this.handbookHelper.fromRUB(itemPrice, desiredCurrency);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Multiply dynamic price by quality modifier
|
// Multiply dynamic price by quality modifier
|
||||||
const itemQualityModifier = this.itemHelper.getItemQualityModifier(item);
|
const itemQualityModifier = this.itemHelper.getItemQualityModifier(item);
|
||||||
price += itemPrice * itemQualityModifier;
|
price += itemPrice * itemQualityModifier;
|
||||||
@ -289,8 +285,8 @@ export class RagfairPriceService implements OnLoad
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip items with children
|
// Check for unreasonable price on singular items
|
||||||
if (items.length === 1 && !manuallyAdjusted)
|
if (offerItems.length === 1 && !manuallyAdjusted)
|
||||||
{
|
{
|
||||||
const rootItemDb = this.itemHelper.getItem(rootItem._tpl)[1];
|
const rootItemDb = this.itemHelper.getItem(rootItem._tpl)[1];
|
||||||
let unreasonableItemPriceChange: IUnreasonableModPrices;
|
let unreasonableItemPriceChange: IUnreasonableModPrices;
|
||||||
@ -314,9 +310,17 @@ export class RagfairPriceService implements OnLoad
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get price multiplier min/max to vary price
|
||||||
const rangeValues = this.getOfferTypeRangeValues(isPreset, isPackOffer);
|
const rangeValues = this.getOfferTypeRangeValues(isPreset, isPackOffer);
|
||||||
price = this.randomiseOfferPrice(price, rangeValues);
|
price = this.randomiseOfferPrice(price, rangeValues);
|
||||||
|
|
||||||
|
// Convert to different currency if desiredCurrency param is not roubles
|
||||||
|
if (desiredCurrency !== Money.ROUBLES)
|
||||||
|
{
|
||||||
|
price = this.handbookHelper.fromRUB(price, desiredCurrency);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guard against weird prices
|
||||||
if (price < 1)
|
if (price < 1)
|
||||||
{
|
{
|
||||||
price = 1;
|
price = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user