diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..24b6d18 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 0xNES + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3341f0c --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# 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 | +| 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 | +| TherapistMinReturn | 1 | Minimum time (in hours) for Therapist to return your insured items | +| TherapistMaxReturn | 2 | Maximum time (in hours) for Therapist to return your insured items | +| TherapistMaxStorageTime | 72 | Number of hours Therapist insured items will stay in your inbox | + +# 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 diff --git a/config/config.json5 b/config/config.json5 new file mode 100644 index 0000000..1db30b5 --- /dev/null +++ b/config/config.json5 @@ -0,0 +1,11 @@ +{ + //Prapor + "PraporMinReturn": 2, + "PraporMaxReturn": 4, + "PraporMaxStorageTime": 72, + + //Therapist + "TherapistMinReturn": 1, + "TherapistMaxReturn": 2, + "TherapistMaxStorageTime": 72 +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 1d88556..56f9e99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "eslint": "8.57", "fs-extra": "11.2", "ignore": "^5.2", + "json5": "^2.2.3", "tsyringe": "4.8.0", "typescript": "5.4", "winston": "3.12" @@ -1386,6 +1387,18 @@ "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, + "node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/jsonfile": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", diff --git a/package.json b/package.json index bf24982..7aac70a 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "eslint": "8.57", "fs-extra": "11.2", "ignore": "^5.2", + "json5": "^2.2.3", "tsyringe": "4.8.0", "typescript": "5.4", "winston": "3.12" diff --git a/src/mod.ts b/src/mod.ts index 4d54e46..170827d 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -1,23 +1,59 @@ 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 { LogBackgroundColor } from "@spt/models/spt/logging/LogBackgroundColor"; +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"; -class Mod implements IPreSptLoadMod +import * as path from "node:path"; + +type ModConfig = { + PraporMinReturn: number, + PraporMaxReturn: number, + PraporMaxStorageTime: number, + TherapistMinReturn: number, + TherapistMaxReturn: number, + TherapistMaxStorageTime: number +} + +class InsuranceTweaks implements IPreSptLoadMod, IPostDBLoadMod { - // Code added here will load BEFORE the server has started loading + public logger: ILogger; + public tables: IDatabaseTables; + public modConfig: ModConfig; + public preSptLoad(container: DependencyContainer): void { - // get the logger from the server container - const logger = container.resolve("WinstonLogger"); + this.logger = container.resolve("WinstonLogger"); + const vfs = container.resolve("VFS"); + this.modConfig = json5.parse(vfs.readFile(path.resolve(__dirname, "../config/config.json5"))); + } - logger.info("I am logging info!"); - logger.warning("I am logging a warning!"); - logger.error("I am logging an error!"); - logger.logWithColor("I am logging with color!", LogTextColor.YELLOW, LogBackgroundColor.RED); + public postDBLoad(container: DependencyContainer): void + { + this.tables = container.resolve("DatabaseServer").getTables(); + this.traderTweaks(this.modConfig); + } + + private traderTweaks(modConfig: ModConfig): void + { + const traders = this.tables.traders; + + // Prapor + traders["54cb50c76803fa8b248b4571"].base.insurance.min_return_hour = modConfig.PraporMinReturn + traders["54cb50c76803fa8b248b4571"].base.insurance.max_return_hour = modConfig.PraporMaxReturn + traders["54cb50c76803fa8b248b4571"].base.insurance.max_storage_time = modConfig.PraporMaxStorageTime + // Therapist + traders["54cb57776803fa99248b456e"].base.insurance.min_return_hour = modConfig.TherapistMinReturn + traders["54cb57776803fa99248b456e"].base.insurance.max_return_hour = modConfig.TherapistMaxReturn + traders["54cb57776803fa99248b456e"].base.insurance.max_storage_time = modConfig.TherapistMaxStorageTime + + this.logger.logWithColor("[InsuranceTweaks] Applied insurance settings", LogTextColor.GREEN); } } -export const mod = new Mod(); +export const mod = new InsuranceTweaks();