2024-05-21 17:59:04 +00:00
|
|
|
import { WeatherGenerator } from "@spt/generators/WeatherGenerator";
|
2024-09-28 23:00:24 +01:00
|
|
|
import { WeatherHelper } from "@spt/helpers/WeatherHelper";
|
2024-05-21 17:59:04 +00:00
|
|
|
import { IWeatherData } from "@spt/models/eft/weather/IWeatherData";
|
|
|
|
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
|
|
|
|
import { IWeatherConfig } from "@spt/models/spt/config/IWeatherConfig";
|
|
|
|
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
2024-07-05 14:21:30 +01:00
|
|
|
import { IGetLocalWeatherResponseData } from "@spt/models/spt/weather/IGetLocalWeatherResponseData";
|
2024-07-23 11:12:53 -04:00
|
|
|
import { ConfigServer } from "@spt/servers/ConfigServer";
|
2024-07-05 14:21:30 +01:00
|
|
|
import { SeasonalEventService } from "@spt/services/SeasonalEventService";
|
2024-07-23 11:12:53 -04:00
|
|
|
import { inject, injectable } from "tsyringe";
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
@injectable()
|
2024-07-23 11:12:53 -04:00
|
|
|
export class WeatherController {
|
2023-03-03 15:23:46 +00:00
|
|
|
protected weatherConfig: IWeatherConfig;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
@inject("WeatherGenerator") protected weatherGenerator: WeatherGenerator,
|
2024-05-28 14:04:20 +00:00
|
|
|
@inject("PrimaryLogger") protected logger: ILogger,
|
2023-11-15 20:35:05 -05:00
|
|
|
@inject("ConfigServer") protected configServer: ConfigServer,
|
2024-07-05 14:21:30 +01:00
|
|
|
@inject("SeasonalEventService") protected seasonalEventService: SeasonalEventService,
|
2024-09-28 23:00:24 +01:00
|
|
|
@inject("WeatherHelper") protected weatherHelper: WeatherHelper,
|
2024-07-23 11:12:53 -04:00
|
|
|
) {
|
2023-03-03 15:23:46 +00:00
|
|
|
this.weatherConfig = this.configServer.getConfig(ConfigTypes.WEATHER);
|
|
|
|
}
|
|
|
|
|
2023-07-15 14:49:25 +01:00
|
|
|
/** Handle client/weather */
|
2024-07-23 11:12:53 -04:00
|
|
|
public generate(): IWeatherData {
|
2024-05-27 20:06:07 +00:00
|
|
|
let result: IWeatherData = { acceleration: 0, time: "", date: "", weather: undefined, season: 1 }; // defaults, hydrated below
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
result = this.weatherGenerator.calculateGameTime(result);
|
|
|
|
result.weather = this.weatherGenerator.generateWeather();
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current in-raid time (MUST HAVE PLAYER LOGGED INTO CLIENT TO WORK)
|
|
|
|
* @returns Date object
|
|
|
|
*/
|
2024-07-23 11:12:53 -04:00
|
|
|
public getCurrentInRaidTime(): Date {
|
2024-09-28 23:00:24 +01:00
|
|
|
return this.weatherHelper.getInRaidTime();
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
2024-07-05 14:21:30 +01:00
|
|
|
|
2024-10-16 18:36:49 +01:00
|
|
|
public generateLocal(sesssionId: string): IGetLocalWeatherResponseData {
|
2024-07-23 11:12:53 -04:00
|
|
|
const result: IGetLocalWeatherResponseData = {
|
2024-10-16 18:36:49 +01:00
|
|
|
season:
|
|
|
|
this.weatherConfig.overrideSeason !== null
|
|
|
|
? this.weatherConfig.overrideSeason
|
|
|
|
: this.seasonalEventService.getActiveWeatherSeason(),
|
2024-07-23 11:12:53 -04:00
|
|
|
weather: [],
|
|
|
|
};
|
2024-07-05 14:21:30 +01:00
|
|
|
|
|
|
|
result.weather.push(this.weatherGenerator.generateWeather());
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2023-11-15 20:35:05 -05:00
|
|
|
}
|