Updated createSingleOffer(), createMultiOffer(), createPackOffer() to make use of same code to figure out average offer price as client

This commit is contained in:
Dev 2024-10-15 14:52:07 +01:00
parent b70572017d
commit c7ae2823cd

View File

@ -304,10 +304,14 @@ export class RagfairController {
/**
* Called when creating an offer on flea, fills values in top right corner
* @param getPriceRequest
* @param getPriceRequest Client request object
* @param ignoreTraderOffers Should trader offers be ignored in the calcualtion
* @returns min/avg/max values for an item based on flea offers available
*/
public getItemMinAvgMaxFleaPriceValues(getPriceRequest: IGetMarketPriceRequestData): IGetItemPriceResult {
public getItemMinAvgMaxFleaPriceValues(
getPriceRequest: IGetMarketPriceRequestData,
ignoreTraderOffers = false,
): IGetItemPriceResult {
// Get all items of tpl
const offers = this.ragfairOfferService.getOffersOfType(getPriceRequest.templateId);
@ -326,6 +330,10 @@ export class RagfairController {
return sum;
}
if (ignoreTraderOffers && offer.user.memberType === MemberCategory.TRADER) {
return sum;
}
// Figure out how many items the requirementsCost is applying to, and what the per-item price is
const offerItemCount = Math.max(
offer.sellInOnePiece ? offer.items[0].upd?.StackObjectsCount ?? 1 : 1,
@ -438,7 +446,8 @@ export class RagfairController {
const qualityMultiplier = this.itemHelper.getItemQualityModifierForItems(offer.items, true);
// Average offer price for single item (or whole weapon)
let averageOfferPriceSingleItem = this.ragfairPriceService.getFleaPriceForOfferItems(offer.items);
const averages = this.getItemMinAvgMaxFleaPriceValues({ templateId: offer.items[0]._tpl });
let averageOfferPriceSingleItem = averages.avg;
// Check for and apply item price modifer if it exists in config
const itemPriceModifer = this.ragfairConfig.dynamic.itemPriceMultiplier[rootItem._tpl];
@ -535,7 +544,8 @@ export class RagfairController {
const newRootOfferItem = offer.items[0];
// Average offer price for single item (or whole weapon)
let averageOfferPrice = this.ragfairPriceService.getFleaPriceForOfferItems(offer.items);
const averages = this.getItemMinAvgMaxFleaPriceValues({ templateId: offer.items[0]._tpl });
let averageOfferPrice = averages.avg;
// Check for and apply item price modifer if it exists in config
const itemPriceModifer = this.ragfairConfig.dynamic.itemPriceMultiplier[newRootOfferItem._tpl];
@ -640,7 +650,8 @@ export class RagfairController {
const newRootOfferItem = offer.items[0];
// Single price for an item
let singleItemPrice = this.ragfairPriceService.getFleaPriceForItem(firstListingAndChidren[0]._tpl);
const averages = this.getItemMinAvgMaxFleaPriceValues({ templateId: firstListingAndChidren[0]._tpl });
let singleItemPrice = averages.avg;
// Check for and apply item price modifer if it exists in config
const itemPriceModifer = this.ragfairConfig.dynamic.itemPriceMultiplier[newRootOfferItem._tpl];