From 463e33d1b763f8f7adb6bd687c0f8fce8ddfb118 Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 24 Apr 2023 13:34:40 +0100 Subject: [PATCH] Refactor getNumberOfItemsNeededToFillGap --- project/src/services/FenceService.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/project/src/services/FenceService.ts b/project/src/services/FenceService.ts index 6ad7b5c5..f8924a1a 100644 --- a/project/src/services/FenceService.ts +++ b/project/src/services/FenceService.ts @@ -268,17 +268,21 @@ export class FenceService protected getCountOfItemsToGenerate(existingItemCountToReplace: number): number { const desiredTotalCount = this.traderConfig.fence.assortSize; - const actualTotalCount = this.fenceAssort.items.filter(x => x.slotId === "hideout").length; - if (actualTotalCount < desiredTotalCount) + const actualTotalCount = this.fenceAssort.items.reduce((count, item) => { - return (desiredTotalCount - actualTotalCount) + existingItemCountToReplace; - } + return item.slotId === "hideout" + ? count + 1 + : count; + }, 0); - return existingItemCountToReplace; + return actualTotalCount < desiredTotalCount + ? (desiredTotalCount - actualTotalCount) + existingItemCountToReplace + : existingItemCountToReplace; } /** * Choose an item (not mod) at random and remove from assorts + * @param assort Items to remove from */ protected removeRandomItemFromAssorts(assort: ITraderAssort): void {