Make use of presetHelper instead of rolling own implementation

This commit is contained in:
Dev 2024-01-16 10:28:08 +00:00
parent e1a8f26507
commit 4d1066b51a
2 changed files with 14 additions and 26 deletions

View File

@ -1,6 +1,7 @@
import { inject, injectable } from "tsyringe";
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
import { PresetHelper } from "@spt-aki/helpers/PresetHelper";
import { IPreset } from "@spt-aki/models/eft/common/IGlobals";
import { Item } from "@spt-aki/models/eft/common/tables/IItem";
import { BaseClasses } from "@spt-aki/models/enums/BaseClasses";
@ -22,6 +23,7 @@ export class RagfairAssortGenerator
@inject("JsonUtil") protected jsonUtil: JsonUtil,
@inject("HashUtil") protected hashUtil: HashUtil,
@inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("PresetHelper") protected presetHelper: PresetHelper,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
@inject("SeasonalEventService") protected seasonalEventService: SeasonalEventService,
@inject("ConfigServer") protected configServer: ConfigServer,
@ -62,9 +64,9 @@ export class RagfairAssortGenerator
const results: Item[] = [];
const items = this.itemHelper.getItems().filter(item => item._type !== "Node");
const weaponPresets = (this.ragfairConfig.dynamic.showDefaultPresetsOnly)
? this.getDefaultPresets()
: this.getPresets();
const presets = (this.ragfairConfig.dynamic.showDefaultPresetsOnly)
? Object.values(this.presetHelper.getDefaultPresets())
: this.presetHelper.getAllPresets()
const ragfairItemInvalidBaseTypes: string[] = [
BaseClasses.LOOT_CONTAINER, // safe, barrel cache etc
@ -74,9 +76,9 @@ export class RagfairAssortGenerator
BaseClasses.STATIONARY_CONTAINER,
BaseClasses.POCKETS,
BaseClasses.BUILT_IN_INSERTS,
BaseClasses.ARMOR,
BaseClasses.VEST,
BaseClasses.HEADWEAR,
BaseClasses.ARMOR, // Handled by presets
BaseClasses.VEST, // Handled by presets
BaseClasses.HEADWEAR, // Handled by presets
];
const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled();
@ -99,7 +101,7 @@ export class RagfairAssortGenerator
results.push(this.createRagfairAssortItem(item._id, item._id)); // tplid and id must be the same so hideout recipe reworks work
}
for (const weapon of weaponPresets)
for (const weapon of presets)
{
results.push(this.createRagfairAssortItem(weapon._items[0]._tpl, weapon._id)); // Preset id must be passed through to ensure flea shows presets
}
@ -107,25 +109,6 @@ export class RagfairAssortGenerator
return results;
}
/**
* Get presets from globals.json
* @returns Preset object array
*/
protected getPresets(): IPreset[]
{
const presets = Object.values(this.databaseServer.getTables().globals.ItemPresets);
return presets;
}
/**
* Get default presets from globals.json
* @returns Preset object array
*/
protected getDefaultPresets(): IPreset[]
{
return this.getPresets().filter((x) => x._encyclopedia);
}
/**
* Create a base assort item and return it with populated values + 999999 stack count + unlimited count = true
* @param tplId tplid to add to item

View File

@ -52,6 +52,11 @@ export class PresetHelper
return this.jsonUtil.clone(this.databaseServer.getTables().globals.ItemPresets[id]);
}
public getAllPresets(): IPreset[]
{
return this.jsonUtil.clone(Object.values(this.databaseServer.getTables().globals.ItemPresets));
}
public getPresets(templateId: string): IPreset[]
{
if (!this.hasPreset(templateId))