From c302aeef2f40c228fa17cab715b1cd2e22364a22 Mon Sep 17 00:00:00 2001 From: Baptiste Boulongne Date: Tue, 16 Jul 2024 12:09:03 +0200 Subject: [PATCH] add instant return feature --- README.md | 11 +++-- config/config.json5 | 25 ++++++----- src/insurancetweaks.ts | 98 ++++++++++++++++++++++++++++++++++++++++++ src/mod.ts | 72 ------------------------------- 4 files changed, 121 insertions(+), 85 deletions(-) create mode 100644 src/insurancetweaks.ts delete mode 100644 src/mod.ts diff --git a/README.md b/README.md index 59717cd..20416fb 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,14 @@ # InsuranceTweaks + A simple mod with little to no configuration to tweak the insurance settings # Config + | Setting | Default Value | Details | -|------------------------------|---------------|--------------------------------------------------------------------| -| PraporMinReturn | 2 | Minimum time (in hours) for Prapor to return your insured items | +| ---------------------------- | ------------- | ------------------------------------------------------------------ | +| InstantReturn | | | +| ├ enabled | false | Whether or not the instant return is enabled | +| └ runIntervalSeconds | 30 | Time (in seconds) between each insurance check | | PraporMaxReturn | 4 | Maximum time (in hours) for Prapor to return your insured items | | PraporMaxStorageTime | 72 | Number of hours Prapor insured items will stay in your inbox | | PraporReturnChancePercent | 50 | Return chance percentage for Prapor insured items | @@ -14,5 +18,6 @@ A simple mod with little to no configuration to tweak the insurance settings | TherapistReturnChancePercent | 75 | Return chance percentage for Therapist insured items | # Thanks + - [chomp](https://dev.sp-tarkov.com/chomp) for the mod examples -- [DJLang](https://github.com/KillerDJLang) for [RaidOverhaul](https://hub.sp-tarkov.com/files/file/1673-raid-overhaul/) giving me the idea to make this mod \ No newline at end of file +- [DJLang](https://github.com/KillerDJLang) for [RaidOverhaul](https://hub.sp-tarkov.com/files/file/1673-raid-overhaul/) giving me the idea to make this mod diff --git a/config/config.json5 b/config/config.json5 index 48c7031..743590a 100644 --- a/config/config.json5 +++ b/config/config.json5 @@ -1,13 +1,18 @@ { - //Prapor - "PraporMinReturn": 2, - "PraporMaxReturn": 4, - "PraporMaxStorageTime": 72, - "PraporReturnChancePercent": 50, + InstantReturn: { + enabled: false, + runIntervalSeconds: 30, + }, + + //Prapor + PraporMinReturn: 2, + PraporMaxReturn: 4, + PraporMaxStorageTime: 72, + PraporReturnChancePercent: 50, //Therapist - "TherapistMinReturn": 1, - "TherapistMaxReturn": 2, - "TherapistMaxStorageTime": 72, - "TherapistReturnChancePercent": 75 -} \ No newline at end of file + TherapistMinReturn: 1, + TherapistMaxReturn: 2, + TherapistMaxStorageTime: 72, + TherapistReturnChancePercent: 75, +} diff --git a/src/insurancetweaks.ts b/src/insurancetweaks.ts new file mode 100644 index 0000000..11df652 --- /dev/null +++ b/src/insurancetweaks.ts @@ -0,0 +1,98 @@ +import * as path from "node:path"; + +import { parse } from "json5"; +import { DependencyContainer } from "tsyringe"; + +import { ConfigTypes } from "@spt/models/enums/ConfigTypes"; +import { IPostDBLoadMod } from "@spt/models/external/IPostDBLoadMod"; +import { IPreSptLoadMod } from "@spt/models/external/IPreSptLoadMod"; +import { IInsuranceConfig } from "@spt/models/spt/config/IInsuranceConfig"; +import { LogTextColor } from "@spt/models/spt/logging/LogTextColor"; +import { IDatabaseTables } from "@spt/models/spt/server/IDatabaseTables"; +import { ILogger } from "@spt/models/spt/utils/ILogger"; +import { ConfigServer } from "@spt/servers/ConfigServer"; +import { DatabaseServer } from "@spt/servers/DatabaseServer"; +import { SaveServer } from "@spt/servers/SaveServer"; +import { VFS } from "@spt/utils/VFS"; + +type ModConfig = { + InstantReturn: { + enabled: boolean; + runIntervalSeconds: number; + }; + + PraporMinReturn: number; + PraporMaxReturn: number; + PraporMaxStorageTime: number; + PraporReturnChancePercent: number; + + TherapistMinReturn: number; + TherapistMaxReturn: number; + TherapistMaxStorageTime: number; + TherapistReturnChancePercent: number; +}; + +class InsuranceTweaks implements IPreSptLoadMod, IPostDBLoadMod { + public logger: ILogger; + public tables: IDatabaseTables; + public modConfig: ModConfig; + public configServer: ConfigServer; + public saveServer: SaveServer; + + public preSptLoad(container: DependencyContainer): void { + this.logger = container.resolve("WinstonLogger"); + const vfs = container.resolve("VFS"); + this.modConfig = parse( + vfs.readFile(path.resolve(__dirname, "../config/config.json5")), + ); + } + + public postDBLoad(container: DependencyContainer): void { + this.tables = container + .resolve("DatabaseServer") + .getTables(); + this.configServer = container.resolve("ConfigServer"); + this.traderTweaks(this.modConfig); + } + + private traderTweaks(modConfig: ModConfig): void { + const traders = this.tables.traders; + const PRAPOR = "54cb50c76803fa8b248b4571"; + const THERAPIST = "54cb57776803fa99248b456e"; + + const insuranceConfig = this.configServer.getConfig( + ConfigTypes.INSURANCE, + ); + + if (!modConfig.InstantReturn.enabled) { + traders[PRAPOR].base.insurance.min_return_hour = + modConfig.PraporMinReturn; + traders[PRAPOR].base.insurance.max_return_hour = + modConfig.PraporMaxReturn; + traders[THERAPIST].base.insurance.min_return_hour = + modConfig.TherapistMinReturn; + traders[THERAPIST].base.insurance.max_return_hour = + modConfig.TherapistMaxReturn; + } else { + insuranceConfig.runIntervalSeconds = + modConfig.InstantReturn.runIntervalSeconds; + insuranceConfig.returnTimeOverrideSeconds = 1; + } + + traders[PRAPOR].base.insurance.max_storage_time = + modConfig.PraporMaxStorageTime; + traders[THERAPIST].base.insurance.max_storage_time = + modConfig.TherapistMaxStorageTime; + insuranceConfig.returnChancePercent[PRAPOR] = + modConfig.PraporReturnChancePercent; + insuranceConfig.returnChancePercent[THERAPIST] = + modConfig.TherapistReturnChancePercent; + + this.logger.logWithColor( + "[InsuranceTweaks] Applied insurance settings", + LogTextColor.GREEN, + ); + } +} + +export const mod = new InsuranceTweaks(); diff --git a/src/mod.ts b/src/mod.ts deleted file mode 100644 index 49b5591..0000000 --- a/src/mod.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { DependencyContainer } from "tsyringe"; -import json5 from "json5"; - -import { IPreSptLoadMod } from "@spt/models/external/IPreSptLoadMod"; -import { ILogger } from "@spt/models/spt/utils/ILogger"; -import { LogTextColor } from "@spt/models/spt/logging/LogTextColor"; -import { IDatabaseTables } from "@spt/models/spt/server/IDatabaseTables"; -import { DatabaseServer } from "@spt/servers/DatabaseServer"; -import { IPostDBLoadMod } from "@spt/models/external/IPostDBLoadMod"; -import { VFS } from "@spt/utils/VFS"; - -import * as path from "node:path"; -import { ConfigServer } from "@spt/servers/ConfigServer"; -import { ConfigTypes } from "@spt/models/enums/ConfigTypes"; -import { IInsuranceConfig } from "@spt/models/spt/config/IInsuranceConfig"; - -type ModConfig = { - PraporMinReturn: number; - PraporMaxReturn: number; - PraporMaxStorageTime: number; - PraporReturnChancePercent: number; - - TherapistMinReturn: number; - TherapistMaxReturn: number; - TherapistMaxStorageTime: number; - TherapistReturnChancePercent: number; -} - -class InsuranceTweaks implements IPreSptLoadMod, IPostDBLoadMod -{ - public logger: ILogger; - public tables: IDatabaseTables; - public modConfig: ModConfig; - public configServer: ConfigServer; - - public preSptLoad(container: DependencyContainer): void - { - this.logger = container.resolve("WinstonLogger"); - const vfs = container.resolve("VFS"); - this.modConfig = json5.parse(vfs.readFile(path.resolve(__dirname, "../config/config.json5"))); - } - - public postDBLoad(container: DependencyContainer): void - { - this.tables = container.resolve("DatabaseServer").getTables(); - this.configServer = container.resolve("ConfigServer"); - this.traderTweaks(this.modConfig); - } - - private traderTweaks(modConfig: ModConfig): void - { - const traders = this.tables.traders; - const PRAPOR = "54cb50c76803fa8b248b4571"; - const THERAPIST = "54cb57776803fa99248b456e"; - const insuranceConfig = this.configServer.getConfig(ConfigTypes.INSURANCE); - - // Prapor - traders[PRAPOR].base.insurance.min_return_hour = modConfig.PraporMinReturn; - traders[PRAPOR].base.insurance.max_return_hour = modConfig.PraporMaxReturn; - traders[PRAPOR].base.insurance.max_storage_time = modConfig.PraporMaxStorageTime; - insuranceConfig.returnChancePercent[PRAPOR] = modConfig.PraporReturnChancePercent; - // Therapist - traders[THERAPIST].base.insurance.min_return_hour = modConfig.TherapistMinReturn; - traders[THERAPIST].base.insurance.max_return_hour = modConfig.TherapistMaxReturn; - traders[THERAPIST].base.insurance.max_storage_time = modConfig.TherapistMaxStorageTime; - insuranceConfig.returnChancePercent[THERAPIST] = modConfig.TherapistReturnChancePercent; - - this.logger.logWithColor("[InsuranceTweaks] Applied insurance settings", LogTextColor.GREEN); - } -} - -export const mod = new InsuranceTweaks();