From ea2257c2fb28c58e3ba3f338a23ad78ba9b97fca Mon Sep 17 00:00:00 2001 From: Dev Date: Sun, 24 Dec 2023 16:06:18 +0000 Subject: [PATCH] Add function to allow addition of custom weapons to PMCs --- project/src/services/mod/CustomItemService.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/project/src/services/mod/CustomItemService.ts b/project/src/services/mod/CustomItemService.ts index 507fb962..2e73f7bb 100644 --- a/project/src/services/mod/CustomItemService.ts +++ b/project/src/services/mod/CustomItemService.ts @@ -1,5 +1,6 @@ import { inject, injectable } from "tsyringe"; +import { ItemHelper } from "@spt-aki/helpers/ItemHelper"; import { ITemplateItem, Props } from "@spt-aki/models/eft/common/tables/ITemplateItem"; import { CreateItemResult, @@ -23,6 +24,7 @@ export class CustomItemService @inject("HashUtil") protected hashUtil: HashUtil, @inject("JsonUtil") protected jsonUtil: JsonUtil, @inject("DatabaseServer") protected databaseServer: DatabaseServer, + @inject("ItemHelper") protected itemHelper: ItemHelper, ) { this.tables = this.databaseServer.getTables(); @@ -197,4 +199,41 @@ export class CustomItemService { this.tables.templates.prices[newItemId] = fleaPriceRoubles; } + + /** + * Add a custom weapon to PMCs loadout + * @param weaponTpl Custom weapon tpl to add to PMCs + * @param weaponWeight The weighting for the weapon to be picked vs other weapons + * @param weaponSlot The slot the weapon should be added to (e.g. FirstPrimaryWeapon/SecondPrimaryWeapon/Holster) + */ + public addCustomWeaponToPMCs(weaponTpl: string, weaponWeight: number, weaponSlot: string): void + { + const weapon = this.itemHelper.getItem(weaponTpl); + if (!weapon[0]) + { + this.logger.warning(`Unable to add custom weapon ${weaponTpl} to PMCs as it cannot be found in the Item db`); + + return; + } + const baseWeaponModObject = {}; + + // Get all slots weapon has and create a dictionary of them with possible mods that slot into each + const weaponSltos = weapon[1]._props.Slots; + for (const slot of weaponSltos) + { + baseWeaponModObject[slot._name] = slot._props.filters[0].Filter; + } + + // Get PMCs + const usec = this.databaseServer.getTables().bots.types.usec; + const bear = this.databaseServer.getTables().bots.types.bear; + + // Add weapon base+mods into bear/usec data + usec.inventory.mods[weaponTpl] = baseWeaponModObject; + bear.inventory.mods[weaponTpl] = baseWeaponModObject; + + // Add weapon to array of allowed weapons + weighting to be picked + usec.inventory.equipment[weaponSlot][weaponTpl] = weaponWeight; + bear.inventory.equipment[weaponSlot][weaponTpl] = weaponWeight; + } }