From 00e367ffa5ea21f7ae2b5449be4307f6f171eee9 Mon Sep 17 00:00:00 2001 From: chomp Date: Sat, 11 Mar 2023 17:38:20 +0000 Subject: [PATCH] Feature: Allow modders to define custom currencies (!62) https://dev.sp-tarkov.com/SPT-AKI/Issues/issues/11 Co-authored-by: Dev Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/62 --- project/assets/configs/inventory.json | 3 ++- project/src/helpers/PaymentHelper.ts | 17 ++++++++++++++--- .../src/models/spt/config/IInventoryConfig.ts | 4 +++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/project/assets/configs/inventory.json b/project/assets/configs/inventory.json index 578319ca..035ffa3f 100644 --- a/project/assets/configs/inventory.json +++ b/project/assets/configs/inventory.json @@ -18,5 +18,6 @@ "544fb6cc4bdc2d34748b456e": 1 } } - } + }, + "customMoneyTpls": [] } diff --git a/project/src/helpers/PaymentHelper.ts b/project/src/helpers/PaymentHelper.ts index e6475077..3cd12fac 100644 --- a/project/src/helpers/PaymentHelper.ts +++ b/project/src/helpers/PaymentHelper.ts @@ -1,19 +1,30 @@ -import { injectable } from "tsyringe"; +import { inject, injectable } from "tsyringe"; +import { ConfigTypes } from "../models/enums/ConfigTypes"; import { Money } from "../models/enums/Money"; +import { IInventoryConfig } from "../models/spt/config/IInventoryConfig"; +import { ConfigServer } from "../servers/ConfigServer"; @injectable() export class PaymentHelper { + protected inventoryConfig: IInventoryConfig; + + constructor( + @inject("ConfigServer") protected configServer: ConfigServer + ) + { + this.inventoryConfig = this.configServer.getConfig(ConfigTypes.INVENTORY); + } /** - * Check whether tpl is Money + * Is the passed in tpl money (also checks custom currencies in inventoryConfig.customMoneyTpls) * @param {string} tpl * @returns void */ public isMoneyTpl(tpl: string): boolean { - return [Money.DOLLARS, Money.EUROS, Money.ROUBLES].some(element => element === tpl); + return [Money.DOLLARS, Money.EUROS, Money.ROUBLES, ...this.inventoryConfig.customMoneyTpls].some(element => element === tpl); } /** diff --git a/project/src/models/spt/config/IInventoryConfig.ts b/project/src/models/spt/config/IInventoryConfig.ts index ff49c7e3..00157ffe 100644 --- a/project/src/models/spt/config/IInventoryConfig.ts +++ b/project/src/models/spt/config/IInventoryConfig.ts @@ -1,10 +1,12 @@ -import { IBaseConfig } from "./IBaseConfig" +import { IBaseConfig } from "./IBaseConfig"; export interface IInventoryConfig extends IBaseConfig { kind: "aki-inventory" newItemsMarkedFound: boolean randomLootContainers: Record + /** Contains item tpls that the server should consider money and treat the same as roubles/euros/dollars */ + customMoneyTpls: string[] } export interface RewardDetails