Add short circuit optimisation to isItemIncompatibleWithCurrentItems()
This commit is contained in:
parent
f3f008e0ec
commit
63ca393372
@ -287,19 +287,25 @@ export class BotInventoryGenerator
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
this.botGeneratorHelper.isItemIncompatibleWithCurrentItems(
|
||||
settings.inventory.items,
|
||||
chosenItemTpl,
|
||||
settings.rootEquipmentSlot,
|
||||
).incompatible)
|
||||
const compatabilityResult = this.botGeneratorHelper.isItemIncompatibleWithCurrentItems(
|
||||
settings.inventory.items,
|
||||
chosenItemTpl,
|
||||
settings.rootEquipmentSlot);
|
||||
if (compatabilityResult.incompatible)
|
||||
{
|
||||
// Entire slot is blocked by another item, no point in checking other items
|
||||
if (compatabilityResult.slotBlocked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Tried 8 different items that failed, stop
|
||||
if (attempts >= 8)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// remove picked item
|
||||
// Remove picked item
|
||||
delete settings.rootEquipmentPool[chosenItemTpl];
|
||||
|
||||
attempts++;
|
||||
@ -335,7 +341,7 @@ export class BotInventoryGenerator
|
||||
);
|
||||
}
|
||||
|
||||
// Item has slots
|
||||
// Item has slots, fill them
|
||||
if ( pickedItemDb._props.Slots?.length > 0 )
|
||||
{
|
||||
const items = this.botEquipmentModGenerator.generateModsForEquipment(
|
||||
|
@ -286,7 +286,7 @@ export class BotGeneratorHelper
|
||||
itemsEquipped: Item[],
|
||||
tplToCheck: string,
|
||||
equipmentSlot: string,
|
||||
): { incompatible: boolean; reason: string; }
|
||||
): { incompatible: boolean; reason: string; slotBlocked?: boolean; }
|
||||
{
|
||||
// Skip slots that have no incompatibilities
|
||||
if (["Scabbard", "Backpack", "SecureContainer", "Holster", "ArmBand"].includes(equipmentSlot))
|
||||
@ -333,6 +333,7 @@ export class BotGeneratorHelper
|
||||
incompatible: true,
|
||||
reason:
|
||||
`${tplToCheck} ${itemToEquip._name} in slot: ${equipmentSlot} blocked by: ${blockingItem._id} ${blockingItem._name}`,
|
||||
slotBlocked: true,
|
||||
};
|
||||
}
|
||||
|
||||
@ -345,6 +346,7 @@ export class BotGeneratorHelper
|
||||
incompatible: true,
|
||||
reason:
|
||||
`${tplToCheck} ${itemToEquip._name} in slot: ${equipmentSlot} blocked by: ${blockingItem._id} ${blockingItem._name}`,
|
||||
slotBlocked: true,
|
||||
};
|
||||
}
|
||||
|
||||
@ -358,6 +360,7 @@ export class BotGeneratorHelper
|
||||
incompatible: true,
|
||||
reason:
|
||||
`${tplToCheck} ${itemToEquip._name} is blocked by: ${existingHeadwear._tpl} in slot: ${existingHeadwear.slotId}`,
|
||||
slotBlocked: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -372,6 +375,7 @@ export class BotGeneratorHelper
|
||||
incompatible: true,
|
||||
reason:
|
||||
`${tplToCheck} ${itemToEquip._name} is blocked by: ${existingFaceCover._tpl} in slot: ${existingFaceCover.slotId}`,
|
||||
slotBlocked: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -386,6 +390,7 @@ export class BotGeneratorHelper
|
||||
incompatible: true,
|
||||
reason:
|
||||
`${tplToCheck} ${itemToEquip._name} is blocked by: ${existingEarpiece._tpl} in slot: ${existingEarpiece.slotId}`,
|
||||
slotBlocked: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -400,6 +405,7 @@ export class BotGeneratorHelper
|
||||
incompatible: true,
|
||||
reason:
|
||||
`${tplToCheck} ${itemToEquip._name} is blocked by: ${existingArmorVest._tpl} in slot: ${existingArmorVest.slotId}`,
|
||||
slotBlocked: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ export class BotWeaponGeneratorHelper
|
||||
for (const slot of equipmentSlots)
|
||||
{
|
||||
// Get container to put item into
|
||||
const container = inventory.items.find((i) => i.slotId === slot);
|
||||
const container = inventory.items.find((item) => item.slotId === slot);
|
||||
if (!container)
|
||||
{
|
||||
missingContainerCount++;
|
||||
@ -240,9 +240,9 @@ export class BotWeaponGeneratorHelper
|
||||
break;
|
||||
}
|
||||
|
||||
// Get all root items in backpack
|
||||
const existingContainerItems = inventory.items.filter((i) =>
|
||||
i.parentId === container._id && i.slotId === slotGrid._name
|
||||
// Get all root items in found container
|
||||
const existingContainerItems = inventory.items.filter((item) =>
|
||||
item.parentId === container._id && item.slotId === slotGrid._name
|
||||
);
|
||||
|
||||
// Get root items in container we can iterate over to find out what space is free
|
||||
|
Loading…
Reference in New Issue
Block a user