-
Notifications
You must be signed in to change notification settings - Fork 1
/
mod.ts
379 lines (331 loc) · 14.8 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
import { DependencyContainer, container } from "tsyringe";
import { IPostDBLoadMod } from "@spt-aki/models/external/IPostDBLoadMod";
import { IPreAkiLoadMod } from "@spt-aki/models/external/IPreAkiLoadMod";
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
import { IBotConfig } from "@spt-aki/models/spt/config/IBotConfig";
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
import * as bosspunisher from "../db/bots/types/bosspunisher.json";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { BossLocationSpawn } from "@spt-aki/models/eft/common/ILocationBase";
import { StaticRouterModService } from "@spt-aki/services/mod/staticRouter/StaticRouterModService";
import * as fs from "fs";
import * as path from "path";
class PunisherBossMod implements IPreAkiLoadMod, IPostDBLoadMod
{
private static readonly spawnChanceDefault = 1;
private static readonly spawnChanceIncrement = .5;
public static sessionID: string;
private static punisherSpawnChance: number;
public static modName = "PunisherChance";
public static databaseServer: DatabaseServer;
public static modFolder = path.dirname(__filename);
public static progressRecord: {
SessionID: string;
successfulConsecutiveRaids: number;
failedConsecutiveRaids: number;
actualPunisherChance: number;
};
mod: string
logger: ILogger;
constructor()
{
this.mod = "PunisherBossMod";
}
public preAkiLoad(container: DependencyContainer): void
{
try
{
const staticRouterModService = container.resolve<StaticRouterModService>("StaticRouterModService");
staticRouterModService.registerStaticRouter(
`${PunisherBossMod.modName}:ProfileSelected`,
[
{
url: "/client/game/profile/select",
action: (url, info, sessionId, output) =>
{
PunisherBossMod.sessionID = sessionId;
return output;
}
}
],
"aki"
);
// Raid Saving (End of raid)
staticRouterModService.registerStaticRouter(
`${PunisherBossMod.modName}:RaidSaved`,
[
{
url: "/raid/profile/save",
action: (url, info, sessionId, output) =>
{
//console.log("Info:", info);
//if (info && info.profile && info.profile.Stats && info.profile.Stats.Victims && info.profile.Stats.Aggressor)
//{
// console.log("Victims:", info.profile.Stats.Victims);
// console.log("Aggressor:", info.profile.Stats.Aggressor);
//}
//else
//{
// console.log("Victims or Aggressor array is not present in the profile.");
//}
PunisherBossMod.onRaidSave(url, info, sessionId, output);
PunisherBossMod.setBossChanceFromProgressFile();
return output;
}
}
],
"aki"
);
}
catch (error)
{
this.logger.error(error);
}
}
public postDBLoad(): void
{
try
{
//console.log("postDBLoad");
const progressFilePath = `${PunisherBossMod.modFolder}/progress.json`;
if (fs.existsSync(progressFilePath))
{
//console.log("Progress file exists, loading...");
PunisherBossMod.progressRecord = PunisherBossMod.readFile(progressFilePath);
if (PunisherBossMod.progressRecord && PunisherBossMod.progressRecord.actualPunisherChance > 100) {
//console.log("Loaded spawn chance exceeds the maximum limit, setting to 100.");
PunisherBossMod.progressRecord.actualPunisherChance = 100;
} else if (PunisherBossMod.progressRecord && PunisherBossMod.progressRecord.actualPunisherChance < 1) {
//console.log("Loaded spawn chance is less than 1, setting to 1.");
PunisherBossMod.progressRecord.actualPunisherChance = 1;
}
// Save the updated progress record to the file
PunisherBossMod.saveToFile(PunisherBossMod.progressRecord, progressFilePath);
//console.log("Progress file updated.");
//console.log("Progress file loaded:", PunisherBossMod.progressRecord);
}
else
{
console.log("Progress file does not exist. This is Normal.");
}
}
catch (error)
{
console.error("An error occurred in postDBLoad:", error);
}
PunisherBossMod.setBossChanceFromProgressFile();
}
static setBossChanceFromProgressFile() {
try {
const progressFilePath = `${PunisherBossMod.modFolder}/progress.json`;
if (!fs.existsSync(progressFilePath)) {
console.log("Progress file does not exist. This is normal.");
return;
}
const progressData = JSON.parse(fs.readFileSync(progressFilePath, "utf8"));
const actualPunisherChance = progressData?.actualPunisherChance ?? 10;
const bosspunisherSpawn = {
BossChance: actualPunisherChance,
BossDifficult: "impossible",
BossEscortAmount: "2",
BossEscortDifficult: "impossible",
BossEscortType: "exUsec",
BossName: "bosspunisher",
BossPlayer: false,
BossZone: "?",
RandomTimeSpawn: false,
Time: -1,
TriggerId: "",
TriggerName: "",
};
console.log("Punisher BossChance:", bosspunisherSpawn.BossChance);
const tables = container.resolve<DatabaseServer>("DatabaseServer").getTables();
const jsonUtil = container.resolve<JsonUtil>("JsonUtil");
const botConfig = container.resolve<ConfigServer>("ConfigServer").getConfig<IBotConfig>(ConfigTypes.BOT);
const batch: any = botConfig.presetBatch;
const stupidfuckingbotsettings = {
"nvgIsActiveChanceDayPercent": 10,
"nvgIsActiveChanceNightPercent": 90,
"faceShieldIsActiveChancePercent": 100,
"lightIsActiveDayChancePercent": 25,
"lightIsActiveNightChancePercent": 90,
"weaponSightWhitelist": {},
"laserIsActiveChancePercent": 85,
"weightingAdjustments": [],
"randomisation": [],
"blacklist": [],
"whitelist": [],
"clothing": [],
"weaponModLimits": {
"scopeLimit": 1,
"lightLaserLimit": 1,
},
};
botConfig.equipment["bosspunisher"] = stupidfuckingbotsettings;
batch.bosspunisher = 1;
botConfig.bosses.push("bosspunisher");
botConfig.itemSpawnLimits["bosspunisher"] = {};
tables.bots.types["bosspunisher"] = jsonUtil.deserialize(jsonUtil.serialize(bosspunisher));
for (const location of Object.values(tables.locations)) {
if (location.base) {
const zones = location.base.Id == "factory4_night" ? tables.locations.factory4_day.base.OpenZones : location.base.OpenZones;
if (zones.length == 0) {
continue;
}
location.base.BossLocationSpawn.push(bosspunisherSpawn);
//console.log(`Added The Punisher to ${location.base.Id}`);
}
}
} catch (error) {
if (error.code === "ENOENT") {
console.log("Progress file not present. This is Normal.");
} else {
console.error("An error occurred in setBossChanceFromProgressFile:", error);
}
}
}
private static saveToFile(data: any, filePath: string): void
{
try
{
fs.writeFileSync(filePath, JSON.stringify(data, null, 4));
//console.log("Data written successfully!");
}
catch (error)
{
console.error("Error writing data: " + error);
}
//console.log("Saved File: " + filePath);
}
public static createProgressFile(
successful: number,
failed: number,
sessionID: string,
punisherSpawnChance: number
): void
{
const progressFile = PunisherBossMod.progressRecord = {
SessionID: sessionID,
successfulConsecutiveRaids: successful,
failedConsecutiveRaids: failed,
actualPunisherChance: punisherSpawnChance
};
PunisherBossMod.saveToFile(progressFile, `${PunisherBossMod.modFolder}/progress.json`);
PunisherBossMod.progressRecord = progressFile;
}
static readFile(filePath: string): any
{
try
{
const jsonString = fs.readFileSync(filePath, "utf-8");
const decryptedData = JSON.parse(jsonString);
return decryptedData;
}
catch (err)
{
console.log(`No file exists at: ${filePath}. This is Normal`);
return null;
}
}
static onRaidSave(url: string, info: any, sessionId: string, output: string)
{
try
{
//console.log("onRaidSave");
// try read values from progress record and if not, set them to default
let successfulConsecutiveRaids = 0;
let failedConsecutiveRaids = 0;
let punisherSpawnChance = 5;
if (!PunisherBossMod.progressRecord)
{
console.log("Progress file not found, creating new file");
PunisherBossMod.createProgressFile(0, 0, sessionId, 5);
PunisherBossMod.progressRecord = PunisherBossMod.readFile(
`${PunisherBossMod.modFolder}/progress.json`
);
//console.log("After progress file creation:", PunisherBossMod.progressRecord);
}
else
{
successfulConsecutiveRaids = PunisherBossMod.progressRecord.successfulConsecutiveRaids;
failedConsecutiveRaids = PunisherBossMod.progressRecord.failedConsecutiveRaids;
punisherSpawnChance = PunisherBossMod.progressRecord.actualPunisherChance;
//console.log("After progress file read:", successfulConsecutiveRaids, failedConsecutiveRaids, punisherSpawnChance);
}
if (PunisherBossMod.progressRecord && info.exit === "survived")
{
successfulConsecutiveRaids++;
failedConsecutiveRaids = 0;
punisherSpawnChance += (PunisherBossMod.spawnChanceIncrement * successfulConsecutiveRaids);
//console.log("You survived the raid! But someone noticed you leaving...");
}
else if (PunisherBossMod.progressRecord && info.exit === "killed")
{
failedConsecutiveRaids++;
successfulConsecutiveRaids = 0;
punisherSpawnChance -= (PunisherBossMod.spawnChanceIncrement * failedConsecutiveRaids);
//console.log("You didn't make it to extract. Shit luck.");
}
else if (PunisherBossMod.progressRecord && info.exit === "runner")
{
punisherSpawnChance += PunisherBossMod.spawnChanceIncrement;
//console.log("Runner Status. Your raid was not counted.");
}
const victimRoles = info.profile.Stats.Victims?.map(victim => victim.Role.toLowerCase());
const aggressorName = info.profile.Stats.Aggressor?.Name?.toLowerCase();
if (victimRoles?.includes("bosspunisher"))
{
punisherSpawnChance /= 4; // Reduce spawn chance by 1/4
//console.log("You gatted the Punisher down! He's going to need some time to heal, but he'll be back soon...");
}
else
{
//console.log("couldn't find bosspunisher in victims");
}
if (victimRoles?.includes("exusec"))
{
const exusecVictims = victimRoles.filter(role => role === "exusec");
const exusecCount = exusecVictims.length;
punisherSpawnChance += PunisherBossMod.spawnChanceIncrement * exusecCount;
//console.log(`The more Rogues you kill, the more you're gonna piss off Frank... Killed ${exusecCount} exusec.`);
}
else
{
//console.log("couldn't find exusec in victims");
}
if (aggressorName === "frank castle")
{
punisherSpawnChance = PunisherBossMod.spawnChanceDefault;
//console.log("The Punisher always gets his vengeance. You'll be safe for a while, but if you keep pissing Frank off he'll be back.");
}
else
{
//console.log("couldn't find frank castle in aggressor");
}
if (punisherSpawnChance > 100)
{
punisherSpawnChance = 100; // Set the spawn chance to the maximum limit
}
if (punisherSpawnChance < 1)
{
punisherSpawnChance = 1; // Set the spawn chance to the minimum limit
}
if (PunisherBossMod.progressRecord)
{
//console.log(`Updated progress file {SuccessfulConsecutiveRaids: ${successfulConsecutiveRaids}, FailedConsecutiveRaids: ${failedConsecutiveRaids}, actualPunisherChance: ${punisherSpawnChance}}`);
PunisherBossMod.createProgressFile(successfulConsecutiveRaids, failedConsecutiveRaids, sessionId, punisherSpawnChance);
//console.log("ProgressFile created successfully!");
}
return output;
}
catch (error)
{
console.error("An error occurred in onRaidSave:", error);
return output;
}
}
// The Punisher \\
}
module.exports = { mod: new PunisherBossMod() }