Fix flea avg and fee calculations (!265)

Properly calculate the flea average, excluding barter offers for a more live-like result
Prioritize handbook price for the /client/items/prices route to match live

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/265
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-03-17 08:54:34 +00:00 committed by chomp
parent 95f5a49c5c
commit e497ecc125
2 changed files with 19 additions and 4 deletions

View File

@ -352,7 +352,21 @@ export class RagfairController
const min = offers[0].requirementsCost; // Get first item from array as its pre-sorted
const max = offers.at(-1).requirementsCost; // Get last item from array as its pre-sorted
return { avg: (min + max) / 2, min: min, max: max };
// Get the average offer price, excluding barter offers
let avgOfferCount = 0;
const avg = offers.reduce((sum, offer) =>
{
// Exclude barter items
if (offer.requirements.some((req) => !this.paymentHelper.isMoneyTpl(req._tpl)))
{
return sum;
}
avgOfferCount++;
return sum + offer.requirementsCost;
}, 0) / Math.max(avgOfferCount, 1);
return { avg: avg, min: min, max: max };
}
// No offers listed, get price from live ragfair price list prices.json

View File

@ -171,13 +171,14 @@ export class RagfairPriceService implements OnLoad
}
/**
* Get prices for all items on flea, priorities dynamic prices from prices.json, use handbook prices if missing
* Get prices for all items on flea, prioritize handbook prices first, use prices from prices.json if missing
* @returns Dictionary of item tpls and rouble cost
*/
public getAllFleaPrices(): Record<string, number>
{
// assign static values first, then overwrite them with dynamic, any values not stored in dynamic data will be covered by static data
return { ...this.prices.static, ...this.prices.dynamic };
// assign dynamic (prices.json) values first, then overwrite them with static (handbook.json)
// any values not stored in static data will be covered by dynamic data
return { ...this.prices.dynamic, ...this.prices.static };
}
public getAllStaticPrices(): Record<string, number>