From b40e41bd3d5231cbb1ed29019d78334237f27056 Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 6 Feb 2024 15:52:22 +0000 Subject: [PATCH] Improve sellChance logic Two changes: Calcualte the quality of an item and its mods, not just root item Calcualte the average price of an offer using item + mods, not just root item --- project/src/controllers/RagfairController.ts | 6 +++-- project/src/helpers/RagfairHelper.ts | 16 ++++++++++++++ project/src/services/RagfairPriceService.ts | 23 ++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/project/src/controllers/RagfairController.ts b/project/src/controllers/RagfairController.ts index 4574134f..4d6ea76d 100644 --- a/project/src/controllers/RagfairController.ts +++ b/project/src/controllers/RagfairController.ts @@ -390,8 +390,10 @@ export class RagfairController playerListedPriceInRub, ); const rootItem = offer.items[0]; - const qualityMultiplier = this.itemHelper.getItemQualityModifier(rootItem); - const averageOfferPrice = this.ragfairPriceService.getFleaPriceForItem(rootItem._tpl) + + // Get average of items quality+children + const qualityMultiplier = this.ragfairHelper.getItemQualityModifierForOfferItems(offer.items); + const averageOfferPrice = this.ragfairPriceService.getFleaPriceForOfferItems(offer.items) * rootItem.upd.StackObjectsCount * qualityMultiplier; const itemStackCount = (offerRequest.sellInOnePiece) ? 1 : rootItem.upd.StackObjectsCount; diff --git a/project/src/helpers/RagfairHelper.ts b/project/src/helpers/RagfairHelper.ts index b35f0e4b..3facc586 100644 --- a/project/src/helpers/RagfairHelper.ts +++ b/project/src/helpers/RagfairHelper.ts @@ -199,4 +199,20 @@ export class RagfairHelper return "₽"; } } + + /** + * Calcualte the average quality of an item and its children + * @param offerItems An offers item to process + * @returns % quality modifer between 0 and 1 + */ + public getItemQualityModifierForOfferItems(offerItems: Item[]): number + { + let qualityModifier = 1; + for (const item of offerItems) + { + qualityModifier += this.itemHelper.getItemQualityModifier(item); + } + + return Math.min(qualityModifier / offerItems.length, 1); + } } diff --git a/project/src/services/RagfairPriceService.ts b/project/src/services/RagfairPriceService.ts index 12ee83b6..7519e70c 100644 --- a/project/src/services/RagfairPriceService.ts +++ b/project/src/services/RagfairPriceService.ts @@ -9,6 +9,7 @@ import { MinMax } from "@spt-aki/models/common/MinMax"; import { IPreset } from "@spt-aki/models/eft/common/IGlobals"; 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"; @@ -115,6 +116,28 @@ export class RagfairPriceService implements OnLoad return itemPrice; } + /** + * Get the flea price for an offers items + children + * @param offerItems offer item + children to process + * @returns Rouble price + */ + public getFleaPriceForOfferItems(offerItems: Item[]): number + { + // Preset weapons take the direct prices.json value, otherwise they're massivly inflated + if (this.itemHelper.isOfBaseclass(offerItems[0]._tpl, BaseClasses.WEAPON)) + { + return this.getFleaPriceForItem(offerItems[0]._tpl); + } + + let totalPrice = 0; + for (const item of offerItems) + { + totalPrice += this.getFleaPriceForItem(item._tpl); + } + + return totalPrice; + } + /** * get the dynamic (flea) price for an item * Grabs prices from prices.json and stores in class if none currently exist