4ac12ef70a
These are the formatting & linting configuration changes from the `3.8.0` branch and the changes that they make to the overall project. The majority of these changes are from running two commands: `npm run lint:fix` `npm run style:fix` This has already been run on the `3.8.0` branch and this PR should make `master` play nicer when it comes to merges going forward. There are now four VSCode plugins recommended for server development. They've been added to the workspace file and a user should get a UI notification when the workspace is opened if they're not installed. The four plugins are: https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig https://marketplace.visualstudio.com/items?itemName=dprint.dprint https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint https://marketplace.visualstudio.com/items?itemName=biomejs.biome Once installed they should just work within the workspace. Also, be sure to `npm i` to get the new dprint application. Co-authored-by: Refringe <brownelltyler@gmail.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/168
126 lines
4.4 KiB
TypeScript
126 lines
4.4 KiB
TypeScript
import { inject, injectable } from "tsyringe";
|
|
|
|
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";
|
|
|
|
@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,
|
|
@inject("SeasonalEventService") protected seasonalEventService: SeasonalEventService,
|
|
@inject("ConfigServer") protected configServer: ConfigServer,
|
|
)
|
|
{
|
|
this.traderConfig = this.configServer.getConfig(ConfigTypes.TRADER);
|
|
}
|
|
|
|
/**
|
|
* Create base fence assorts dynamically and store in db
|
|
*/
|
|
public generateFenceBaseAssorts(): void
|
|
{
|
|
const blockedSeasonalItems = this.seasonalEventService.getAllSeasonalEventItems();
|
|
|
|
const baseFenceAssort = this.databaseServer.getTables().traders[Traders.FENCE].assort;
|
|
|
|
const dbItems = Object.values(this.databaseServer.getTables().templates.items);
|
|
for (const item of dbItems.filter((x) => this.isValidFenceItem(x)))
|
|
{
|
|
// Skip blacklisted items
|
|
if (this.itemFilterService.isItemBlacklisted(item._id))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!this.itemHelper.isValidItem(item._id))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Skip quest items
|
|
if (item._props.QuestItem)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Skip items on fence ignore list
|
|
if (this.traderConfig.fence.blacklist.length > 0)
|
|
{
|
|
if (
|
|
this.traderConfig.fence.blacklist.includes(item._id)
|
|
|| this.itemHelper.isOfBaseclasses(item._id, this.traderConfig.fence.blacklist)
|
|
)
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
|
|
// Skip seasonal event items when not in seasonal event
|
|
if (this.traderConfig.fence.blacklistSeasonalItems && blockedSeasonalItems.includes(item._id))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Create barter scheme object
|
|
const barterSchemeToAdd: IBarterScheme = {
|
|
count: Math.round(
|
|
this.handbookHelper.getTemplatePrice(item._id) * this.traderConfig.fence.itemPriceMult,
|
|
),
|
|
_tpl: Money.ROUBLES,
|
|
};
|
|
|
|
// 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",
|
|
upd: { StackObjectsCount: 9999999, UnlimitedCount: true },
|
|
};
|
|
|
|
// 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;
|
|
}
|
|
}
|