From a45cc3052ef948d0fbeb2e7e9237aade64d30ce4 Mon Sep 17 00:00:00 2001 From: Dev Date: Tue, 30 Jan 2024 21:14:15 +0000 Subject: [PATCH] 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 --- .../generators/BotEquipmentModGenerator.ts | 24 +++++++++++++++---- project/src/generators/BotWeaponGenerator.ts | 12 +++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/project/src/generators/BotEquipmentModGenerator.ts b/project/src/generators/BotEquipmentModGenerator.ts index 6ada2180..be0478c5 100644 --- a/project/src/generators/BotEquipmentModGenerator.ts +++ b/project/src/generators/BotEquipmentModGenerator.ts @@ -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]; } diff --git a/project/src/generators/BotWeaponGenerator.ts b/project/src/generators/BotWeaponGenerator.ts index 398712de..6f021b76 100644 --- a/project/src/generators/BotWeaponGenerator.ts +++ b/project/src/generators/BotWeaponGenerator.ts @@ -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)