Fix issue with choosing a default mod for a weapon when the bot doesnt have the default mod in their mod pool already - would result in missing vital mods causing a fallback to a default weapon preset

This commit is contained in:
Dev 2024-01-30 21:14:15 +00:00
parent 2cd92c4e7e
commit a45cc3052e
2 changed files with 23 additions and 13 deletions

View File

@ -864,7 +864,7 @@ export class BotEquipmentModGenerator
if (chosenModResult.slotBlocked)
{
// Give max of 8 attempts of picking an item ifs blocked by another item
// Give max of x attempts of picking a mod if blocked by another
if (blockedAttemptCount > maxBlockedAttempts)
{
blockedAttemptCount = 0;
@ -920,14 +920,30 @@ export class BotEquipmentModGenerator
{
const defaultWeaponPreset = this.presetHelper.getDefaultPreset(weaponTemplate._id)
const matchingMod = defaultWeaponPreset._items.find(item => item?.slotId?.toLowerCase() === modSlot.toLowerCase());
// Only filter mods down to single default item if it already exists in existing itemModPool, OR the default item has no children
// Filtering mod pool to item that wasnt already there can have problems;
// You'd have a mod being picked without any sub-mods in its chain, possibly resulting in missing required mods not being added
if (matchingMod)
{
return [matchingMod._tpl];
// Mod isnt in existing mod pool
if (itemModPool[modSlot].includes(matchingMod._tpl))
{
// Found mod on preset + it already exists in mod pool
return [matchingMod._tpl];
}
// Mod isnt in existing pool, only add if its got no children
if (this.itemHelper.getItem(matchingMod._tpl)[1]._props.Slots.length === 0)
{
// Mod has no children
return [matchingMod._tpl];
}
}
this.logger.warning(`No default: ${modSlot} mod found on: ${weaponTemplate._name}`);
this.logger.debug(`No default: ${modSlot} mod found on template: ${weaponTemplate._id}`);
// Couuldnt find default in globals, use existing mod pool data
// Couldnt find default in globals, use existing mod pool data
return itemModPool[modSlot];
}

View File

@ -311,7 +311,7 @@ export class BotWeaponGenerator
{
// Invalid weapon generated, fallback to preset
this.logger.warning(
this.localisationService.getText("bot-weapon_generated_incorrect_using_default", weaponTpl),
this.localisationService.getText("bot-weapon_generated_incorrect_using_default", `${weaponTpl} ${itemTemplate._name}`),
);
const weaponMods = [];
@ -363,15 +363,9 @@ export class BotWeaponGenerator
continue;
}
// Iterate over slots in db item, if required, check tpl in that slot matches the filter list
for (const modSlotTemplate of modTemplate._props.Slots)
// Iterate over required slots in db item, check mod exists for that slot
for (const modSlotTemplate of modTemplate._props.Slots.filter(slot => slot._required))
{
// Ignore optional mods
if (!modSlotTemplate._required)
{
continue;
}
const slotName = modSlotTemplate._name;
const weaponSlotItem = weaponItemArray.find((weaponItem) => weaponItem.parentId === mod._id && weaponItem.slotId === slotName);
if (!weaponSlotItem)