Make use of presetHelper instead of rolling own implementation
This commit is contained in:
parent
e1a8f26507
commit
4d1066b51a
@ -1,6 +1,7 @@
|
|||||||
import { inject, injectable } from "tsyringe";
|
import { inject, injectable } from "tsyringe";
|
||||||
|
|
||||||
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
||||||
|
import { PresetHelper } from "@spt-aki/helpers/PresetHelper";
|
||||||
import { IPreset } from "@spt-aki/models/eft/common/IGlobals";
|
import { IPreset } from "@spt-aki/models/eft/common/IGlobals";
|
||||||
import { Item } from "@spt-aki/models/eft/common/tables/IItem";
|
import { Item } from "@spt-aki/models/eft/common/tables/IItem";
|
||||||
import { BaseClasses } from "@spt-aki/models/enums/BaseClasses";
|
import { BaseClasses } from "@spt-aki/models/enums/BaseClasses";
|
||||||
@ -22,6 +23,7 @@ export class RagfairAssortGenerator
|
|||||||
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
||||||
@inject("HashUtil") protected hashUtil: HashUtil,
|
@inject("HashUtil") protected hashUtil: HashUtil,
|
||||||
@inject("ItemHelper") protected itemHelper: ItemHelper,
|
@inject("ItemHelper") protected itemHelper: ItemHelper,
|
||||||
|
@inject("PresetHelper") protected presetHelper: PresetHelper,
|
||||||
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
||||||
@inject("SeasonalEventService") protected seasonalEventService: SeasonalEventService,
|
@inject("SeasonalEventService") protected seasonalEventService: SeasonalEventService,
|
||||||
@inject("ConfigServer") protected configServer: ConfigServer,
|
@inject("ConfigServer") protected configServer: ConfigServer,
|
||||||
@ -62,9 +64,9 @@ export class RagfairAssortGenerator
|
|||||||
const results: Item[] = [];
|
const results: Item[] = [];
|
||||||
const items = this.itemHelper.getItems().filter(item => item._type !== "Node");
|
const items = this.itemHelper.getItems().filter(item => item._type !== "Node");
|
||||||
|
|
||||||
const weaponPresets = (this.ragfairConfig.dynamic.showDefaultPresetsOnly)
|
const presets = (this.ragfairConfig.dynamic.showDefaultPresetsOnly)
|
||||||
? this.getDefaultPresets()
|
? Object.values(this.presetHelper.getDefaultPresets())
|
||||||
: this.getPresets();
|
: this.presetHelper.getAllPresets()
|
||||||
|
|
||||||
const ragfairItemInvalidBaseTypes: string[] = [
|
const ragfairItemInvalidBaseTypes: string[] = [
|
||||||
BaseClasses.LOOT_CONTAINER, // safe, barrel cache etc
|
BaseClasses.LOOT_CONTAINER, // safe, barrel cache etc
|
||||||
@ -74,9 +76,9 @@ export class RagfairAssortGenerator
|
|||||||
BaseClasses.STATIONARY_CONTAINER,
|
BaseClasses.STATIONARY_CONTAINER,
|
||||||
BaseClasses.POCKETS,
|
BaseClasses.POCKETS,
|
||||||
BaseClasses.BUILT_IN_INSERTS,
|
BaseClasses.BUILT_IN_INSERTS,
|
||||||
BaseClasses.ARMOR,
|
BaseClasses.ARMOR, // Handled by presets
|
||||||
BaseClasses.VEST,
|
BaseClasses.VEST, // Handled by presets
|
||||||
BaseClasses.HEADWEAR,
|
BaseClasses.HEADWEAR, // Handled by presets
|
||||||
];
|
];
|
||||||
|
|
||||||
const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled();
|
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
|
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
|
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;
|
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
|
* Create a base assort item and return it with populated values + 999999 stack count + unlimited count = true
|
||||||
* @param tplId tplid to add to item
|
* @param tplId tplid to add to item
|
||||||
|
@ -52,6 +52,11 @@ export class PresetHelper
|
|||||||
return this.jsonUtil.clone(this.databaseServer.getTables().globals.ItemPresets[id]);
|
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[]
|
public getPresets(templateId: string): IPreset[]
|
||||||
{
|
{
|
||||||
if (!this.hasPreset(templateId))
|
if (!this.hasPreset(templateId))
|
||||||
|
Loading…
Reference in New Issue
Block a user