diff --git a/project/src/generators/RepeatableQuestGenerator.ts b/project/src/generators/RepeatableQuestGenerator.ts index 531792a1..9d3187af 100644 --- a/project/src/generators/RepeatableQuestGenerator.ts +++ b/project/src/generators/RepeatableQuestGenerator.ts @@ -995,7 +995,7 @@ export class RepeatableQuestGenerator ) { // Add a random default preset weapon as reward - const defaultPresets = Object.values(this.presetHelper.getDefaultPresets()); + const defaultPresets = Object.values(this.presetHelper.getDefaultWeaponPresets()); const defaultPresetClone = this.jsonUtil.clone(this.randomUtil.getArrayValue(defaultPresets)); // use _encyclopedia as its always the base items _tpl, items[0] isn't guaranteed to be base item diff --git a/project/src/helpers/PresetHelper.ts b/project/src/helpers/PresetHelper.ts index 5692ce8f..6a48d984 100644 --- a/project/src/helpers/PresetHelper.ts +++ b/project/src/helpers/PresetHelper.ts @@ -1,18 +1,22 @@ import { inject, injectable } from "tsyringe"; import { IPreset } from "@spt-aki/models/eft/common/IGlobals"; +import { BaseClasses } from "@spt-aki/models/enums/BaseClasses"; import { DatabaseServer } from "@spt-aki/servers/DatabaseServer"; import { JsonUtil } from "@spt-aki/utils/JsonUtil"; +import { ItemHelper } from "./ItemHelper"; @injectable() export class PresetHelper { protected lookup: Record = {}; - protected defaultPresets: Record; + protected defaultEquipmentPresets: Record; + protected defaultWeaponPresets: Record; constructor( @inject("JsonUtil") protected jsonUtil: JsonUtil, @inject("DatabaseServer") protected databaseServer: DatabaseServer, + @inject("ItemHelper") protected itemHelper: ItemHelper, ) {} @@ -21,12 +25,30 @@ export class PresetHelper this.lookup = input; } + /** + * Get default weapon and equipment presets + * @returns Dictionary + */ public getDefaultPresets(): Record { - if (!this.defaultPresets) + const weapons = this.getDefaultWeaponPresets(); + const equipment = this.getDefaultEquipmentPresets(); + + return Object.assign({}, weapons, equipment); + } + + /** + * Get default weapon presets + * @returns Dictionary + */ + public getDefaultWeaponPresets(): Record + { + if (!this.defaultWeaponPresets) { - this.defaultPresets = Object.values(this.databaseServer.getTables().globals.ItemPresets).filter((x) => - x._encyclopedia !== undefined + this.defaultWeaponPresets = Object.values(this.databaseServer.getTables().globals.ItemPresets).filter(( + preset, + ) => preset._encyclopedia !== undefined + && this.itemHelper.isOfBaseclass(preset._encyclopedia, BaseClasses.WEAPON) ).reduce((acc, cur) => { acc[cur._id] = cur; @@ -34,7 +56,28 @@ export class PresetHelper }, {}); } - return this.defaultPresets; + return this.defaultWeaponPresets; + } + + /** + * Get default equipment presets + * @returns Dictionary + */ + public getDefaultEquipmentPresets(): Record + { + if (!this.defaultEquipmentPresets) + { + this.defaultEquipmentPresets = Object.values(this.databaseServer.getTables().globals.ItemPresets).filter(( + preset, + ) => preset._encyclopedia !== undefined && this.itemHelper.armorItemCanHoldMods(preset._encyclopedia)) + .reduce((acc, cur) => + { + acc[cur._id] = cur; + return acc; + }, {}); + } + + return this.defaultEquipmentPresets; } public isPreset(id: string): boolean