2023-03-03 16:23:46 +01:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
|
2023-10-19 19:21:17 +02:00
|
|
|
import { HandbookHelper } from "@spt-aki/helpers/HandbookHelper";
|
|
|
|
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
|
|
|
import { Item } from "@spt-aki/models/eft/common/tables/IItem";
|
|
|
|
import { ITemplateItem } from "@spt-aki/models/eft/common/tables/ITemplateItem";
|
|
|
|
import { IBarterScheme } from "@spt-aki/models/eft/common/tables/ITrader";
|
|
|
|
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
|
|
|
|
import { Money } from "@spt-aki/models/enums/Money";
|
|
|
|
import { Traders } from "@spt-aki/models/enums/Traders";
|
|
|
|
import { ITraderConfig } from "@spt-aki/models/spt/config/ITraderConfig";
|
|
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
|
|
|
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
|
|
|
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
|
|
|
import { ItemFilterService } from "@spt-aki/services/ItemFilterService";
|
|
|
|
import { SeasonalEventService } from "@spt-aki/services/SeasonalEventService";
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class FenceBaseAssortGenerator
|
|
|
|
{
|
|
|
|
protected traderConfig: ITraderConfig;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
@inject("WinstonLogger") protected logger: ILogger,
|
|
|
|
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
|
|
|
@inject("HandbookHelper") protected handbookHelper: HandbookHelper,
|
|
|
|
@inject("ItemHelper") protected itemHelper: ItemHelper,
|
|
|
|
@inject("ItemFilterService") protected itemFilterService: ItemFilterService,
|
2023-07-22 15:11:47 +02:00
|
|
|
@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.traderConfig = this.configServer.getConfig(ConfigTypes.TRADER);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create base fence assorts dynamically and store in db
|
|
|
|
*/
|
|
|
|
public generateFenceBaseAssorts(): void
|
|
|
|
{
|
2023-11-01 12:35:05 +01:00
|
|
|
const blockedSeasonalItems = this.seasonalEventService.getInactiveSeasonalEventItems();
|
2023-07-22 15:11:47 +02:00
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
const baseFenceAssort = this.databaseServer.getTables().traders[Traders.FENCE].assort;
|
|
|
|
|
|
|
|
const dbItems = Object.values(this.databaseServer.getTables().templates.items);
|
2023-11-16 02:35:05 +01:00
|
|
|
for (const item of dbItems.filter((x) => this.isValidFenceItem(x)))
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
// Skip blacklisted items
|
|
|
|
if (this.itemFilterService.isItemBlacklisted(item._id))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.itemHelper.isValidItem(item._id))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip items on fence ignore list
|
|
|
|
if (this.traderConfig.fence.blacklist.length > 0)
|
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
if (
|
|
|
|
this.traderConfig.fence.blacklist.includes(item._id)
|
|
|
|
|| this.itemHelper.isOfBaseclasses(item._id, this.traderConfig.fence.blacklist)
|
|
|
|
)
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-22 15:11:47 +02:00
|
|
|
// Skip seasonal event items when not in seasonal event
|
2023-07-22 15:16:19 +02:00
|
|
|
if (this.traderConfig.fence.blacklistSeasonalItems && blockedSeasonalItems.includes(item._id))
|
2023-07-22 15:11:47 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
// Create barter scheme object
|
|
|
|
const barterSchemeToAdd: IBarterScheme = {
|
2023-11-16 02:35:05 +01:00
|
|
|
count: Math.round(
|
|
|
|
this.handbookHelper.getTemplatePrice(item._id) * this.traderConfig.fence.itemPriceMult,
|
|
|
|
),
|
|
|
|
_tpl: Money.ROUBLES,
|
2023-03-03 16:23:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Add barter data to base
|
|
|
|
baseFenceAssort.barter_scheme[item._id] = [[barterSchemeToAdd]];
|
|
|
|
|
|
|
|
// Create item object
|
|
|
|
const itemToAdd: Item = {
|
|
|
|
_id: item._id,
|
|
|
|
_tpl: item._id,
|
|
|
|
parentId: "hideout",
|
|
|
|
slotId: "hideout",
|
2023-11-16 02:35:05 +01:00
|
|
|
upd: { StackObjectsCount: 9999999, UnlimitedCount: true },
|
2023-03-03 16:23:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Add item to base
|
|
|
|
baseFenceAssort.items.push(itemToAdd);
|
|
|
|
|
|
|
|
// Add loyalty data to base
|
|
|
|
baseFenceAssort.loyal_level_items[item._id] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if item is valid for being added to fence assorts
|
|
|
|
* @param item Item to check
|
|
|
|
* @returns true if valid fence item
|
|
|
|
*/
|
|
|
|
protected isValidFenceItem(item: ITemplateItem): boolean
|
|
|
|
{
|
|
|
|
if (item._type === "Item")
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2023-11-16 02:35:05 +01:00
|
|
|
}
|