From 104fd03b394cbe9510124158df1da03b02fb03c9 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 22 Feb 2024 21:48:57 +0000 Subject: [PATCH] FIxed infinite loop when only one item exists in pool and bot has maxed out number of that item already --- project/src/generators/BotLootGenerator.ts | 33 ++++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/project/src/generators/BotLootGenerator.ts b/project/src/generators/BotLootGenerator.ts index 1c8e9911..1f01ad2a 100644 --- a/project/src/generators/BotLootGenerator.ts +++ b/project/src/generators/BotLootGenerator.ts @@ -368,6 +368,12 @@ export class BotLootGenerator let fitItemIntoContainerAttempts = 0; for (let i = 0; i < totalItemCount; i++) { + // Pool can become empty if item spawn limits keep removing items + if (Object.keys(pool).length === 0) + { + return; + } + const weightedItemTpl = this.weightedRandomHelper.getWeightedValue(pool); const itemResult = this.itemHelper.getItem(weightedItemTpl); const itemToAddTemplate = itemResult[1]; @@ -380,6 +386,18 @@ export class BotLootGenerator continue; } + if (itemSpawnLimits) + { + if (this.itemHasReachedSpawnLimit(itemToAddTemplate, botRole, itemSpawnLimits)) + { + // Only remove if pool has some other items to pick + delete pool[weightedItemTpl]; + + i--; + continue; + } + } + const newRootItemId = this.hashUtil.generate(); const itemWithChildrenToAdd: Item[] = [{ _id: newRootItemId, @@ -387,21 +405,6 @@ export class BotLootGenerator ...this.botGeneratorHelper.generateExtraPropertiesForItem(itemToAddTemplate, botRole), }]; - if (itemSpawnLimits) - { - if (this.itemHasReachedSpawnLimit(itemToAddTemplate, botRole, itemSpawnLimits)) - { - // Delete item from pool so it cant be picked again - if (poolSize > 5) - { // Only remove if pool has some other items to pick - delete pool[weightedItemTpl]; - } - - i--; - continue; - } - } - // Is Simple-Wallet if (weightedItemTpl === "5783c43d2459774bbe137486") {