FIxed infinite loop when only one item exists in pool and bot has maxed out number of that item already
This commit is contained in:
parent
fbfdeea9c1
commit
104fd03b39
@ -368,6 +368,12 @@ export class BotLootGenerator
|
|||||||
let fitItemIntoContainerAttempts = 0;
|
let fitItemIntoContainerAttempts = 0;
|
||||||
for (let i = 0; i < totalItemCount; i++)
|
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<string>(pool);
|
const weightedItemTpl = this.weightedRandomHelper.getWeightedValue<string>(pool);
|
||||||
const itemResult = this.itemHelper.getItem(weightedItemTpl);
|
const itemResult = this.itemHelper.getItem(weightedItemTpl);
|
||||||
const itemToAddTemplate = itemResult[1];
|
const itemToAddTemplate = itemResult[1];
|
||||||
@ -380,6 +386,18 @@ export class BotLootGenerator
|
|||||||
continue;
|
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 newRootItemId = this.hashUtil.generate();
|
||||||
const itemWithChildrenToAdd: Item[] = [{
|
const itemWithChildrenToAdd: Item[] = [{
|
||||||
_id: newRootItemId,
|
_id: newRootItemId,
|
||||||
@ -387,21 +405,6 @@ export class BotLootGenerator
|
|||||||
...this.botGeneratorHelper.generateExtraPropertiesForItem(itemToAddTemplate, botRole),
|
...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
|
// Is Simple-Wallet
|
||||||
if (weightedItemTpl === "5783c43d2459774bbe137486")
|
if (weightedItemTpl === "5783c43d2459774bbe137486")
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user