Updated 13AddTrader mod example (#42)
Co-authored-by: Echo-55 <82003117+Echo-55@users.noreply.github.com> Reviewed-on: #42 Co-authored-by: Echo55 <echo55@noreply.dev.sp-tarkov.com> Co-committed-by: Echo55 <echo55@noreply.dev.sp-tarkov.com>
This commit is contained in:
parent
10616089ae
commit
b82b84a5eb
@ -55,39 +55,12 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sell_category": [
|
"sell_category": [
|
||||||
"82e7fac0b7495d72d4083356",
|
"575146b724597720a27126d5",
|
||||||
"ac705d3440c1407645e33579",
|
"635a758bfefc88a93f021b8a",
|
||||||
"dc97aee367144dc03389405d",
|
"55d45d3f4bdc2d972f8b456c",
|
||||||
"7ffcc96aa06c7e90940330c5",
|
"5b363dd25acfc4001a598fd2",
|
||||||
"e8f46e3ad74b9d862121f9dc",
|
"5d1b36a186f7742523398433",
|
||||||
"5b47574386f77428ca22b33e",
|
"59e3577886f774176a362503",
|
||||||
"5b47574386f77428ca22b33f",
|
"5d6e67fba4b9361bc73bc779"
|
||||||
"5b5f78dc86f77409407a7f8e",
|
|
||||||
"5b47574386f77428ca22b346",
|
|
||||||
"5b47574386f77428ca22b340",
|
|
||||||
"5b47574386f77428ca22b344",
|
|
||||||
"5b47574386f77428ca22b342",
|
|
||||||
"5b47574386f77428ca22b341",
|
|
||||||
"5b47574386f77428ca22b345",
|
|
||||||
"5b47574386f77428ca22b343",
|
|
||||||
"5b5f71b386f774093f2ecf11",
|
|
||||||
"5b5f71c186f77409407a7ec0",
|
|
||||||
"5b5f71de86f774093f2ecf13",
|
|
||||||
"5b5f724186f77447ed5636ad",
|
|
||||||
"5b5f736886f774094242f193",
|
|
||||||
"5b5f73ec86f774093e6cb4fd",
|
|
||||||
"5b5f74cc86f77447ec5d770a",
|
|
||||||
"5b5f750686f774093e6cb503",
|
|
||||||
"5b5f751486f77447ec5d770c",
|
|
||||||
"5b5f752e86f774093e6cb505",
|
|
||||||
"5b5f754a86f774094242f19b",
|
|
||||||
"5b5f755f86f77447ec5d770e",
|
|
||||||
"5b5f757486f774093e6cb507",
|
|
||||||
"5b5f75b986f77447ec5d7710",
|
|
||||||
"5b5f75c686f774094242f19f",
|
|
||||||
"5b5f75e486f77447ec5d7712",
|
|
||||||
"5b5f760586f774093e6cb509",
|
|
||||||
"5b5f761f86f774094242f1a1",
|
|
||||||
"5b5f764186f77447ec5d7714"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,13 @@ import { TraderHelper } from "./traderHelpers";
|
|||||||
class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod
|
class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod
|
||||||
{
|
{
|
||||||
private mod: string;
|
private mod: string;
|
||||||
|
private traderImgPath: string;
|
||||||
private logger: ILogger;
|
private logger: ILogger;
|
||||||
private traderHelper: TraderHelper;
|
private traderHelper: TraderHelper;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.mod = "acidphantasm-131AddTraderWithAssortJSON"; // Set name of mod so we can log it to console later - match this to your folder name that's built for \user\mods\
|
this.mod = "131AddTraderWithAssortJSON"; // Set name of mod so we can log it to console later - match this to your folder name that's built for \user\mods\
|
||||||
|
this.traderImgPath = "res/cat.jpg"; // Set path to trader image
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +51,7 @@ class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod
|
|||||||
|
|
||||||
// Create helper class and use it to register our traders image/icon + set its stock refresh time
|
// Create helper class and use it to register our traders image/icon + set its stock refresh time
|
||||||
this.traderHelper = new TraderHelper();
|
this.traderHelper = new TraderHelper();
|
||||||
this.traderHelper.registerProfileImage(baseJson, this.mod, preSptModLoader, imageRouter, "cat.jpg");
|
imageRouter.addRoute(baseJson.avatar.replace(".jpg", ""), `${preSptModLoader.getModPath(this.mod)}${this.traderImgPath}`);
|
||||||
this.traderHelper.setTraderUpdateTime(traderConfig, baseJson, 3600, 4000);
|
this.traderHelper.setTraderUpdateTime(traderConfig, baseJson, 3600, 4000);
|
||||||
|
|
||||||
// Add trader to trader enum
|
// Add trader to trader enum
|
||||||
|
@ -7,23 +7,6 @@ import { JsonUtil } from "@spt/utils/JsonUtil";
|
|||||||
|
|
||||||
export class TraderHelper
|
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}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add record to trader config to set the refresh time of trader in seconds (default is 60 minutes)
|
* Add record to trader config to set the refresh time of trader in seconds (default is 60 minutes)
|
||||||
* @param traderConfig trader config to add our trader to
|
* @param traderConfig trader config to add our trader to
|
||||||
|
@ -55,39 +55,12 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sell_category": [
|
"sell_category": [
|
||||||
"82e7fac0b7495d72d4083356",
|
"575146b724597720a27126d5",
|
||||||
"ac705d3440c1407645e33579",
|
"635a758bfefc88a93f021b8a",
|
||||||
"dc97aee367144dc03389405d",
|
"55d45d3f4bdc2d972f8b456c",
|
||||||
"7ffcc96aa06c7e90940330c5",
|
"5b363dd25acfc4001a598fd2",
|
||||||
"e8f46e3ad74b9d862121f9dc",
|
"5d1b36a186f7742523398433",
|
||||||
"5b47574386f77428ca22b33e",
|
"59e3577886f774176a362503",
|
||||||
"5b47574386f77428ca22b33f",
|
"5d6e67fba4b9361bc73bc779"
|
||||||
"5b5f78dc86f77409407a7f8e",
|
|
||||||
"5b47574386f77428ca22b346",
|
|
||||||
"5b47574386f77428ca22b340",
|
|
||||||
"5b47574386f77428ca22b344",
|
|
||||||
"5b47574386f77428ca22b342",
|
|
||||||
"5b47574386f77428ca22b341",
|
|
||||||
"5b47574386f77428ca22b345",
|
|
||||||
"5b47574386f77428ca22b343",
|
|
||||||
"5b5f71b386f774093f2ecf11",
|
|
||||||
"5b5f71c186f77409407a7ec0",
|
|
||||||
"5b5f71de86f774093f2ecf13",
|
|
||||||
"5b5f724186f77447ed5636ad",
|
|
||||||
"5b5f736886f774094242f193",
|
|
||||||
"5b5f73ec86f774093e6cb4fd",
|
|
||||||
"5b5f74cc86f77447ec5d770a",
|
|
||||||
"5b5f750686f774093e6cb503",
|
|
||||||
"5b5f751486f77447ec5d770c",
|
|
||||||
"5b5f752e86f774093e6cb505",
|
|
||||||
"5b5f754a86f774094242f19b",
|
|
||||||
"5b5f755f86f77447ec5d770e",
|
|
||||||
"5b5f757486f774093e6cb507",
|
|
||||||
"5b5f75b986f77447ec5d7710",
|
|
||||||
"5b5f75c686f774094242f19f",
|
|
||||||
"5b5f75e486f77447ec5d7712",
|
|
||||||
"5b5f760586f774093e6cb509",
|
|
||||||
"5b5f761f86f774094242f1a1",
|
|
||||||
"5b5f764186f77447ec5d7714"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import { DependencyContainer } from "tsyringe";
|
|||||||
import { IPreSptLoadMod } from "@spt/models/external/IPreSptLoadMod";
|
import { IPreSptLoadMod } from "@spt/models/external/IPreSptLoadMod";
|
||||||
import { IPostDBLoadMod } from "@spt/models/external/IPostDBLoadMod";
|
import { IPostDBLoadMod } from "@spt/models/external/IPostDBLoadMod";
|
||||||
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
||||||
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
|
|
||||||
import { DatabaseServer } from "@spt/servers/DatabaseServer";
|
import { DatabaseServer } from "@spt/servers/DatabaseServer";
|
||||||
import { ImageRouter } from "@spt/routers/ImageRouter";
|
import { ImageRouter } from "@spt/routers/ImageRouter";
|
||||||
import { ConfigServer } from "@spt/servers/ConfigServer";
|
import { ConfigServer } from "@spt/servers/ConfigServer";
|
||||||
@ -25,6 +24,7 @@ import { ItemTpl } from "@spt/models/enums/ItemTpl";
|
|||||||
|
|
||||||
class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod {
|
class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod {
|
||||||
private mod: string;
|
private mod: string;
|
||||||
|
private traderImgPath: string;
|
||||||
private logger: ILogger;
|
private logger: ILogger;
|
||||||
private traderHelper: TraderHelper;
|
private traderHelper: TraderHelper;
|
||||||
private fluentAssortCreator: FluentAssortCreator;
|
private fluentAssortCreator: FluentAssortCreator;
|
||||||
@ -34,6 +34,7 @@ class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.mod = "13AddTrader"; // Set name of mod so we can log it to console later
|
this.mod = "13AddTrader"; // Set name of mod so we can log it to console later
|
||||||
|
this.traderImgPath = "res/cat.jpg"; // Set path to trader image
|
||||||
// Get base json from /db/ folder
|
// Get base json from /db/ folder
|
||||||
this.traderBase = baseJson;
|
this.traderBase = baseJson;
|
||||||
this.traderNickname = "Cat"
|
this.traderNickname = "Cat"
|
||||||
@ -49,7 +50,6 @@ class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod {
|
|||||||
this.logger.debug(`[${this.mod}] preSpt Loading... `);
|
this.logger.debug(`[${this.mod}] preSpt Loading... `);
|
||||||
|
|
||||||
// Get SPT code/data we need later
|
// Get SPT code/data we need later
|
||||||
const preSptModLoader: PreSptModLoader = container.resolve<PreSptModLoader>("PreSptModLoader");
|
|
||||||
const imageRouter: ImageRouter = container.resolve<ImageRouter>("ImageRouter");
|
const imageRouter: ImageRouter = container.resolve<ImageRouter>("ImageRouter");
|
||||||
const hashUtil: HashUtil = container.resolve<HashUtil>("HashUtil");
|
const hashUtil: HashUtil = container.resolve<HashUtil>("HashUtil");
|
||||||
const configServer = container.resolve<ConfigServer>("ConfigServer");
|
const configServer = container.resolve<ConfigServer>("ConfigServer");
|
||||||
@ -58,12 +58,15 @@ class SampleTrader implements IPreSptLoadMod, IPostDBLoadMod {
|
|||||||
|
|
||||||
// IMPORTANT - YOUR TRADER NEEDS A UNIQUE MONGO-ID, ASK IN DISCORD IF YOU DONT KNOW WHAT THAT IS
|
// IMPORTANT - YOUR TRADER NEEDS A UNIQUE MONGO-ID, ASK IN DISCORD IF YOU DONT KNOW WHAT THAT IS
|
||||||
// GOOGLE "mongoid generator"
|
// GOOGLE "mongoid generator"
|
||||||
this.traderBase._id = "66eeef8b2a166b73d2066a7e";
|
this.traderBase = {
|
||||||
|
...baseJson,
|
||||||
|
_id: "66eeef8b2a166b73d2066a7e" // This is a unique ID for your trader, also the first key in base.json
|
||||||
|
};
|
||||||
|
|
||||||
// Create helper class and use it to register our traders image/icon + set its stock refresh time
|
// Create helper class and use it to register our traders image/icon + set its stock refresh time
|
||||||
this.traderHelper = new TraderHelper();
|
this.traderHelper = new TraderHelper();
|
||||||
this.fluentAssortCreator = new FluentAssortCreator(hashUtil, this.logger);
|
this.fluentAssortCreator = new FluentAssortCreator(hashUtil, this.logger);
|
||||||
this.traderHelper.registerProfileImage(this.traderBase, this.mod, preSptModLoader, imageRouter, "cat.jpg");
|
imageRouter.addRoute(this.traderBase.avatar.replace(".jpg", ""), this.traderImgPath);
|
||||||
this.traderHelper.setTraderUpdateTime(traderConfig, this.traderBase, 3600, 4000);
|
this.traderHelper.setTraderUpdateTime(traderConfig, this.traderBase, 3600, 4000);
|
||||||
|
|
||||||
// Add trader to trader enum
|
// Add trader to trader enum
|
||||||
|
@ -1,28 +1,13 @@
|
|||||||
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
|
import {PreSptModLoader} from "@spt/loaders/PreSptModLoader";
|
||||||
import { Item } from "@spt/models/eft/common/tables/IItem";
|
import {IItem} from "@spt/models/eft/common/tables/IItem";
|
||||||
import { ITraderBase, ITraderAssort } from "@spt/models/eft/common/tables/ITrader";
|
import {ITraderBase, ITraderAssort} from "@spt/models/eft/common/tables/ITrader";
|
||||||
import { ITraderConfig, UpdateTime } from "@spt/models/spt/config/ITraderConfig";
|
import {ITraderConfig, IUpdateTime} from "@spt/models/spt/config/ITraderConfig";
|
||||||
import { IDatabaseTables } from "@spt/models/spt/server/IDatabaseTables";
|
import {IDatabaseTables} from "@spt/models/spt/server/IDatabaseTables";
|
||||||
import { ImageRouter } from "@spt/routers/ImageRouter";
|
import {ImageRouter} from "@spt/routers/ImageRouter";
|
||||||
import { JsonUtil } from "@spt/utils/JsonUtil";
|
import {JsonUtil} from "@spt/utils/JsonUtil";
|
||||||
import { NewItemIds } from "./newitemIds";
|
import {NewItemIds} from "./newItemIds";
|
||||||
|
|
||||||
export class TraderHelper {
|
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}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add record to trader config to set the refresh time of trader in seconds (default is 60 minutes)
|
* Add record to trader config to set the refresh time of trader in seconds (default is 60 minutes)
|
||||||
@ -33,7 +18,7 @@ export class TraderHelper {
|
|||||||
*/
|
*/
|
||||||
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
|
// Add refresh time in seconds to config
|
||||||
const traderRefreshRecord: UpdateTime = {
|
const traderRefreshRecord: IUpdateTime = {
|
||||||
traderId: baseJson._id,
|
traderId: baseJson._id,
|
||||||
seconds: {
|
seconds: {
|
||||||
min: refreshTimeSecondsMin,
|
min: refreshTimeSecondsMin,
|
||||||
@ -83,9 +68,9 @@ export class TraderHelper {
|
|||||||
* Create a weapon from scratch, ready to be added to trader
|
* Create a weapon from scratch, ready to be added to trader
|
||||||
* @returns Item[]
|
* @returns Item[]
|
||||||
*/
|
*/
|
||||||
public createGlock(): Item[] {
|
public createGlock(): IItem[] {
|
||||||
// Create an array ready to hold weapon + all mods
|
// Create an array ready to hold weapon + all mods
|
||||||
const glock: Item[] = [];
|
const glock: IItem[] = [];
|
||||||
|
|
||||||
// Add the base first
|
// Add the base first
|
||||||
glock.push({ // Add the base weapon first
|
glock.push({ // Add the base weapon first
|
||||||
@ -153,15 +138,15 @@ export class TraderHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add traders name/location/description to the locale table
|
* Add traders name/location/description to the locale table
|
||||||
* @param baseJson json file for trader (db/base.json)
|
* @param baseJson json file for trader (db/base.json)
|
||||||
* @param tables database tables
|
* @param tables database tables
|
||||||
* @param fullName Complete name of trader
|
* @param fullName Complete name of trader
|
||||||
* @param firstName First name of trader
|
* @param firstName First name of trader
|
||||||
* @param nickName Nickname of trader
|
* @param nickName Nickname of trader
|
||||||
* @param location Location of trader (e.g. "Here in the cat shop")
|
* @param location Location of trader (e.g. "Here in the cat shop")
|
||||||
* @param description Description of trader
|
* @param description Description of trader
|
||||||
*/
|
*/
|
||||||
public addTraderToLocales(baseJson: any, tables: IDatabaseTables, fullName: string, firstName: string, nickName: string, location: string, description: string) {
|
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
|
// For each language, add locale for the new trader
|
||||||
const locales = Object.values(tables.locales.global);
|
const locales = Object.values(tables.locales.global);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user