Skip to content

Commit b969376

Browse files
committed
Adds option to override scav raid times
1 parent 6808ee1 commit b969376

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

config/config.json5

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
streets: 50,
4949
woods: 40,
5050
},
51+
52+
// Override scav raid times?
53+
overrideScav: true,
5154
},
5255

5356
trainSchedule: {

src/CustomRaidTimes.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import type { IPreSptLoadMod } from "@spt/models/external/IPreSptLoadMod";
33
import type { ILogger } from "@spt/models/spt/utils/ILogger";
44
import type { StaticRouterModService } from "@spt/services/mod/staticRouter/StaticRouterModService";
55
import { DependencyContainer } from "tsyringe";
6+
import { RaidTimeAdjustmentService } from "@spt/services/RaidTimeAdjustmentService";
7+
import { IGetRaidTimeRequest } from "@spt/models/eft/game/IGetRaidTimeRequest";
8+
import { IGetRaidTimeResponse } from "@spt/models/eft/game/IGetRaidTimeResponse";
69
import { LocationProcessor } from "./processors/LocationProcessor";
710
import { RaidTimeProcessor } from "./processors/RaidTimeProcessor";
811
import { ConfigServer } from "./servers/ConfigServer";
12+
import { ILocationBase } from "@spt/models/eft/common/ILocationBase";
13+
import { DatabaseService } from "@spt/services/DatabaseService";
914
import type { Configuration } from "./types";
1015

1116
/**
@@ -14,12 +19,14 @@ import type { Configuration } from "./types";
1419
class CustomRaidTimes implements IPostDBLoadMod, IPreSptLoadMod {
1520
private logger: ILogger;
1621
private config: Configuration | null = null;
22+
private container: DependencyContainer;
1723

1824
/**
1925
* Handle loading the configuration file and registering our custom CustomRaidTimesMatchEnd route.
2026
* Runs before the database is loaded.
2127
*/
2228
public preSptLoad(container: DependencyContainer): void {
29+
this.container = container;
2330
this.logger = container.resolve<ILogger>("WinstonLogger");
2431

2532
// Load and validate the configuration file.
@@ -66,6 +73,46 @@ class CustomRaidTimes implements IPostDBLoadMod, IPreSptLoadMod {
6673
],
6774
"CustomRaidTimesMatchEnd"
6875
);
76+
77+
// Register a replacement for the RaidTimeAdjustmentService getRaidAdjustments method if the configuration is
78+
// set to override the scav raid times as well.
79+
if (this.config?.raidTimes?.overrideScav) {
80+
container.afterResolution(
81+
"RaidTimeAdjustmentService",
82+
(_t, result: RaidTimeAdjustmentService) => {
83+
result.getRaidAdjustments = (
84+
sessionId: string,
85+
request: IGetRaidTimeRequest
86+
): IGetRaidTimeResponse => {
87+
return this.getRaidAdjustments(request);
88+
};
89+
},
90+
{ frequency: "Always" }
91+
);
92+
}
93+
}
94+
95+
/**
96+
* Return the same response as the original method, even if you're a scav.
97+
* @override @spt/services/RaidTimeAdjustmentService.getRaidAdjustments
98+
*/
99+
private getRaidAdjustments(request: IGetRaidTimeRequest): IGetRaidTimeResponse {
100+
const databaseService = this.container.resolve<DatabaseService>("DatabaseService");
101+
102+
const globals = databaseService.getGlobals();
103+
const mapBase: ILocationBase = databaseService.getLocation(request.Location.toLowerCase()).base;
104+
const baseEscapeTimeMinutes = mapBase.EscapeTimeLimit;
105+
106+
const result: IGetRaidTimeResponse = {
107+
RaidTimeMinutes: baseEscapeTimeMinutes,
108+
ExitChanges: [],
109+
NewSurviveTimeSeconds: undefined,
110+
OriginalSurvivalTimeSeconds: globals.config.exp.match_end.survived_seconds_requirement,
111+
};
112+
113+
this.logger.log("CustomRaidTimes: The `getRaidAdjustments` override has been triggered.", "cyan");
114+
115+
return result;
69116
}
70117

71118
/**

src/processors/RaidTimeProcessor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export class RaidTimeProcessor {
1515
overrideAll: false,
1616
override: 0,
1717
customTimes: {},
18+
overrideScav: false,
1819
};
1920

2021
/**
@@ -45,6 +46,9 @@ export class RaidTimeProcessor {
4546
);
4647
}
4748

49+
// Copy 'overrideScav' value from the original configuration
50+
this.resolvedRaidTimes.overrideScav = raidTimes.overrideScav;
51+
4852
return this;
4953
}
5054

src/schemas/ConfigSchema.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ export class ConfigSchema {
4040
],
4141
},
4242
},
43+
overrideScav: { type: "boolean" },
4344
},
44-
required: ["overrideAll", "override", "customTimes"],
45+
required: ["overrideAll", "override", "customTimes", "overrideScav"],
4546
},
4647
trainSchedule: {
4748
type: "object",

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface RaidTimes {
1313
overrideAll: boolean;
1414
override: number | TimeSetting[];
1515
customTimes: CustomTimes;
16+
overrideScav: boolean;
1617
}
1718

1819
export interface TimeSetting {

0 commit comments

Comments
 (0)