diff --git a/project/src/generators/RagfairOfferGenerator.ts b/project/src/generators/RagfairOfferGenerator.ts index 6e476ed8..a9f22f37 100644 --- a/project/src/generators/RagfairOfferGenerator.ts +++ b/project/src/generators/RagfairOfferGenerator.ts @@ -129,7 +129,7 @@ export class RagfairOfferGenerator // Add cartridges to offers for ammo boxes 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) { this.itemHelper.addCartridgesToAmmoBox(itemsClone, this.itemHelper.getItem(items[0]._tpl)[1]); @@ -154,9 +154,9 @@ export class RagfairOfferGenerator }, root: items[0]._id, items: itemsClone, + itemsCost: Math.round(this.handbookHelper.getTemplatePrice(items[0]._tpl)), // Handbook price requirements: offerRequirements, requirementsCost: roublePrice, - itemsCost: Math.round(this.handbookHelper.getTemplatePrice(items[0]._tpl)), // Handbook price summaryCost: roublePrice, startTime: time, endTime: this.getOfferEndTime(userID, time), diff --git a/project/src/services/RagfairPriceService.ts b/project/src/services/RagfairPriceService.ts index e05e2e3b..6762bcec 100644 --- a/project/src/services/RagfairPriceService.ts +++ b/project/src/services/RagfairPriceService.ts @@ -216,14 +216,14 @@ export class RagfairPriceService implements OnLoad /** * 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 isPackOffer Price is for a pack type offer * @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 let price = 0; @@ -231,8 +231,9 @@ export class RagfairPriceService implements OnLoad let endLoop = false; let isPreset = 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)) { continue; @@ -260,11 +261,12 @@ export class RagfairPriceService implements OnLoad const itemDetails = this.itemHelper.getItem(item._tpl); 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; isPreset = true; } + // Check for existance of manual price adjustment multiplier const manualPriceMultipler = this.ragfairConfig.dynamic.itemPriceMultiplier[item._tpl]; if (manualPriceMultipler) { @@ -272,12 +274,6 @@ export class RagfairPriceService implements OnLoad 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 const itemQualityModifier = this.itemHelper.getItemQualityModifier(item); price += itemPrice * itemQualityModifier; @@ -289,8 +285,8 @@ export class RagfairPriceService implements OnLoad } } - // Skip items with children - if (items.length === 1 && !manuallyAdjusted) + // Check for unreasonable price on singular items + if (offerItems.length === 1 && !manuallyAdjusted) { const rootItemDb = this.itemHelper.getItem(rootItem._tpl)[1]; 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); 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) { price = 1;