From 4582bb6fe2b9919134dae694e91ea7625e987648 Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 12 Aug 2024 17:43:42 +0100 Subject: [PATCH] Improved handling of bot stock generation. Moved code into own function Expanded force stock check to look for any child items instead of ones for slot `mod_stock` Expanded check to include additional slot names --- .../generators/BotEquipmentModGenerator.ts | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/project/src/generators/BotEquipmentModGenerator.ts b/project/src/generators/BotEquipmentModGenerator.ts index b9a6aa66..36e0d038 100644 --- a/project/src/generators/BotEquipmentModGenerator.ts +++ b/project/src/generators/BotEquipmentModGenerator.ts @@ -455,16 +455,11 @@ export class BotEquipmentModGenerator { } // If stock mod can take a sub stock mod, force spawn chance to be 100% to ensure sub-stock gets added - // Or if mod_stock is configured to be forced on - if ( - modSlot === "mod_stock" && - modToAddTemplate._props.Slots.some( - (slot) => slot._name.includes("mod_stock") || botEquipConfig.forceStock, - ) - ) { + // Or if bot has stock force enabled + if (this.shouldForceSubStockSlots(modSlot, botEquipConfig, modToAddTemplate)) { // Stock mod can take additional stocks, could be a locking device, force 100% chance - const stockSlots = ["mod_stock", "mod_stock_000", "mod_stock_akms"]; - this.adjustSlotSpawnChances(request.modSpawnChances, stockSlots, 100); + const subStockSlots = ["mod_stock", "mod_stock_000", "mod_stock_001", "mod_stock_akms"]; + this.adjustSlotSpawnChances(request.modSpawnChances, subStockSlots, 100); } // Gather stats on mods being added to weapon @@ -538,6 +533,27 @@ export class BotEquipmentModGenerator { return request.weapon; } + /** + * Should the provided bot have its stock chance values altered to 100% + * @param modSlot Slot to check + * @param botEquipConfig Bots equipment config/chance values + * @param modToAddTemplate Mod being added to bots weapon + * @returns True if it should + */ + protected shouldForceSubStockSlots( + modSlot: string, + botEquipConfig: EquipmentFilters, + modToAddTemplate: ITemplateItem, + ): boolean { + // Slots a weapon can store its stock in + const stockSlots = ["mod_stock", "mod_stock_000", "mod_stock_001", "mod_stock_akms"]; + + // Can the stock hold child items + const hasSubSlots = modToAddTemplate._props.Slots?.length > 0; + + return (stockSlots.includes(modSlot) && hasSubSlots) || botEquipConfig.forceStock; + } + /** * Is this modslot a front or rear sight * @param modSlot Slot to check