0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:50:43 -05:00
server/project/src/controllers/WeatherController.ts

55 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-03-03 15:23:46 +00:00
import { inject, injectable } from "tsyringe";
import { WeatherGenerator } from "@spt/generators/WeatherGenerator";
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";
import { ConfigServer } from "@spt/servers/ConfigServer";
2024-07-05 14:21:30 +01:00
import { IGetLocalWeatherResponseData } from "@spt/models/spt/weather/IGetLocalWeatherResponseData";
import { SeasonalEventService } from "@spt/services/SeasonalEventService";
2023-03-03 15:23:46 +00:00
@injectable()
export class WeatherController
{
protected weatherConfig: IWeatherConfig;
constructor(
@inject("WeatherGenerator") protected weatherGenerator: WeatherGenerator,
@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,
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 */
2023-03-03 15:23:46 +00:00
public generate(): IWeatherData
{
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
*/
public getCurrentInRaidTime(): Date
{
return this.weatherGenerator.getInRaidTime();
2023-03-03 15:23:46 +00:00
}
2024-07-05 14:21:30 +01:00
public generateLocal(sesssionID: string): IGetLocalWeatherResponseData
{
let result: IGetLocalWeatherResponseData = { season: this.seasonalEventService.getActiveWeatherSeason(), weather: [] };
result.weather.push(this.weatherGenerator.generateWeather());
return result;
}
2023-11-15 20:35:05 -05:00
}