From 285f65bb8d5994fd6db06d55b6ee86ba0ebb3145 Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 9 Aug 2023 19:20:41 +0100 Subject: [PATCH] Only remove item from fence assort if he has items to remove Add empty assort check to remove function too --- project/src/services/FenceService.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/project/src/services/FenceService.ts b/project/src/services/FenceService.ts index 0d0a1c2f..6aedb8f9 100644 --- a/project/src/services/FenceService.ts +++ b/project/src/services/FenceService.ts @@ -201,18 +201,25 @@ export class FenceService let itemCountToReplace = this.getCountOfItemsToReplace(this.traderConfig.fence.assortSize); const discountItemCountToReplace = this.getCountOfItemsToReplace(this.traderConfig.fence.discountOptions.assortSize); - // Iterate x times to remove items - for (let index = 0; index < itemCountToReplace; index++) + // Iterate x times to remove items (only remove if assort has items) + if (this.fenceAssort?.items?.length > 0) { - this.removeRandomItemFromAssorts(this.fenceAssort); + for (let index = 0; index < itemCountToReplace; index++) + { + this.removeRandomItemFromAssorts(this.fenceAssort); + } } - // Iterate x times to remove items - for (let index = 0; index < discountItemCountToReplace; index++) + // Iterate x times to remove items (only remove if assort has items) + if (this.fenceDiscountAssort?.items?.length > 0) { - this.removeRandomItemFromAssorts(this.fenceDiscountAssort); + for (let index = 0; index < discountItemCountToReplace; index++) + { + this.removeRandomItemFromAssorts(this.fenceDiscountAssort); + } } + itemCountToReplace = this.getCountOfItemsToGenerate(itemCountToReplace); const newItems = this.createBaseTraderAssortItem(); @@ -286,6 +293,14 @@ export class FenceService */ protected removeRandomItemFromAssorts(assort: ITraderAssort): void { + // Only remove if assort has items + if (!assort.items.some(x => x.slotId === "hideout")) + { + this.logger.warning("Unable to remove random assort from trader as they have no assorts with a slotid of `hideout`"); + + return; + } + let itemToRemove: Item; while (!itemToRemove || itemToRemove.slotId !== "hideout") { @@ -296,6 +311,7 @@ export class FenceService assort.items.splice(indexOfItemToRemove, 1); // Clean up any mods if item removed was a weapon + // TODO: also check for mods attached down the item chain assort.items = assort.items.filter(x => x.parentId !== itemToRemove._id); delete assort.barter_scheme[itemToRemove._id];