From 8ee176b9d84d55ea39269aa8be7c8914590a12ac Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 4 Nov 2023 20:11:09 +0000 Subject: [PATCH] Handle when `fillCamora()` cannot find camora slots in weapons modPool --- .../assets/database/locales/server/en.json | 2 +- .../generators/BotEquipmentModGenerator.ts | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/project/assets/database/locales/server/en.json b/project/assets/database/locales/server/en.json index 7b19373e..17c5068c 100644 --- a/project/assets/database/locales/server/en.json +++ b/project/assets/database/locales/server/en.json @@ -46,7 +46,7 @@ "bot-weapon_missing_mod_slot": "Slot: {{modSlot}}' does not exist for weapon: {{weaponId}} {{weaponName}} on {{botRole}}", "bot-weapons_required_slot_missing_item": "Required slot '{{modSlot}}' on {{modName}} {{slotId}} was empty on {{botRole}}", "bot-item_missing_props_property": "Item {{itemTpl}} {{name}} is missing a _props property", - "bot-unable_to_fill_camora_slot_mod_pool_empty": "Unable to fill weapon camora slot for {{weaponId}} {{weaponName}} mod pool for item was empty", + "bot-unable_to_fill_camora_slot_mod_pool_empty": "Unable to fill weapon camora slots for {{weaponId}} - {{weaponName}}. Mod pool for was empty, attempting to generate dynamically", "bot-unable_to_edit_limits_of_unknown_map": "Unable to edit bot limits of map: %s as it cannot be found", "bot-unable_to_find_loot_n_value_for_bot": "Unable to find loot N value for bot: %s, using scav n value instead", "bot-unable_to_find_bot_in_cache": "Unable to find bot in cache with name: %s", diff --git a/project/src/generators/BotEquipmentModGenerator.ts b/project/src/generators/BotEquipmentModGenerator.ts index 4de2393b..eaffe1e6 100644 --- a/project/src/generators/BotEquipmentModGenerator.ts +++ b/project/src/generators/BotEquipmentModGenerator.ts @@ -787,17 +787,25 @@ export class BotEquipmentModGenerator * Ammo is not put into the magazine directly but assigned to the magazine's slots: The "camora_xxx" slots. * This function is a helper called by generateModsForItem for mods with parent type "CylinderMagazine" * @param items The items where the CylinderMagazine's camora are appended to - * @param modPool modPool which should include available cartrigdes + * @param modPool modPool which should include available cartridges * @param parentId The CylinderMagazine's UID * @param parentTemplate The CylinderMagazine's template */ protected fillCamora(items: Item[], modPool: Mods, parentId: string, parentTemplate: ITemplateItem): void { - const itemModPool = modPool[parentTemplate._id]; - + let itemModPool = modPool[parentTemplate._id]; if (!itemModPool) { - this.logger.error(this.localisationService.getText("bot-unable_to_fill_camora_slot_mod_pool_empty", {weaponId: parentTemplate._id, weaponName: parentTemplate._name})); + this.logger.warning(this.localisationService.getText("bot-unable_to_fill_camora_slot_mod_pool_empty", {weaponId: parentTemplate._id, weaponName: parentTemplate._name})); + const camoraSlots = parentTemplate._props.Slots.filter(x => x._name.startsWith("camora")); + + // Attempt to generate camora slots for item + modPool[parentTemplate._id] = {}; + for (const camora of camoraSlots) + { + modPool[parentTemplate._id][camora._name] = camora._props.filters[0].Filter; + } + itemModPool = modPool[parentTemplate._id]; } let exhaustableModPool = null; @@ -843,10 +851,10 @@ export class BotEquipmentModGenerator const modSlotId = slot._name; const modId = this.hashUtil.generate(); items.push({ - "_id": modId, - "_tpl": modTpl, - "parentId": parentId, - "slotId": modSlotId + _id: modId, + _tpl: modTpl, + parentId: parentId, + slotId: modSlotId }); } }