Compare commits

..

5 Commits

14 changed files with 1826 additions and 193 deletions

View File

@ -18,3 +18,7 @@
/package-lock.json /package-lock.json
/tsconfig.json /tsconfig.json
/types /types
/.prettierignore
/.prettierrc.json
/icon.png
/README.md

View File

@ -8,3 +8,4 @@
*.json *.json
*.txt *.txt
*.exe *.exe
*.mjs

View File

@ -1,98 +1,113 @@
{ {
"root": true, "root": true,
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"plugins": [ "plugins": ["@typescript-eslint"],
"@typescript-eslint" "extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:import/recommended",
"plugin:import/typescript"
],
"rules": {
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-unused-vars": 1,
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-namespace": 0,
"@typescript-eslint/func-call-spacing": 2,
"@typescript-eslint/quotes": ["warn", "double"],
"@typescript-eslint/brace-style": ["warn", "1tbs"],
"@typescript-eslint/naming-convention": [
"warn",
{
"selector": "default",
"format": ["camelCase"],
"leadingUnderscore": "allow"
},
{
"selector": "typeLike",
"format": ["PascalCase"]
},
{
"selector": "objectLiteralProperty",
"format": ["PascalCase", "camelCase"],
"leadingUnderscore": "allow"
},
{
"selector": "typeProperty",
"format": ["PascalCase", "camelCase"],
"leadingUnderscore": "allow"
},
{
"selector": "enumMember",
"format": ["UPPER_CASE"]
}
], ],
"extends": [ "@typescript-eslint/indent": ["warn", 2],
"eslint:recommended", "@typescript-eslint/no-unused-expressions": [
"plugin:@typescript-eslint/eslint-recommended", "warn",
"plugin:@typescript-eslint/recommended" {
"allowShortCircuit": false,
"allowTernary": false
}
], ],
"rules": { "@typescript-eslint/keyword-spacing": [
"@typescript-eslint/no-explicit-any": 0, "warn",
"@typescript-eslint/no-unused-vars": 1, {
"@typescript-eslint/no-empty-interface": 0, "before": true,
"@typescript-eslint/no-namespace": 0, "after": true
"@typescript-eslint/comma-dangle": 1, }
"@typescript-eslint/func-call-spacing": 2, ],
"@typescript-eslint/quotes": 1, "@typescript-eslint/explicit-module-boundary-types": [
"@typescript-eslint/brace-style": [ "warn",
"warn", {
"allman" "allowArgumentsExplicitlyTypedAsAny": true
}
],
"sort-imports": [
"error",
{
"ignoreCase": false,
"ignoreDeclarationSort": true, // don"t want to sort import lines, use eslint-plugin-import instead
"ignoreMemberSort": false,
"memberSyntaxSortOrder": ["none", "all", "multiple", "single"],
"allowSeparatedGroups": true
}
],
"import/no-unresolved": "error",
"import/order": [
"error",
{
"groups": [
"builtin",
"external",
"internal",
["sibling", "parent"],
"index",
"unknown"
], ],
"@typescript-eslint/naming-convention": [ "newlines-between": "always",
"warn", "alphabetize": {
{ "order": "asc",
"selector": "default", "caseInsensitive": true
"format": [
"camelCase"
],
"leadingUnderscore": "allow"
},
{
"selector": "typeLike",
"format": [
"PascalCase"
]
},
{
"selector": "objectLiteralProperty",
"format": [
"PascalCase",
"camelCase"
],
"leadingUnderscore": "allow"
},
{
"selector": "typeProperty",
"format": [
"PascalCase",
"camelCase"
],
"leadingUnderscore": "allow"
},
{
"selector": "enumMember",
"format": [
"UPPER_CASE"
]
}
],
"@typescript-eslint/indent": [
"warn",
4
],
"@typescript-eslint/no-unused-expressions": [
"warn",
{
"allowShortCircuit": false,
"allowTernary": false
}
],
"@typescript-eslint/keyword-spacing": [
"warn",
{
"before": true,
"after": true
}
],
"@typescript-eslint/explicit-module-boundary-types": [
"warn",
{
"allowArgumentsExplicitlyTypedAsAny": true
}
]
},
"overrides": [
{
"files": [
"*.mjs",
"*.ts"
],
"env": {
"node": true
}
} }
}
] ]
},
"settings": {
"import/resolver": {
"typescript": {
"project": "./tsconfig.json"
}
}
},
"overrides": [
{
"files": ["*.mjs", "*.ts"],
"env": {
"node": true
}
}
]
} }

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
node_modules/ node_modules/
dist/ dist/
.vscode/

11
.prettierignore Normal file
View File

@ -0,0 +1,11 @@
# Exclude these folders from linting
**/node_modules
/tmp
/dist
/types
# Exclude these filetypes from linting
*.json
*.txt
*.exe
*.mjs

6
.prettierrc.json Normal file
View File

@ -0,0 +1,6 @@
{
"singleQuote": false,
"trailingComma": "all",
"tabWidth": 2,
"semi": true
}

View File

