Added ability to know if current raid is at nighttime

This commit is contained in:
Dev 2024-09-28 23:00:24 +01:00
parent fa37cb4ea8
commit f5360d0a92
4 changed files with 60 additions and 17 deletions

View File

@ -1,4 +1,5 @@
import { WeatherGenerator } from "@spt/generators/WeatherGenerator";
import { WeatherHelper } from "@spt/helpers/WeatherHelper";
import { IWeatherData } from "@spt/models/eft/weather/IWeatherData";
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
import { IWeatherConfig } from "@spt/models/spt/config/IWeatherConfig";
@ -17,6 +18,7 @@ export class WeatherController {
@inject("PrimaryLogger") protected logger: ILogger,
@inject("ConfigServer") protected configServer: ConfigServer,
@inject("SeasonalEventService") protected seasonalEventService: SeasonalEventService,
@inject("WeatherHelper") protected weatherHelper: WeatherHelper,
) {
this.weatherConfig = this.configServer.getConfig(ConfigTypes.WEATHER);
}
@ -36,7 +38,7 @@ export class WeatherController {
* @returns Date object
*/
public getCurrentInRaidTime(): Date {
return this.weatherGenerator.getInRaidTime();
return this.weatherHelper.getInRaidTime();
}
public generateLocal(sesssionID: string): IGetLocalWeatherResponseData {

View File

@ -123,6 +123,7 @@ import { TradeHelper } from "@spt/helpers/TradeHelper";
import { TraderAssortHelper } from "@spt/helpers/TraderAssortHelper";
import { TraderHelper } from "@spt/helpers/TraderHelper";
import { UtilityHelper } from "@spt/helpers/UtilityHelper";
import { WeatherHelper } from "@spt/helpers/WeatherHelper";
import { WeightedRandomHelper } from "@spt/helpers/WeightedRandomHelper";
import { BundleLoader } from "@spt/loaders/BundleLoader";
import { ModLoadOrder } from "@spt/loaders/ModLoadOrder";
@ -617,6 +618,7 @@ export class Container {
depContainer.register<NotificationSendHelper>("NotificationSendHelper", { useClass: NotificationSendHelper });
depContainer.register<SecureContainerHelper>("SecureContainerHelper", { useClass: SecureContainerHelper });
depContainer.register<ProbabilityHelper>("ProbabilityHelper", { useClass: ProbabilityHelper });
depContainer.register<WeatherHelper>("WeatherHelper", { useClass: WeatherHelper });
depContainer.register<BotWeaponGeneratorHelper>("BotWeaponGeneratorHelper", {
useClass: BotWeaponGeneratorHelper,
});

View File

@ -1,4 +1,5 @@
import { ApplicationContext } from "@spt/context/ApplicationContext";
import { WeatherHelper } from "@spt/helpers/WeatherHelper";
import { WeightedRandomHelper } from "@spt/helpers/WeightedRandomHelper";
import { IWeather, IWeatherData } from "@spt/models/eft/weather/IWeatherData";
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
@ -21,6 +22,7 @@ export class WeatherGenerator {
constructor(
@inject("WeightedRandomHelper") protected weightedRandomHelper: WeightedRandomHelper,
@inject("WeatherHelper") protected weatherHelper: WeatherHelper,
@inject("PrimaryLogger") protected logger: ILogger,
@inject("RandomUtil") protected randomUtil: RandomUtil,
@inject("TimeUtil") protected timeUtil: TimeUtil,
@ -58,25 +60,11 @@ export class WeatherGenerator {
* @returns formatted time
*/
protected getBsgFormattedInRaidTime(): string {
const clientAcceleratedDate = this.getInRaidTime();
const clientAcceleratedDate = this.weatherHelper.getInRaidTime();
return this.getBSGFormattedTime(clientAcceleratedDate);
}
/**
* Get the current in-raid time
* @param currentDate (new Date())
* @returns Date object of current in-raid time
*/
public getInRaidTime(): Date {
// tarkov time = (real time * 7 % 24 hr) + 3 hour
const russiaOffset = this.timeUtil.getHoursAsSeconds(3) * 1000;
return new Date(
(russiaOffset + new Date().getTime() * this.weatherConfig.acceleration) %
(this.timeUtil.getHoursAsSeconds(24) * 1000),
);
}
/**
* Get current time formatted to fit BSGs requirement
* @param date date to format into bsg style
@ -118,7 +106,7 @@ export class WeatherGenerator {
* @param weather Object to update
*/
protected setCurrentDateTime(weather: IWeather): void {
const currentDate = this.getInRaidTime();
const currentDate = this.weatherHelper.getInRaidTime();
const normalTime = this.getBSGFormattedTime(currentDate);
const formattedDate = this.timeUtil.formatDate(currentDate);
const datetime = `${formattedDate} ${normalTime}`;

View File

@ -0,0 +1,51 @@
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
import { DateTime } from "@spt/models/enums/DateTime";
import { IWeatherConfig } from "@spt/models/spt/config/IWeatherConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { TimeUtil } from "@spt/utils/TimeUtil";
import { inject, injectable } from "tsyringe";
@injectable()
export class WeatherHelper {
protected weatherConfig: IWeatherConfig;
constructor(
@inject("PrimaryLogger") protected logger: ILogger,
@inject("TimeUtil") protected timeUtil: TimeUtil,
@inject("ConfigServer") protected configServer: ConfigServer,
) {
this.weatherConfig = this.configServer.getConfig(ConfigTypes.WEATHER);
}
/**
* Get the current in-raid time
* @param currentDate (new Date())
* @returns Date object of current in-raid time
*/
public getInRaidTime(): Date {
// tarkov time = (real time * 7 % 24 hr) + 3 hour
const russiaOffset = this.timeUtil.getHoursAsSeconds(3) * 1000;
return new Date(
(russiaOffset + new Date().getTime() * this.weatherConfig.acceleration) %
(this.timeUtil.getHoursAsSeconds(24) * 1000),
);
}
/**
* Is the current raid at nighttime
* @param timeVariant PASS OR CURR (from raid settings)
* @returns True when nighttime
*/
public isNightTime(timeVariant: DateTime) {
const time = this.getInRaidTime();
// We get left side value, if player chose right side, set ahead 12 hrs
if (timeVariant === "PAST") {
time.setHours(time.getHours() + 12);
}
// Night if after 9pm or before 5am
return time.getHours() > 21 || time.getHours() < 5;
}
}