diff --git a/project/src/controllers/WeatherController.ts b/project/src/controllers/WeatherController.ts index 0eb464d1..b7d034bc 100644 --- a/project/src/controllers/WeatherController.ts +++ b/project/src/controllers/WeatherController.ts @@ -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 { diff --git a/project/src/di/Container.ts b/project/src/di/Container.ts index 5c4adc04..224ce30b 100644 --- a/project/src/di/Container.ts +++ b/project/src/di/Container.ts @@ -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", { useClass: NotificationSendHelper }); depContainer.register("SecureContainerHelper", { useClass: SecureContainerHelper }); depContainer.register("ProbabilityHelper", { useClass: ProbabilityHelper }); + depContainer.register("WeatherHelper", { useClass: WeatherHelper }); depContainer.register("BotWeaponGeneratorHelper", { useClass: BotWeaponGeneratorHelper, }); diff --git a/project/src/generators/WeatherGenerator.ts b/project/src/generators/WeatherGenerator.ts index 302a633b..0f7c8e3a 100644 --- a/project/src/generators/WeatherGenerator.ts +++ b/project/src/generators/WeatherGenerator.ts @@ -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}`; diff --git a/project/src/helpers/WeatherHelper.ts b/project/src/helpers/WeatherHelper.ts new file mode 100644 index 00000000..5ac2a74d --- /dev/null +++ b/project/src/helpers/WeatherHelper.ts @@ -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; + } +}