@ -1,10 +1,14 @@
# InsuranceTweaks # InsuranceTweaks
A simple mod with little to no configuration to tweak the insurance settings A simple mod with little to no configuration to tweak the insurance settings
# Config # Config
| Setting | Default Value | Details | | 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 | | 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 | | PraporMaxStorageTime | 72 | Number of hours Prapor insured items will stay in your inbox |
| PraporReturnChancePercent | 50 | Return chance percentage for Prapor insured items | | 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 | | TherapistReturnChancePercent | 75 | Return chance percentage for Therapist insured items |
# Thanks # Thanks
- [chomp](https://dev.sp-tarkov.com/chomp) for the mod examples - [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 - [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

View File

@ -121,7 +121,7 @@ async function main() {
logger.log("info", zipFilePath); logger.log("info", zipFilePath);
// Move the zip file inside of the project directory, within the temporary working directory. // Move the zip file inside of the project directory, within the temporary working directory.
const zipFileInProjectDir = path.join(projectDir, `${projectName}.zip`); const zipFileInProjectDir = path.join(projectDir, `${projectName}-${packageJson.version}.zip`);
await fs.move(zipFilePath, zipFileInProjectDir); await fs.move(zipFilePath, zipFileInProjectDir);
logger.log("success", "Archive successfully moved."); logger.log("success", "Archive successfully moved.");
logger.log("info", zipFileInProjectDir); logger.log("info", zipFileInProjectDir);
@ -134,7 +134,7 @@ async function main() {
logger.log("success", "------------------------------------"); logger.log("success", "------------------------------------");
logger.log("success", "Build script completed successfully!"); logger.log("success", "Build script completed successfully!");
logger.log("success", "Your mod package has been created in the 'dist' directory:"); logger.log("success", "Your mod package has been created in the 'dist' directory:");
logger.log("success", `/${path.relative(process.cwd(), path.join(distDir, `${projectName}.zip`))}`); logger.log("success", `/${path.relative(process.cwd(), path.join(distDir, `${projectName}-${packageJson.version}.zip`))}`);
logger.log("success", "------------------------------------"); logger.log("success", "------------------------------------");
if (!verbose) { if (!verbose) {
logger.log("success", "To see a detailed build log, use `npm run buildinfo`."); logger.log("success", "To see a detailed build log, use `npm run buildinfo`.");

View File

@ -1,13 +1,18 @@
{ {
InstantReturn: {
enabled: false,
runIntervalSeconds: 30,
},
//Prapor //Prapor
"PraporMinReturn": 2, PraporMinReturn: 2,
"PraporMaxReturn": 4, PraporMaxReturn: 4,
"PraporMaxStorageTime": 72, PraporMaxStorageTime: 72,
"PraporReturnChancePercent": 50, PraporReturnChancePercent: 50,
//Therapist //Therapist
"TherapistMinReturn": 1, TherapistMinReturn: 1,
"TherapistMaxReturn": 2, TherapistMaxReturn: 2,
"TherapistMaxStorageTime": 72, TherapistMaxStorageTime: 72,
"TherapistReturnChancePercent": 75 TherapistReturnChancePercent: 75,
} }

View File

@ -1,13 +1,18 @@
{ {
"folders": [ "folders": [
{ {
"path": "." "path": ".",
} },
],
"extensions": {
"recommendations": [
"dbaeumer.vscode-eslint",
"refringe.spt-id-highlighter",
], ],
"extensions": { },
"recommendations": [ "settings": {
"dbaeumer.vscode-eslint", "editor.tabSize": 2,
"refringe.spt-id-highlighter" "editor.defaultFormatter": "esbenp.prettier-vscode",
] "editor.formatOnSave": true,
} },
} }

1553
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,12 @@
{ {
"name": "InsuranceTweaks", "name": "InsuranceTweaks",
"version": "0.0.2", "version": "0.0.3",
"sptVersion": "~3.9", "sptVersion": "~3.9",
"loadBefore": [], "loadBefore": [],
"loadAfter": [], "loadAfter": [],
"incompatibilities": [], "incompatibilities": [],
"isBundleMod": false, "isBundleMod": false,
"main": "src/mod.js", "main": "src/insurancetweaks.js",
"scripts": { "scripts": {
"setup": "npm i", "setup": "npm i",
"build": "node ./build.mjs", "build": "node ./build.mjs",
@ -18,9 +18,14 @@
"@typescript-eslint/parser": "7.2", "@typescript-eslint/parser": "7.2",
"archiver": "^6.0", "archiver": "^6.0",
"eslint": "8.57", "eslint": "8.57",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"fs-extra": "11.2", "fs-extra": "11.2",
"ignore": "^5.2", "ignore": "^5.2",
"json5": "^2.2.3", "json5": "^2.2.3",
"prettier": "^3.3.3",
"tsyringe": "4.8.0", "tsyringe": "4.8.0",
"typescript": "5.4", "typescript": "5.4",
"winston": "3.12" "winston": "3.12"

98
src/insurancetweaks.ts Normal file
View File

@ -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<ILogger>("WinstonLogger");
const vfs = container.resolve<VFS>("VFS");
this.modConfig = parse(
vfs.readFile(path.resolve(__dirname, "../config/config.json5")),
);
}
public postDBLoad(container: DependencyContainer): void {
this.tables = container
.resolve<DatabaseServer>("DatabaseServer")
.getTables();
this.configServer = container.resolve<ConfigServer>("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<IInsuranceConfig>(
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();

View File

@ -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<ILogger>("WinstonLogger");
const vfs = container.resolve<VFS>("VFS");
this.modConfig = json5.parse(vfs.readFile(path.resolve(__dirname, "../config/config.json5")));
}
public postDBLoad(container: DependencyContainer): void
{
this.tables = container.resolve<DatabaseServer>("DatabaseServer").getTables();
this.configServer = container.resolve<ConfigServer>("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<IInsuranceConfig>(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();