0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-12 15:50:42 -05:00

Added filtering of offers that have exceeded the buy limit threshold from possible offers to display 0 - Fixed a limit-reached trader offers always showing over a PMC offer

Various improvements to `getOffersForBuild`:
Renamed offers to offersToReturn
Removed one layer of indentation by using early return
Replaced use of `ragfairOfferService.getOffers` with `ragfairOfferService.getOffersOfType` to improve performance by using a more appropriately indexed dictionary of offers
Run `getOffersInsideBuyRestrictionLimits` as part of offer filtering process
removed redundant reassignment of availableOffers/possibleOffers
This commit is contained in:
Chomp 2024-12-22 19:49:57 +00:00
parent 35ba24b639
commit 140a1e8c00

View File

@ -208,12 +208,14 @@ export class RagfairOfferHelper {
pmcData: IPmcData,
): IRagfairOffer[] {
const offersMap = new Map<string, IRagfairOffer[]>();
const offers: IRagfairOffer[] = [];
const offersToReturn: IRagfairOffer[] = [];
const playerIsFleaBanned = this.profileHelper.playerIsFleaBanned(pmcData);
const tieredFlea = this.ragfairConfig.tieredFlea;
const tieredFleaLimitTypes = Object.keys(tieredFlea.unlocksType);
for (const offer of this.ragfairOfferService.getOffers()) {
for (const desiredItemTpl of Object.keys(searchRequest.buildItems)) {
const matchingOffers = this.ragfairOfferService.getOffersOfType(desiredItemTpl);
for (const offer of matchingOffers) {
// Dont show pack offers
if (offer.sellInOnePiece) {
continue;
@ -223,7 +225,19 @@ export class RagfairOfferHelper {
continue;
}
if (this.isDisplayableOffer(searchRequest, itemsToAdd, traderAssorts, offer, pmcData, playerIsFleaBanned)) {
if (
!this.isDisplayableOffer(
searchRequest,
itemsToAdd,
traderAssorts,
offer,
pmcData,
playerIsFleaBanned,
)
) {
continue;
}
const isTraderOffer = offer.user.memberType === MemberCategory.TRADER;
if (isTraderOffer) {
if (this.traderBuyRestrictionReached(offer)) {
@ -271,17 +285,41 @@ export class RagfairOfferHelper {
const lockedOffers = this.getLoyaltyLockedOffers(possibleOffers, pmcData);
// Exclude locked offers + above loyalty locked offers if at least 1 was found
const availableOffers = possibleOffers.filter((x) => !(x.locked || lockedOffers.includes(x._id)));
if (availableOffers.length > 0) {
possibleOffers = availableOffers;
}
possibleOffers = possibleOffers.filter((offer) => !(offer.locked || lockedOffers.includes(offer._id)));
// Exclude trader offers over their buy restriction limit
possibleOffers = this.getOffersInsideBuyRestrictionLimits(possibleOffers);
}
// Sort offers by price and pick the best
const offer = this.ragfairSortHelper.sortOffers(possibleOffers, RagfairSort.PRICE, 0)[0];
offers.push(offer);
offersToReturn.push(offer);
}
return offers;
return offersToReturn;
}
/**
* Get offers that have not exceeded buy limits
* @param possibleOffers offers to process
* @returns Offers
*/
protected getOffersInsideBuyRestrictionLimits(possibleOffers: IRagfairOffer[]) {
// Check offer has buy limit + is from trader + current buy count is at or over max
return possibleOffers.filter((offer) => {
if (
typeof offer.buyRestrictionMax !== "undefined" &&
this.offerIsFromTrader(offer) &&
offer.buyRestrictionCurrent >= offer.buyRestrictionMax
) {
if (offer.buyRestrictionCurrent >= offer.buyRestrictionMax) {
return false;
}
}
// Doesnt have buy limits, retrun offer
return true;
});
}
/**
@ -622,7 +660,7 @@ export class RagfairOfferHelper {
searchRequest.oneHourExpiration &&
offer.endTime - this.timeUtil.getTimestamp() > TimeUtil.ONE_HOUR_AS_SECONDS
) {
// offer doesnt expire within an hour
// offer expires within an hour
return false;
}
@ -690,7 +728,7 @@ export class RagfairOfferHelper {
* @returns True if the given item is functional
*/
public isItemFunctional(offerRootItem: IItem, offer: IRagfairOffer): boolean {
// Non-presets are always functional
// Non-preset weapons/armor are always functional
if (!this.presetHelper.hasPreset(offerRootItem._tpl)) {
return true;
}
@ -837,4 +875,13 @@ export class RagfairOfferHelper {
return true;
}
/**
* Does this offer come from a trader
* @param offer Offer to check
* @returns True = from trader
*/
public offerIsFromTrader(offer: IRagfairOffer) {
return offer.user.memberType === MemberCategory.TRADER;
}
}