diff --git a/project/assets/configs/ragfair.json b/project/assets/configs/ragfair.json index 5e696a16..fe2ddd5a 100644 --- a/project/assets/configs/ragfair.json +++ b/project/assets/configs/ragfair.json @@ -303,8 +303,8 @@ "5448fe124bdc2da5018b4567": { "itemType": "Weapon Mod", "enabled": true, - "handbookPriceOverMultiplier": 9, - "newPriceHandbookMultiplier": 9 + "handbookPriceOverMultiplier": 6, + "newPriceHandbookMultiplier": 6 }, "57864a66245977548f04a81f": { "itemType": "Electronics", diff --git a/project/src/services/ProfileFixerService.ts b/project/src/services/ProfileFixerService.ts index 50031a3e..c5ce0cfa 100644 --- a/project/src/services/ProfileFixerService.ts +++ b/project/src/services/ProfileFixerService.ts @@ -158,11 +158,6 @@ export class ProfileFixerService this.fixNullTraderSalesSums(pmcProfile); this.updateProfileQuestDataValues(pmcProfile); - - if (Object.keys(this.ragfairConfig.dynamic.unreasonableModPrices).length > 0) - { - this.adjustUnreasonableModFleaPrices(); - } } /** @@ -391,47 +386,6 @@ export class ProfileFixerService } } - protected adjustUnreasonableModFleaPrices(): void - { - const db = this.databaseServer.getTables(); - const fleaPrices = db.templates.prices; - const handbookPrices = db.templates.handbook.Items; - - for (const itemTypeKey in this.ragfairConfig.dynamic.unreasonableModPrices) - { - const details = this.ragfairConfig.dynamic.unreasonableModPrices[itemTypeKey]; - if (!details?.enabled) - { - continue; - } - - for (const itemTpl in fleaPrices) - { - if (!this.itemHelper.isOfBaseclass(itemTpl, itemTypeKey)) - { - continue; - } - - const itemHandbookPrice = handbookPrices.find((x) => x.Id === itemTpl); - if (!itemHandbookPrice) - { - continue; - } - - if (fleaPrices[itemTpl] > (itemHandbookPrice.Price * details.handbookPriceOverMultiplier)) - { - if (fleaPrices[itemTpl] <= 1) - { - continue; - } - - // Price is over limit, adjust - fleaPrices[itemTpl] = itemHandbookPrice.Price * details.newPriceHandbookMultiplier; - } - } - } - } - /** * Add tag to profile to indicate when it was made * @param fullProfile diff --git a/project/src/services/RagfairPriceService.ts b/project/src/services/RagfairPriceService.ts index 400b8e4d..b94b6fab 100644 --- a/project/src/services/RagfairPriceService.ts +++ b/project/src/services/RagfairPriceService.ts @@ -7,12 +7,13 @@ import { PresetHelper } from "@spt-aki/helpers/PresetHelper"; import { TraderHelper } from "@spt-aki/helpers/TraderHelper"; import { MinMax } from "@spt-aki/models/common/MinMax"; import { IPreset } from "@spt-aki/models/eft/common/IGlobals"; +import { HandbookItem } from "@spt-aki/models/eft/common/tables/IHandbookBase"; import { Item } from "@spt-aki/models/eft/common/tables/IItem"; import { IBarterScheme } from "@spt-aki/models/eft/common/tables/ITrader"; import { BaseClasses } from "@spt-aki/models/enums/BaseClasses"; import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; import { Money } from "@spt-aki/models/enums/Money"; -import { IRagfairConfig } from "@spt-aki/models/spt/config/IRagfairConfig"; +import { IRagfairConfig, IUnreasonableModPrices } from "@spt-aki/models/spt/config/IRagfairConfig"; import { IRagfairServerPrices } from "@spt-aki/models/spt/ragfair/IRagfairServerPrices"; import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; import { ConfigServer } from "@spt-aki/servers/ConfigServer"; @@ -221,6 +222,8 @@ export class RagfairPriceService implements OnLoad */ public getDynamicOfferPriceForOffer(items: Item[], desiredCurrency: string, isPackOffer: boolean): number { + const rootItem = items[0]; + // Price to return let price = 0; @@ -278,6 +281,22 @@ export class RagfairPriceService implements OnLoad } } + // Skip items with children + if (items.length === 1) + { + const rootItemDb = this.itemHelper.getItem(rootItem._tpl)[1]; + const unreasonableItemPriceChange = this.ragfairConfig.dynamic.unreasonableModPrices[rootItemDb._parent]; + if (unreasonableItemPriceChange?.enabled) + { + price = this.adjustUnreasonablePrice( + this.databaseServer.getTables().templates.handbook.Items, + unreasonableItemPriceChange, + rootItem._tpl, + price, + ); + } + } + const rangeValues = this.getOfferTypeRangeValues(isPreset, isPackOffer); price = this.randomiseOfferPrice(price, rangeValues); @@ -289,6 +308,43 @@ export class RagfairPriceService implements OnLoad return price; } + /** + * using data from config, adjust an items price to be relative to its handbook price + * @param handbookPrices Prices of items in handbook + * @param unreasonableItemChange Change object from config + * @param itemTpl Item being adjusted + * @param price Current price of item + * @returns Adjusted price of item + */ + protected adjustUnreasonablePrice( + handbookPrices: HandbookItem[], + unreasonableItemChange: IUnreasonableModPrices, + itemTpl: string, + price: number, + ): number + { + const itemHandbookPrice = handbookPrices.find((handbookItem) => handbookItem.Id === itemTpl); + if (!itemHandbookPrice) + { + return price; + } + + // Flea price is over handbook price + if (price > (itemHandbookPrice.Price * unreasonableItemChange.handbookPriceOverMultiplier)) + { + // Skip extreme values + if (price <= 1) + { + return price; + } + + // Price is over limit, adjust + return itemHandbookPrice.Price * unreasonableItemChange.newPriceHandbookMultiplier; + } + + return price; + } + /** * Get different min/max price multipliers for different offer types (preset/pack/default) * @param isPreset Offer is a preset