From dc1e172df00491175e7dd33c282a69c28aa1b9ad Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 10 Jan 2024 14:47:09 +0000 Subject: [PATCH] Handle generating a fence armor item and a default plate is not found Add extra plates to pool Centralise plate-related checks into itemhelper --- .../generators/BotEquipmentModGenerator.ts | 7 +------ project/src/helpers/ItemHelper.ts | 19 +++++++++++++++++++ project/src/services/FenceService.ts | 14 ++++++++++---- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/project/src/generators/BotEquipmentModGenerator.ts b/project/src/generators/BotEquipmentModGenerator.ts index 3a7d9438..7e285e24 100644 --- a/project/src/generators/BotEquipmentModGenerator.ts +++ b/project/src/generators/BotEquipmentModGenerator.ts @@ -180,7 +180,7 @@ export class BotEquipmentModGenerator protected filterPlateModsForSlotByLevel(settings: IGenerateEquipmentProperties, modSlot: string, modPool: string[], armorItem: ITemplateItem): string[] { // Not pmc or not a plate slot, return original mod pool array - if (!this.slotIsPlate(modSlot)) + if (!this.itemHelper.isRemovablePlateSlot(modSlot)) { return modPool; } @@ -225,11 +225,6 @@ export class BotEquipmentModGenerator } - protected slotIsPlate(modSlot: string): boolean - { - return ["front_plate", "back_plate", "side_plate"].includes(modSlot.toLowerCase()); - } - /** * Add mods to a weapon using the provided mod pool * @param sessionId session id diff --git a/project/src/helpers/ItemHelper.ts b/project/src/helpers/ItemHelper.ts index a78424cd..98ff427e 100644 --- a/project/src/helpers/ItemHelper.ts +++ b/project/src/helpers/ItemHelper.ts @@ -1276,6 +1276,25 @@ export class ItemHelper return chosenTpl; } + + /** + * Is the provided item._props.Slots._name property a plate slot + * @param slotName Name of slot (_name) of Items Slot array + * @returns True if its a slot that holds a removable palte + */ + public isRemovablePlateSlot(slotName: string): boolean + { + return this.getRevovablePlateSlotIds().includes(slotName.toLowerCase()); + } + + /** + * Get a list of slot names that hold removable plates + * @returns Array of slot ids (e.g. front_plate) + */ + public getRevovablePlateSlotIds(): string[] + { + return ["front_plate", "back_plate", "side_plate", "left_side_plate", "right_side_plate"]; + } } namespace ItemHelper diff --git a/project/src/services/FenceService.ts b/project/src/services/FenceService.ts index f39a63ac..aeb4c7d9 100644 --- a/project/src/services/FenceService.ts +++ b/project/src/services/FenceService.ts @@ -532,9 +532,8 @@ export class FenceService } // Check for and add plate items - const plateSlots = itemDbDetails._props.Slots.filter(slot => ["front_plate", "back_plate", "side_plate"].includes(slot._name.toLowerCase())); - const hasPlateSlots = plateSlots.length > 0; - if (hasPlateSlots) + const plateSlots = itemDbDetails._props.Slots.filter(slot => this.itemHelper.isRemovablePlateSlot(slot._name)); + if (plateSlots.length > 0) { for (const plateSlot of plateSlots) { @@ -544,7 +543,14 @@ export class FenceService continue; } - const modItemDbDetails = this.itemHelper.getItem(plateSlot._props.filters[0].Plate)[1]; + const plateTpl = plateSlot._props.filters[0].Plate + if (!plateTpl) + { + this.logger.warning(`Fence generation: item: ${itemDbDetails._id} ${itemDbDetails._name} lacks a default plate for slot: ${plateSlot._name}, skipping`); + + continue; + } + const modItemDbDetails = this.itemHelper.getItem(plateTpl)[1]; const durabilityValues = this.getRandomisedArmorDurabilityValues(modItemDbDetails, this.traderConfig.fence.armorMaxDurabilityPercentMinMax); armor.push({ _id: this.hashUtil.generate(),