From a53eea239c0eff309c43455acfd2bc2d37e86107 Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 10 Jul 2024 13:46:09 +0100 Subject: [PATCH] FIx Fixed `openRandomLootContainer()` failing when no config values are found for desired random container --- .../src/controllers/InventoryController.ts | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/project/src/controllers/InventoryController.ts b/project/src/controllers/InventoryController.ts index c2bfb45e..6767e240 100644 --- a/project/src/controllers/InventoryController.ts +++ b/project/src/controllers/InventoryController.ts @@ -891,24 +891,34 @@ export class InventoryController else { const rewardContainerDetails = this.inventoryHelper.getRandomLootContainerRewardDetails(openedItem._tpl); - rewards.push(...this.lootGenerator.getRandomLootContainerLoot(rewardContainerDetails)); - - if (rewardContainerDetails.foundInRaid) + if (!rewardContainerDetails || !rewardContainerDetails.rewardCount) { - foundInRaid = rewardContainerDetails.foundInRaid; + this.logger.error(`Unable to add loot to container: ${openedItem._tpl}, no rewards found`); + } + else + { + rewards.push(...this.lootGenerator.getRandomLootContainerLoot(rewardContainerDetails)); + + if (rewardContainerDetails.foundInRaid) + { + foundInRaid = rewardContainerDetails.foundInRaid; + } } } - const addItemsRequest: IAddItemsDirectRequest = { - itemsWithModsToAdd: rewards, - foundInRaid: foundInRaid, - callback: undefined, - useSortingTable: true, - }; - this.inventoryHelper.addItemsToStash(sessionID, addItemsRequest, pmcData, output); - if (output.warnings.length > 0) + if (rewards.length > 0) { - return; + const addItemsRequest: IAddItemsDirectRequest = { + itemsWithModsToAdd: rewards, + foundInRaid: foundInRaid, + callback: undefined, + useSortingTable: true, + }; + this.inventoryHelper.addItemsToStash(sessionID, addItemsRequest, pmcData, output); + if (output.warnings.length > 0) + { + return; + } } // Find and delete opened container item from player inventory