From 91c154daa81bb0fa5077304239b1d00327d4feb4 Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Sat, 17 Feb 2024 10:48:22 +0000 Subject: [PATCH] Fix some armor not showing up on the flea when Operational filter is enabled (!228) Some plate carriers have no required plates, and thus were failing the functional check. I've changed it to check for an item count greater than the required plate count (Since `items` also contains the carrier itself). Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/228 Co-authored-by: DrakiaXYZ Co-committed-by: DrakiaXYZ --- project/src/helpers/RagfairOfferHelper.ts | 32 ++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/project/src/helpers/RagfairOfferHelper.ts b/project/src/helpers/RagfairOfferHelper.ts index 48ed067b..0dbe9d30 100644 --- a/project/src/helpers/RagfairOfferHelper.ts +++ b/project/src/helpers/RagfairOfferHelper.ts @@ -606,7 +606,7 @@ export class RagfairOfferHelper return false; } - if (searchRequest.onlyFunctional && this.presetHelper.hasPreset(offerRootItem._tpl) && offer.items.length === 1) + if (searchRequest.onlyFunctional && !this.isItemFunctional(offerRootItem, offer)) { // don't include non-functional items return false; @@ -664,6 +664,36 @@ export class RagfairOfferHelper return true; } + /** + * Check that the passed in offer item is functional + * @param offerRootItem The root item of the offer + * @param offer The flea offer + * @returns True if the given item is functional + */ + public isItemFunctional( + offerRootItem: Item, + offer: IRagfairOffer + ): boolean + { + // Non-presets are always functional + if (!this.presetHelper.hasPreset(offerRootItem._tpl)) + { + return true; + } + + // For armor items that can hold mods, make sure the item count is atleast the amount of required plates + if (this.itemHelper.armorItemCanHoldMods(offerRootItem._tpl)) + { + const offerRootTemplate = this.itemHelper.getItem(offerRootItem._tpl)[1]; + const requiredPlateCount = offerRootTemplate._props.Slots?.filter(item => item._required)?.length; + + return offer.items.length > requiredPlateCount; + } + + // For other presets, make sure the offer has more than 1 item + return offer.items.length > 1; + } + /** * Should a ragfair offer be visible to the player * @param searchRequest Search request