Add function to allow addition of custom weapons to PMCs
This commit is contained in:
parent
66f04f194a
commit
ea2257c2fb
@ -1,5 +1,6 @@
|
|||||||
import { inject, injectable } from "tsyringe";
|
import { inject, injectable } from "tsyringe";
|
||||||
|
|
||||||
|
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
||||||
import { ITemplateItem, Props } from "@spt-aki/models/eft/common/tables/ITemplateItem";
|
import { ITemplateItem, Props } from "@spt-aki/models/eft/common/tables/ITemplateItem";
|
||||||
import {
|
import {
|
||||||
CreateItemResult,
|
CreateItemResult,
|
||||||
@ -23,6 +24,7 @@ export class CustomItemService
|
|||||||
@inject("HashUtil") protected hashUtil: HashUtil,
|
@inject("HashUtil") protected hashUtil: HashUtil,
|
||||||
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
||||||
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
||||||
|
@inject("ItemHelper") protected itemHelper: ItemHelper,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.tables = this.databaseServer.getTables();
|
this.tables = this.databaseServer.getTables();
|
||||||
@ -197,4 +199,41 @@ export class CustomItemService
|
|||||||
{
|
{
|
||||||
this.tables.templates.prices[newItemId] = fleaPriceRoubles;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user