diff --git a/TypeScript/13AddTrader/src/mod.ts b/TypeScript/13AddTrader/src/mod.ts index f110e8f..e917e00 100644 --- a/TypeScript/13AddTrader/src/mod.ts +++ b/TypeScript/13AddTrader/src/mod.ts @@ -21,9 +21,9 @@ import * as baseJson from "../db/base.json"; import { TraderHelper } from "./traderHelpers"; import { FluentAssortConstructor as FluentAssortCreator } from "./fluentTraderAssortCreator"; +import { ItemTpl } from "@spt/models/enums/ItemTpl"; -class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod -{ +class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod { private mod: string; private logger: ILogger; private traderHelper: TraderHelper; @@ -37,8 +37,7 @@ class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod * Some work needs to be done prior to SPT code being loaded, registering the profile image + setting trader update time inside the trader config json * @param container Dependency container */ - public preSptLoad(container: DependencyContainer): void - { + public preSptLoad(container: DependencyContainer): void { // Get a logger this.logger = container.resolve("WinstonLogger"); this.logger.debug(`[${this.mod}] preSpt Loading... `); @@ -70,8 +69,7 @@ class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod * Majority of trader-related work occurs after the aki database has been loaded but prior to SPT code being run * @param container Dependency container */ - public postDBLoad(container: DependencyContainer): void - { + public postDBLoad(container: DependencyContainer): void { this.logger.debug(`[${this.mod}] postDb Loading... `); // Resolve SPT classes we'll use @@ -86,9 +84,9 @@ class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod this.traderHelper.addTraderToDb(baseJson, tables, jsonUtil); // Add milk - const MILK_ID = "575146b724597720a27126d5"; // Can find item ids in `database\templates\items.json` or with https://db.sp-tarkov.com/search + this.fluentAssortCreator - .createSingleAssortItem(MILK_ID) + .createSingleAssortItem(ItemTpl.DRINK_PACK_OF_MILK) .addStackCount(200) .addBuyRestriction(10) .addMoneyCost(Money.ROUBLES, 2000) @@ -96,13 +94,11 @@ class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod .export(tables.traders[baseJson._id]); // Add 3x bitcoin + salewa for milk barter - const BITCOIN_ID = "59faff1d86f7746c51718c9c"; - const SALEWA_ID = "544fb45d4bdc2dee738b4568"; this.fluentAssortCreator - .createSingleAssortItem(MILK_ID) + .createSingleAssortItem(ItemTpl.DRINK_PACK_OF_MILK) .addStackCount(100) - .addBarterCost(BITCOIN_ID, 3) - .addBarterCost(SALEWA_ID, 1) + .addBarterCost(ItemTpl.BARTER_PHYSICAL_BITCOIN, 3) + .addBarterCost(ItemTpl.MEDKIT_SALEWA_FIRST_AID_KIT, 1) .addLoyaltyLevel(1) .export(tables.traders[baseJson._id]); @@ -118,9 +114,9 @@ class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod // Add mp133 preset as mayo barter this.fluentAssortCreator - .createComplexAssortItem(tables.globals.ItemPresets["584148f2245977598f1ad387"]._items) + .createComplexAssortItem(tables.globals.ItemPresets["584148f2245977598f1ad387"]._items) // Weapon preset id comes from globals.json .addStackCount(200) - .addBarterCost("5bc9b156d4351e00367fbce9", 1) + .addBarterCost(ItemTpl.FOOD_JAR_OF_DEVILDOG_MAYO, 1) .addBuyRestriction(3) .addLoyaltyLevel(1) .export(tables.traders[baseJson._id]); diff --git a/TypeScript/13AddTrader/src/traderHelpers.ts b/TypeScript/13AddTrader/src/traderHelpers.ts index ed2e897..68f3a8c 100644 --- a/TypeScript/13AddTrader/src/traderHelpers.ts +++ b/TypeScript/13AddTrader/src/traderHelpers.ts @@ -6,24 +6,22 @@ import { IDatabaseTables } from "@spt/models/spt/server/IDatabaseTables"; import { ImageRouter } from "@spt/routers/ImageRouter"; import { JsonUtil } from "@spt/utils/JsonUtil"; -export class TraderHelper -{ - /** - * Add profile picture to our trader - * @param baseJson json file for trader (db/base.json) - * @param modName mod folder name - * @param preSptModLoader mod loader class - used to get the mods file path - * @param imageRouter image router class - used to register the trader image path so we see their image on trader page - * @param traderImageName Filename of the trader icon to use - */ - public registerProfileImage(baseJson: any, modName: string, preSptModLoader: PreSptModLoader, imageRouter: ImageRouter, traderImageName: string): void - { - // Reference the mod "res" folder - const imageFilepath = `./${preSptModLoader.getModPath(modName)}res`; +export class TraderHelper { + /** + * Add profile picture to our trader + * @param baseJson json file for trader (db/base.json) + * @param modName mod folder name + * @param preSptModLoader mod loader class - used to get the mods file path + * @param imageRouter image router class - used to register the trader image path so we see their image on trader page + * @param traderImageName Filename of the trader icon to use + */ + public registerProfileImage(baseJson: any, modName: string, preSptModLoader: PreSptModLoader, imageRouter: ImageRouter, traderImageName: string): void { + // Reference the mod "res" folder + const imageFilepath = `./${preSptModLoader.getModPath(modName)}res`; - // Register a route to point to the profile picture - remember to remove the .jpg from it - imageRouter.addRoute(baseJson.avatar.replace(".jpg", ""), `${imageFilepath}/${traderImageName}`); - } + // Register a route to point to the profile picture - remember to remove the .jpg from it + imageRouter.addRoute(baseJson.avatar.replace(".jpg", ""), `${imageFilepath}/${traderImageName}`); + } /** * Add record to trader config to set the refresh time of trader in seconds (default is 60 minutes) @@ -32,8 +30,7 @@ export class TraderHelper * @param refreshTimeSecondsMin How many seconds between trader stock refresh min time * @param refreshTimeSecondsMax How many seconds between trader stock refresh max time */ - public setTraderUpdateTime(traderConfig: ITraderConfig, baseJson: any, refreshTimeSecondsMin: number, refreshTimeSecondsMax: number): void - { + public setTraderUpdateTime(traderConfig: ITraderConfig, baseJson: any, refreshTimeSecondsMin: number, refreshTimeSecondsMax: number): void { // Add refresh time in seconds to config const traderRefreshRecord: UpdateTime = { traderId: baseJson._id, @@ -53,8 +50,7 @@ export class TraderHelper * @param jsonUtil json utility class */ // rome-ignore lint/suspicious/noExplicitAny: traderDetailsToAdd comes from base.json, so no type - public addTraderToDb(traderDetailsToAdd: any, tables: IDatabaseTables, jsonUtil: JsonUtil): void - { + public addTraderToDb(traderDetailsToAdd: any, tables: IDatabaseTables, jsonUtil: JsonUtil): void { // Add trader to trader table, key is the traders id tables.traders[traderDetailsToAdd._id] = { assort: this.createAssortTable(), // assorts are the 'offers' trader sells, can be a single item (e.g. carton of milk) or multiple items as a collection (e.g. a gun) @@ -71,8 +67,7 @@ export class TraderHelper * Create basic data for trader + add empty assorts table for trader * @returns ITraderAssort */ - private createAssortTable(): ITraderAssort - { + private createAssortTable(): ITraderAssort { // Create a blank assort object, ready to have items added const assortTable: ITraderAssort = { nextResupply: 0, @@ -88,8 +83,7 @@ export class TraderHelper * Create a weapon from scratch, ready to be added to trader * @returns Item[] */ - public createGlock(): Item[] - { + public createGlock(): Item[] { // Create an array ready to hold weapon + all mods const glock: Item[] = []; @@ -110,15 +104,15 @@ export class TraderHelper // Add reciever glock.push({ _id: "glockReciever", - _tpl:"5a9685b1a2750c0032157104", + _tpl: "5a9685b1a2750c0032157104", parentId: "glockBase", slotId: "mod_reciever", }); - // Add compensator - glock.push({ + // Add compensator + glock.push({ _id: "glockCompensator", - _tpl:"5a7b32a2e899ef00135e345a", + _tpl: "5a7b32a2e899ef00135e345a", parentId: "glockReciever", // The parent of this mod is the reciever NOT weapon, be careful to get the correct parent slotId: "mod_muzzle", }); @@ -126,7 +120,7 @@ export class TraderHelper // Add Pistol grip glock.push({ _id: "glockPistolGrip", - _tpl:"5a7b4960e899ef197b331a2d", + _tpl: "5a7b4960e899ef197b331a2d", parentId: "glockBase", slotId: "mod_pistol_grip", }); @@ -158,18 +152,17 @@ export class TraderHelper return glock; } - /** - * Add traders name/location/description to the locale table - * @param baseJson json file for trader (db/base.json) - * @param tables database tables - * @param fullName Complete name of trader - * @param firstName First name of trader - * @param nickName Nickname of trader - * @param location Location of trader (e.g. "Here in the cat shop") - * @param description Description of trader - */ - public addTraderToLocales(baseJson: any, tables: IDatabaseTables, fullName: string, firstName: string, nickName: string, location: string, description: string) - { + /** + * Add traders name/location/description to the locale table + * @param baseJson json file for trader (db/base.json) + * @param tables database tables + * @param fullName Complete name of trader + * @param firstName First name of trader + * @param nickName Nickname of trader + * @param location Location of trader (e.g. "Here in the cat shop") + * @param description Description of trader + */ + public addTraderToLocales(baseJson: any, tables: IDatabaseTables, fullName: string, firstName: string, nickName: string, location: string, description: string) { // For each language, add locale for the new trader const locales = Object.values(tables.locales.global);