Small optimisations applied to reateRandomLoot()

This commit is contained in:
Dev 2024-01-20 18:08:09 +00:00
parent 80fdaf65e6
commit 13ce200f80

View File

@ -106,11 +106,14 @@ export class LootGenerator
}
const globalDefaultPresets = Object.values(this.presetHelper.getDefaultPresets());
const itemBlacklistArray = Array.from(itemBlacklist);
// Filter default presets to just weapons
const weaponDefaultPresets = globalDefaultPresets.filter(preset => this.itemHelper.isOfBaseclass(preset._encyclopedia, BaseClasses.WEAPON));
const randomisedWeaponPresetCount = this.randomUtil.getInt(options.weaponPresetCount.min, options.weaponPresetCount.max);
const itemBlacklistArray = Array.from(itemBlacklist);
if (randomisedWeaponPresetCount > 0)
{
const weaponDefaultPresets = globalDefaultPresets.filter(preset => this.itemHelper.isOfBaseclass(preset._encyclopedia, BaseClasses.WEAPON));
for (let index = 0; index < randomisedWeaponPresetCount; index++)
{
if (!this.findAndAddRandomPresetToLoot(weaponDefaultPresets, itemTypeCounts, itemBlacklistArray, result))
@ -118,11 +121,15 @@ export class LootGenerator
index--;
}
}
}
// Filter default presets to just armors and then filter again by protection level
const randomisedArmorPresetCount = this.randomUtil.getInt(options.armorPresetCount.min, options.armorPresetCount.max);
if (randomisedArmorPresetCount > 0)
{
const armorDefaultPresets = globalDefaultPresets.filter(preset => this.itemHelper.armorItemCanHoldMods(preset._encyclopedia));
const levelFilteredArmorPresets = armorDefaultPresets.filter(armor => this.armorIsDesiredProtectionLevel(armor, options));
const randomisedArmorPresetCount = this.randomUtil.getInt(options.armorPresetCount.min, options.armorPresetCount.max);
for (let index = 0; index < randomisedArmorPresetCount; index++)
{
if (!this.findAndAddRandomPresetToLoot(levelFilteredArmorPresets, itemTypeCounts, itemBlacklistArray, result))
@ -130,6 +137,7 @@ export class LootGenerator
index--;
}
}
}
return result;
}