2023-03-03 16:23:46 +01:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
|
2023-10-19 19:21:17 +02:00
|
|
|
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
2024-01-16 11:28:08 +01:00
|
|
|
import { PresetHelper } from "@spt-aki/helpers/PresetHelper";
|
2023-10-19 19:21:17 +02:00
|
|
|
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";
|
|
|
|
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
|
|
|
|
import { IRagfairConfig } from "@spt-aki/models/spt/config/IRagfairConfig";
|
|
|
|
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
|
|
|
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
|
|
|
import { SeasonalEventService } from "@spt-aki/services/SeasonalEventService";
|
|
|
|
import { HashUtil } from "@spt-aki/utils/HashUtil";
|
|
|
|
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class RagfairAssortGenerator
|
|
|
|
{
|
|
|
|
protected generatedAssortItems: Item[] = [];
|
|
|
|
protected ragfairConfig: IRagfairConfig;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
|
|
|
@inject("HashUtil") protected hashUtil: HashUtil,
|
|
|
|
@inject("ItemHelper") protected itemHelper: ItemHelper,
|
2024-01-16 11:28:08 +01:00
|
|
|
@inject("PresetHelper") protected presetHelper: PresetHelper,
|
2023-03-03 16:23:46 +01:00
|
|
|
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
|
|
|
@inject("SeasonalEventService") protected seasonalEventService: SeasonalEventService,
|
2023-11-16 02:35:05 +01:00
|
|
|
@inject("ConfigServer") protected configServer: ConfigServer,
|
2023-03-03 16:23:46 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
this.ragfairConfig = this.configServer.getConfig(ConfigTypes.RAGFAIR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an array of unique items that can be sold on the flea
|
|
|
|
* @returns array of unique items
|
|
|
|
*/
|
|
|
|
public getAssortItems(): Item[]
|
|
|
|
{
|
|
|
|
if (!this.assortsAreGenerated())
|
|
|
|
{
|
|
|
|
this.generatedAssortItems = this.generateRagfairAssortItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.generatedAssortItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check internal generatedAssortItems array has objects
|
|
|
|
* @returns true if array has objects
|
|
|
|
*/
|
|
|
|
protected assortsAreGenerated(): boolean
|
|
|
|
{
|
|
|
|
return this.generatedAssortItems.length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate an array of items the flea can sell
|
|
|
|
* @returns array of unique items
|
|
|
|
*/
|
|
|
|
protected generateRagfairAssortItems(): Item[]
|
|
|
|
{
|
|
|
|
const results: Item[] = [];
|
2024-01-12 22:59:30 +01:00
|
|
|
const items = this.itemHelper.getItems().filter(item => item._type !== "Node");
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2024-01-16 11:28:08 +01:00
|
|
|
const presets = (this.ragfairConfig.dynamic.showDefaultPresetsOnly)
|
|
|
|
? Object.values(this.presetHelper.getDefaultPresets())
|
|
|
|
: this.presetHelper.getAllPresets()
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
const ragfairItemInvalidBaseTypes: string[] = [
|
|
|
|
BaseClasses.LOOT_CONTAINER, // safe, barrel cache etc
|
|
|
|
BaseClasses.STASH, // player inventory stash
|
|
|
|
BaseClasses.SORTING_TABLE,
|
|
|
|
BaseClasses.INVENTORY,
|
|
|
|
BaseClasses.STATIONARY_CONTAINER,
|
2023-11-16 02:35:05 +01:00
|
|
|
BaseClasses.POCKETS,
|
2024-01-12 22:59:30 +01:00
|
|
|
BaseClasses.BUILT_IN_INSERTS,
|
2024-01-16 11:28:08 +01:00
|
|
|
BaseClasses.ARMOR, // Handled by presets
|
|
|
|
BaseClasses.VEST, // Handled by presets
|
|
|
|
BaseClasses.HEADWEAR, // Handled by presets
|
2023-03-03 16:23:46 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled();
|
2023-11-01 12:35:05 +01:00
|
|
|
const seasonalItemTplBlacklist = this.seasonalEventService.getInactiveSeasonalEventItems();
|
2023-03-03 16:23:46 +01:00
|
|
|
for (const item of items)
|
|
|
|
{
|
|
|
|
if (!this.itemHelper.isValidItem(item._id, ragfairItemInvalidBaseTypes))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-11-16 02:35:05 +01:00
|
|
|
if (
|
|
|
|
this.ragfairConfig.dynamic.removeSeasonalItemsWhenNotInEvent && !seasonalEventActive
|
|
|
|
&& seasonalItemTplBlacklist.includes(item._id)
|
|
|
|
)
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-04-23 14:44:15 +02:00
|
|
|
results.push(this.createRagfairAssortItem(item._id, item._id)); // tplid and id must be the same so hideout recipe reworks work
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
2024-01-16 11:28:08 +01:00
|
|
|
for (const weapon of presets)
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
2024-01-12 22:59:30 +01:00
|
|
|
results.push(this.createRagfairAssortItem(weapon._items[0]._tpl, weapon._id)); // Preset id must be passed through to ensure flea shows presets
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return results;
|
|
|
|
}
|
2023-11-16 02:35:05 +01:00
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
/**
|
|
|
|
* 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 id id to add to item
|
|
|
|
* @returns hydrated Item object
|
|
|
|
*/
|
|
|
|
protected createRagfairAssortItem(tplId: string, id = this.hashUtil.generate()): Item
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
_id: id,
|
|
|
|
_tpl: tplId,
|
|
|
|
parentId: "hideout",
|
|
|
|
slotId: "hideout",
|
2023-11-16 02:35:05 +01:00
|
|
|
upd: { StackObjectsCount: 99999999, UnlimitedCount: true },
|
2023-03-03 16:23:46 +01:00
|
|
|
};
|
|
|
|
}
|
2023-11-16 02:35:05 +01:00
|
|
|
}
|