From 61dbc2b1d02e6da98e84d60d26038d1dd26c70bb Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 3 Apr 2024 19:48:45 +0100 Subject: [PATCH] Add season handling --- project/assets/configs/weather.json | 46 ++++++++++++++++++- project/src/generators/WeatherGenerator.ts | 7 +++ .../helpers/Dialogue/SptDialogueChatBot.ts | 2 +- .../src/models/eft/weather/IWeatherData.ts | 4 +- .../src/models/spt/config/IWeatherConfig.ts | 13 +++++- project/src/services/SeasonalEventService.ts | 27 ++++++++++- 6 files changed, 92 insertions(+), 7 deletions(-) diff --git a/project/assets/configs/weather.json b/project/assets/configs/weather.json index 85799bb7..df8ac3de 100644 --- a/project/assets/configs/weather.json +++ b/project/assets/configs/weather.json @@ -1,6 +1,5 @@ { "acceleration": 7, - "forceWinterEvent": false, "weather": { "clouds": { "values": [ @@ -100,5 +99,48 @@ "min": 760, "max": 764 } - } + }, + "seasonDates": [ + { + "seasonType": 0, + "name": "SUMMER", + "startDay": "2", + "startMonth": "5", + "endDay": "1", + "endMonth": "8" + }, + { + "seasonType": 1, + "name": "AUTUMN", + "startDay": "2", + "startMonth": "8", + "endDay": "1", + "endMonth": "11" + }, + { + "seasonType": 2, + "name": "WINTER", + "startDay": "2", + "startMonth": "11", + "endDay": "1", + "endMonth": "3" + }, + { + "seasonType": 3, + "name": "SPRING", + "startDay": "2", + "startMonth": "3", + "endDay": "1", + "endMonth": "5" + }, + { + "seasonType": 4, + "name": "STORM", + "startDay": "24", + "startMonth": "10", + "endDay": "4", + "endMonth": "11" + }, + ], + "overrideSeason": null } \ No newline at end of file diff --git a/project/src/generators/WeatherGenerator.ts b/project/src/generators/WeatherGenerator.ts index 2a708ba9..178aa86c 100644 --- a/project/src/generators/WeatherGenerator.ts +++ b/project/src/generators/WeatherGenerator.ts @@ -5,10 +5,12 @@ import { ContextVariableType } from "@spt-aki/context/ContextVariableType"; import { WeightedRandomHelper } from "@spt-aki/helpers/WeightedRandomHelper"; import { IWeather, IWeatherData } from "@spt-aki/models/eft/weather/IWeatherData"; import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; +import { Season } from "@spt-aki/models/enums/Season"; import { WindDirection } from "@spt-aki/models/enums/WindDirection"; import { IWeatherConfig } from "@spt-aki/models/spt/config/IWeatherConfig"; import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; import { ConfigServer } from "@spt-aki/servers/ConfigServer"; +import { SeasonalEventService } from "@spt-aki/services/SeasonalEventService"; import { RandomUtil } from "@spt-aki/utils/RandomUtil"; import { TimeUtil } from "@spt-aki/utils/TimeUtil"; @@ -26,6 +28,7 @@ export class WeatherGenerator @inject("WinstonLogger") protected logger: ILogger, @inject("RandomUtil") protected randomUtil: RandomUtil, @inject("TimeUtil") protected timeUtil: TimeUtil, + @inject("SeasonalEventService") protected seasonalEventService: SeasonalEventService, @inject("ApplicationContext") protected applicationContext: ApplicationContext, @inject("ConfigServer") protected configServer: ConfigServer, ) @@ -47,6 +50,10 @@ export class WeatherGenerator data.time = this.getBsgFormattedInRaidTime(); data.acceleration = this.weatherConfig.acceleration; + data.season = this.weatherConfig.overrideSeason + ? this.weatherConfig.overrideSeason + : this.seasonalEventService.getActiveWeatherSeason(); + return data; } diff --git a/project/src/helpers/Dialogue/SptDialogueChatBot.ts b/project/src/helpers/Dialogue/SptDialogueChatBot.ts index 5592e520..1f707c90 100644 --- a/project/src/helpers/Dialogue/SptDialogueChatBot.ts +++ b/project/src/helpers/Dialogue/SptDialogueChatBot.ts @@ -154,7 +154,7 @@ export class SptDialogueChatBot implements IDialogueChatBot if (request.text.toLowerCase() === "itsonlysnowalan") { - this.weatherConfig.season = Season.WINTER; + this.weatherConfig.overrideSeason = Season.WINTER; this.mailSendService.sendUserMessageToPlayer( sessionId, diff --git a/project/src/models/eft/weather/IWeatherData.ts b/project/src/models/eft/weather/IWeatherData.ts index ff3b6d73..ea2d3c1f 100644 --- a/project/src/models/eft/weather/IWeatherData.ts +++ b/project/src/models/eft/weather/IWeatherData.ts @@ -6,8 +6,8 @@ export interface IWeatherData acceleration: number; time: string; date: string; - weather?: IWeather; - season?: Season; + weather: IWeather; + season: Season; } export interface IWeather diff --git a/project/src/models/spt/config/IWeatherConfig.ts b/project/src/models/spt/config/IWeatherConfig.ts index e4af2e4d..a818fbb8 100644 --- a/project/src/models/spt/config/IWeatherConfig.ts +++ b/project/src/models/spt/config/IWeatherConfig.ts @@ -8,7 +8,18 @@ export interface IWeatherConfig extends IBaseConfig kind: "aki-weather"; acceleration: number; weather: Weather; - season: Season; + seasonDates: ISeasonDateTimes[]; + overrideSeason?: Season; +} + +export interface ISeasonDateTimes +{ + seasonType: Season; + name: string; + startDay: number; + startMonth: number; + endDay: number; + endMonth: number; } export interface Weather diff --git a/project/src/services/SeasonalEventService.ts b/project/src/services/SeasonalEventService.ts index 399d11ab..8d73cda4 100644 --- a/project/src/services/SeasonalEventService.ts +++ b/project/src/services/SeasonalEventService.ts @@ -259,6 +259,31 @@ export class SeasonalEventService } } + public getActiveWeatherSeason(): Season + { + const currentDate = new Date(); + for (const seasonRange of this.weatherConfig.seasonDates) + { + // Figure out start and end dates to get range of season + const eventStartDate = new Date( + currentDate.getFullYear(), + seasonRange.startMonth - 1, // Month value starts at 0 + seasonRange.startDay, + ); + const eventEndDate = new Date(currentDate.getFullYear(), seasonRange.endMonth - 1, seasonRange.endDay); + + // Does todays date fit inside the above range + if (currentDate >= eventStartDate && currentDate <= eventEndDate) + { + return seasonRange.seasonType; + } + } + + this.logger.warning("Unable to find a season using current date, defaulting to Summer"); + + return Season.SUMMER; + } + /** * Iterate through bots inventory and loot to find and remove christmas items (as defined in SeasonalEventService) * @param botInventory Bots inventory to iterate over @@ -598,6 +623,6 @@ export class SeasonalEventService public enableSnow(): void { - this.weatherConfig.season = Season.WINTER; + this.weatherConfig.overrideSeason = Season.WINTER; } }