mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 09:50:43 -05:00
Add search criteria filtering to required search
Pull out`isDisplayableOffer` from`passesSearchFilterCriteria`
This commit is contained in:
parent
36d6e56d89
commit
3c371a6c16
@ -74,19 +74,25 @@ export class RagfairOfferHelper
|
|||||||
* @param searchRequest Data from client
|
* @param searchRequest Data from client
|
||||||
* @param itemsToAdd ragfairHelper.filterCategories()
|
* @param itemsToAdd ragfairHelper.filterCategories()
|
||||||
* @param traderAssorts Trader assorts
|
* @param traderAssorts Trader assorts
|
||||||
* @param pmcProfile Player profile
|
* @param pmcData Player profile
|
||||||
* @returns Offers the player should see
|
* @returns Offers the player should see
|
||||||
*/
|
*/
|
||||||
public getValidOffers(
|
public getValidOffers(
|
||||||
searchRequest: ISearchRequestData,
|
searchRequest: ISearchRequestData,
|
||||||
itemsToAdd: string[],
|
itemsToAdd: string[],
|
||||||
traderAssorts: Record<string, ITraderAssort>,
|
traderAssorts: Record<string, ITraderAssort>,
|
||||||
pmcProfile: IPmcData,
|
pmcData: IPmcData,
|
||||||
): IRagfairOffer[]
|
): IRagfairOffer[]
|
||||||
{
|
{
|
||||||
return this.ragfairOfferService.getOffers().filter((offer) =>
|
return this.ragfairOfferService.getOffers().filter((offer) =>
|
||||||
this.isDisplayableOffer(searchRequest, itemsToAdd, traderAssorts, offer, pmcProfile)
|
{
|
||||||
);
|
if (!this.passesSearchFilterCriteria(searchRequest, offer, pmcData))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.isDisplayableOffer(searchRequest, itemsToAdd, traderAssorts, offer, pmcData);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,12 +107,8 @@ export class RagfairOfferHelper
|
|||||||
const requiredOffers = this.ragfairRequiredItemsService.getRequiredItemsById(searchRequest.neededSearchId);
|
const requiredOffers = this.ragfairRequiredItemsService.getRequiredItemsById(searchRequest.neededSearchId);
|
||||||
return requiredOffers.filter((offer: IRagfairOffer) =>
|
return requiredOffers.filter((offer: IRagfairOffer) =>
|
||||||
{
|
{
|
||||||
if (
|
if (!this.passesSearchFilterCriteria(searchRequest, offer, pmcData))
|
||||||
pmcData.Info.Level < this.databaseServer.getTables().globals.config.RagFair.minUserLevel
|
|
||||||
&& offer.user.memberType === MemberCategory.DEFAULT
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
// Skip item if player is < global unlock level (default is 15) and item is from a dynamically generated source (non-trader)
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -539,30 +541,25 @@ export class RagfairOfferHelper
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Should a ragfair offer be visible to the player
|
* Check an offer passes the various search criteria the player requested
|
||||||
* @param searchRequest Search request
|
* @param searchRequest
|
||||||
* @param itemsToAdd ?
|
* @param offer
|
||||||
* @param traderAssorts Trader assort items
|
* @param pmcData
|
||||||
* @param offer The flea offer
|
* @returns True
|
||||||
* @param pmcProfile Player profile
|
|
||||||
* @returns True = should be shown to player
|
|
||||||
*/
|
*/
|
||||||
public isDisplayableOffer(
|
protected passesSearchFilterCriteria(
|
||||||
searchRequest: ISearchRequestData,
|
searchRequest: ISearchRequestData,
|
||||||
itemsToAdd: string[],
|
|
||||||
traderAssorts: Record<string, ITraderAssort>,
|
|
||||||
offer: IRagfairOffer,
|
offer: IRagfairOffer,
|
||||||
pmcProfile: IPmcData,
|
pmcData: IPmcData,
|
||||||
): boolean
|
): boolean
|
||||||
{
|
{
|
||||||
|
const isDefaultUserOffer = offer.user.memberType === MemberCategory.DEFAULT;
|
||||||
const offerRootItem = offer.items[0];
|
const offerRootItem = offer.items[0];
|
||||||
/** Currency offer is sold for */
|
|
||||||
const moneyTypeTpl = offer.requirements[0]._tpl;
|
const moneyTypeTpl = offer.requirements[0]._tpl;
|
||||||
const isTraderOffer = offer.user.memberType === MemberCategory.TRADER;
|
const isTraderOffer = offer.user.memberType === MemberCategory.TRADER;
|
||||||
const isDefaultUserOffer = offer.user.memberType === MemberCategory.DEFAULT;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
pmcProfile.Info.Level < this.databaseServer.getTables().globals.config.RagFair.minUserLevel
|
pmcData.Info.Level < this.databaseServer.getTables().globals.config.RagFair.minUserLevel
|
||||||
&& isDefaultUserOffer
|
&& isDefaultUserOffer
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
@ -570,30 +567,6 @@ export class RagfairOfferHelper
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Offer root items tpl not in searched for array
|
|
||||||
if (!itemsToAdd?.includes(offerRootItem._tpl))
|
|
||||||
{
|
|
||||||
// skip items we shouldn't include
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Performing a required search and offer doesn't have requirement for item
|
|
||||||
if (searchRequest.neededSearchId && !offer.requirements.some((x) => x._tpl === searchRequest.neededSearchId))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter out presets when search request has multiple buildItems
|
|
||||||
// Assuming 1 build item = single item e.g. gun
|
|
||||||
if (
|
|
||||||
searchRequest.buildCount && this.presetHelper.hasPreset(offerRootItem._tpl)
|
|
||||||
&& Object.keys(searchRequest.buildItems).length > 1
|
|
||||||
)
|
|
||||||
{
|
|
||||||
// Don't include preset offer
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (searchRequest.offerOwnerType === OfferOwnerType.TRADEROWNERTYPE && !isTraderOffer)
|
if (searchRequest.offerOwnerType === OfferOwnerType.TRADEROWNERTYPE && !isTraderOffer)
|
||||||
{
|
{
|
||||||
// don't include player offers
|
// don't include player offers
|
||||||
@ -641,14 +614,6 @@ export class RagfairOfferHelper
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// commented out as required search "which is for checking offers that are barters"
|
|
||||||
// has info.removeBartering as true, this if statement removed barter items.
|
|
||||||
if (searchRequest.removeBartering && !this.paymentHelper.isMoneyTpl(moneyTypeTpl))
|
|
||||||
{
|
|
||||||
// don't include barter offers
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (searchRequest.currency > 0 && this.paymentHelper.isMoneyTpl(moneyTypeTpl))
|
if (searchRequest.currency > 0 && this.paymentHelper.isMoneyTpl(moneyTypeTpl))
|
||||||
{
|
{
|
||||||
const currencies = ["all", "RUB", "USD", "EUR"];
|
const currencies = ["all", "RUB", "USD", "EUR"];
|
||||||
@ -672,6 +637,63 @@ export class RagfairOfferHelper
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Passes above checks, search criteria filters have not filtered offer out
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should a ragfair offer be visible to the player
|
||||||
|
* @param searchRequest Search request
|
||||||
|
* @param itemsToAdd ?
|
||||||
|
* @param traderAssorts Trader assort items
|
||||||
|
* @param offer The flea offer
|
||||||
|
* @param pmcProfile Player profile
|
||||||
|
* @returns True = should be shown to player
|
||||||
|
*/
|
||||||
|
public isDisplayableOffer(
|
||||||
|
searchRequest: ISearchRequestData,
|
||||||
|
itemsToAdd: string[],
|
||||||
|
traderAssorts: Record<string, ITraderAssort>,
|
||||||
|
offer: IRagfairOffer,
|
||||||
|
pmcProfile: IPmcData,
|
||||||
|
): boolean
|
||||||
|
{
|
||||||
|
const offerRootItem = offer.items[0];
|
||||||
|
/** Currency offer is sold for */
|
||||||
|
const moneyTypeTpl = offer.requirements[0]._tpl;
|
||||||
|
|
||||||
|
// Offer root items tpl not in searched for array
|
||||||
|
if (!itemsToAdd?.includes(offerRootItem._tpl))
|
||||||
|
{
|
||||||
|
// skip items we shouldn't include
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Performing a required search and offer doesn't have requirement for item
|
||||||
|
if (searchRequest.neededSearchId && !offer.requirements.some((x) => x._tpl === searchRequest.neededSearchId))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter out presets when search request has multiple buildItems
|
||||||
|
// Assuming 1 build item = single item e.g. gun
|
||||||
|
if (
|
||||||
|
searchRequest.buildCount && this.presetHelper.hasPreset(offerRootItem._tpl)
|
||||||
|
&& Object.keys(searchRequest.buildItems).length > 1
|
||||||
|
)
|
||||||
|
{
|
||||||
|
// Don't include preset offer
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// commented out as required search "which is for checking offers that are barters"
|
||||||
|
// has info.removeBartering as true, this if statement removed barter items.
|
||||||
|
if (searchRequest.removeBartering && !this.paymentHelper.isMoneyTpl(moneyTypeTpl))
|
||||||
|
{
|
||||||
|
// don't include barter offers
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (Number.isNaN(offer.requirementsCost))
|
if (Number.isNaN(offer.requirementsCost))
|
||||||
{
|
{
|
||||||
// don't include offers with null or NaN in it
|
// don't include offers with null or NaN in it
|
||||||
|
Loading…
x
Reference in New Issue
Block a user