Adjusted how item quality % is calculated for player flea offers. Now excludes items without any quality modifier from calculation instead of assuming 100% (slightly lowers sell chance of things like armors)

Renamed `getItemQualityModifierForOfferItems()` to `getItemQualityModifierForItems()`
This commit is contained in:
Dev 2024-06-19 14:27:58 +01:00
parent 43a09c29c2
commit cf5411336f
5 changed files with 25 additions and 10 deletions

View File

@ -439,7 +439,7 @@ export class RagfairController
const rootItem = offer.items[0];
// Get average of items quality+children
const qualityMultiplier = this.itemHelper.getItemQualityModifierForOfferItems(offer.items);
const qualityMultiplier = this.itemHelper.getItemQualityModifierForItems(offer.items, true);
let averageOfferPrice = this.ragfairPriceService.getFleaPriceForOfferItems(offer.items);
// Check for and apply item price modifer if it exists

View File

@ -178,7 +178,7 @@ export class FenceBaseAssortGenerator
// Calculate preset price (root item + child items)
const price = this.handbookHelper.getTemplatePriceForItems(itemAndChildren);
const itemQualityModifier = this.itemHelper.getItemQualityModifierForOfferItems(itemAndChildren);
const itemQualityModifier = this.itemHelper.getItemQualityModifierForItems(itemAndChildren);
// Multiply weapon+mods rouble price by quality modifier
baseFenceAssort.barter_scheme[itemAndChildren[0]._id] = [[]];

View File

@ -503,9 +503,10 @@ export class ItemHelper
/**
* Calcualte the average quality of an item and its children
* @param items An offers item to process
* @param nonQualityItemsReturnNegative Treat items without a quality property as non-existant
* @returns % quality modifer between 0 and 1
*/
public getItemQualityModifierForOfferItems(items: Item[]): number
public getItemQualityModifierForItems(items: Item[], nonQualityItemsReturnNegative = false): number
{
if (this.isOfBaseclass(items[0]._tpl, BaseClasses.WEAPON))
{
@ -513,12 +514,20 @@ export class ItemHelper
}
let qualityModifier = 0;
let itemsWithQualityCount = 0;
for (const item of items)
{
qualityModifier += this.getItemQualityModifier(item);
const result = this.getItemQualityModifier(item, nonQualityItemsReturnNegative);
if (result === -1)
{
continue;
}
qualityModifier += result;
itemsWithQualityCount++;
}
return Math.min(qualityModifier / items.length, 1);
return Math.min(qualityModifier / itemsWithQualityCount, 1);
}
/**
@ -526,7 +535,7 @@ export class ItemHelper
* @param item
* @returns number between 0 and 1
*/
public getItemQualityModifier(item: Item): number
public getItemQualityModifier(item: Item, nonQualityItemsReturnNegative = false): number
{
// Default to 100%
let result = 1;
@ -573,6 +582,12 @@ export class ItemHelper
result = repairKit.Resource / itemDetails._props.MaxRepairResource;
}
// Not handled by any of the above + default value
if (nonQualityItemsReturnNegative && result === 1)
{
return -1;
}
if (result === 0)
{
// make item non-zero but still very low
@ -582,7 +597,7 @@ export class ItemHelper
return result;
}
return 1;
return result;
}
/**

View File

@ -644,7 +644,7 @@ export class RagfairOfferHelper
}
else
{
const itemQualityPercent = this.itemHelper.getItemQualityModifierForOfferItems(offer.items) * 100;
const itemQualityPercent = this.itemHelper.getItemQualityModifierForItems(offer.items) * 100;
if (itemQualityPercent < searchRequest.conditionFrom)
{
return false;

View File

@ -1035,7 +1035,7 @@ export class FenceService
const priceLimitRouble = this.traderConfig.fence.itemCategoryRoublePriceLimit[rootItemDb._parent];
const itemPrice
= this.handbookHelper.getTemplatePriceForItems(presetWithChildrenClone)
* this.itemHelper.getItemQualityModifierForOfferItems(presetWithChildrenClone);
* this.itemHelper.getItemQualityModifierForItems(presetWithChildrenClone);
if (priceLimitRouble)
{
if (itemPrice > priceLimitRouble)
@ -1100,7 +1100,7 @@ export class FenceService
const priceLimitRouble = this.traderConfig.fence.itemCategoryRoublePriceLimit[rootItemDb._parent];
const itemPrice
= this.handbookHelper.getTemplatePriceForItems(presetWithChildrenClone)
* this.itemHelper.getItemQualityModifierForOfferItems(presetWithChildrenClone);
* this.itemHelper.getItemQualityModifierForItems(presetWithChildrenClone);
if (priceLimitRouble)
{
if (itemPrice > priceLimitRouble)