commit 73eca5c27b99a7470abc5c98e39f88d37238e411 Author: Kaeno <> Date: Thu Mar 23 19:46:53 2023 +0000 Initial add of LoosekeyModifier diff --git a/config/config.json b/config/config.json new file mode 100644 index 0000000..24bbf3f --- /dev/null +++ b/config/config.json @@ -0,0 +1,7 @@ +{ + "relativeProbabilityThreshold": 3, + "relativeProbabilitymultiplier": 20, + "lootPileProbability": 0.10 +} + + diff --git a/mod.code-workspace b/mod.code-workspace new file mode 100644 index 0000000..6732c67 --- /dev/null +++ b/mod.code-workspace @@ -0,0 +1,12 @@ +{ + "folders": [ + { + "path": "." + } + ], + "extensions": { + "recommendations": [ + "dbaeumer.vscode-eslint" + ] + } +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..da5aaf8 --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "LooseKeyModifier", + "version": "1.0.0", + "main": "src/mod.js", + "license": "See License file", + "author": "Kaeno", + "akiVersion": "3.5.*", + + "devDependencies": { + "@types/node": "16.18.10", + "@typescript-eslint/eslint-plugin": "5.46.1", + "@typescript-eslint/parser": "5.46.1", + "bestzip": "2.2.1", + "eslint": "8.30.0", + "fs-extra": "11.1.0", + "glob": "8.0.3", + "tsyringe": "4.7.0", + "typescript": "4.9.4" + } +} diff --git a/src/mod.ts b/src/mod.ts new file mode 100644 index 0000000..01df905 --- /dev/null +++ b/src/mod.ts @@ -0,0 +1,63 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { ItemHelper } from "@spt-aki/helpers/ItemHelper"; +import { Spawnpoint } from "@spt-aki/models/eft/common/ILooseLoot"; +import { BaseClasses } from "@spt-aki/models/enums/BaseClasses"; +import type { IPostDBLoadMod } from "@spt-aki/models/external/IPostDBLoadMod"; +import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; +import { DatabaseServer } from "@spt-aki/servers/DatabaseServer"; +import { DependencyContainer } from "tsyringe"; + + +// eslint-disable-next-line @typescript-eslint/no-var-requires +const Config = require("../config/config.json"); + +class Lkm implements IPostDBLoadMod +{ + // Code added here will load BEFORE the server has started loading + public postDBLoad(container: DependencyContainer): void + { + // get the logger from the server container + const DatabaseServer: DatabaseServer = container.resolve("DatabaseServer"); + const logger = container.resolve("WinstonLogger"); + const itemHelper = container.resolve("ItemHelper"); + const database = DatabaseServer.getTables(); + const locations = database.locations; + + for (const mapId in locations) + { + const spawnPoints: Spawnpoint[] = locations[mapId]?.looseLoot?.spawnpoints; + if (!spawnPoints) + { + continue; + } + for (const spawnPoint of spawnPoints) + { + for (const item of spawnPoint.template.Items) + { + if (itemHelper.isOfBaseclass(item._tpl, BaseClasses.KEY)) + { + const matchingItem = spawnPoint.itemDistribution.find(x => x.composedKey.key === item._id); + if (matchingItem) + { + if (spawnPoint.probability < Config.lootPileProbability) + { + spawnPoint.probability = Config.lootPileProbability; + //logger.debug(`Updated Spawnpoint Probability having new probability of ${spawnPoint.probability} on loot pile ${spawnPoint.template.Id} on map ${mapId}`); + + } + if (matchingItem.relativeProbability < Config.relativeProbabilityThreshold) + { + matchingItem.relativeProbability *= Config.relativeProbabilitymultiplier; + //logger.debug(`Updated ${item._tpl} having new relativeProbability of ${matchingItem.relativeProbability} on loot pile ${spawnPoint.template.Id} on map ${mapId}`); + } + + } + } + } + } + } + logger.debug("Altering Probabilities Complete. Lkm"); + } +} + +module.exports = { mod: new Lkm() }; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..8151310 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "allowJs": true, + "module": "CommonJS", + "target": "es2020", + "moduleResolution": "node", + "esModuleInterop": true, + "downlevelIteration": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "resolveJsonModule": true, + "outDir": "tmp", + "baseUrl": ".", + "paths": { + "@spt-aki/*": ["./types/*"] + } + }, + "lib": [ + "es2020" + ], + "include": [ + "src/*", + "src/**/*" + ] +} \ No newline at end of file