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
This commit is contained in:
Dev 2024-02-06 15:52:22 +00:00
parent fcf7ff5c3d
commit b40e41bd3d
3 changed files with 43 additions and 2 deletions

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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