From 953acb47a02cfe3455aeb3dc4cb3a8676bcafb0a Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 17 Oct 2024 13:19:35 +0100 Subject: [PATCH] Updated `getRaidTemperature()` to take into account the current raid time when choosing temps --- project/assets/configs/weather.json | 88 ++++++++++++------- project/src/generators/WeatherGenerator.ts | 19 +++- .../src/models/eft/weather/IWeatherData.ts | 1 + .../src/models/spt/config/IWeatherConfig.ts | 7 +- 4 files changed, 78 insertions(+), 37 deletions(-) diff --git a/project/assets/configs/weather.json b/project/assets/configs/weather.json index cdcd957a..a04979a1 100644 --- a/project/assets/configs/weather.json +++ b/project/assets/configs/weather.json @@ -1,7 +1,7 @@ { "acceleration": 7, "weather": { - "generateWeatherAmountHours": 24, + "generateWeatherAmountHours": 24, "clouds": { "values": [-1, 0, 0.5, 1, 1.5], "weights": [100, 15, 5, 4, 3] @@ -31,78 +31,102 @@ "weights": [25, 8, 5, 5, 1] }, "temp": { - "0": { - "min": 17, - "max": 32 - }, + "0": { + "day": { + "min": 17, + "max": 32 + }, + "night": { + "min": 14, + "max": 24 + } + }, "1": { - "min": 7, - "max": 15 - }, + "day": { + "min": 7, + "max": 15 + }, + "night": { + "min": 2, + "max": 12 + } + }, "2": { - "min": -10, - "max": 5 - }, + "day": { + "min": -10, + "max": 5 + }, + "night": { + "min": -20, + "max": 0 + } + }, "3": { - "min": 1, - "max": 15 - }, + "day": { + "min": 1, + "max": 15 + }, + "night": { + "min": -10, + "max": 5 + } + }, "4": { - "min": 0, - "max": 24 - } + "day": { + "min": 0, + "max": 24 + }, + "night": { + "min": -10, + "max": 8 + } + } }, "pressure": { "min": 760, "max": 780 }, - "timePeriod": { - "values": [15, 30], + "timePeriod": { + "values": [15, 30], "weights": [1, 2] - } + } }, - "seasonDates": [ - { + "seasonDates": [{ "seasonType": 0, "name": "SUMMER", "startDay": "2", "startMonth": "6", "endDay": "15", "endMonth": "10" - }, - { + }, { "seasonType": 1, "name": "AUTUMN", "startDay": "15", "startMonth": "10", "endDay": "1", "endMonth": "11" - }, - { + }, { "seasonType": 2, "name": "WINTER_END", "startDay": "1", "startMonth": "11", "endDay": "31", "endMonth": "12" - }, - { + }, { "seasonType": 2, "name": "WINTER_START", "startDay": "1", "startMonth": "1", "endDay": "24", "endMonth": "3" - }, - { + }, { "seasonType": 3, "name": "SPRING", "startDay": "25", "startMonth": "3", "endDay": "2", "endMonth": "6" - }, - { + }, { "seasonType": 4, "name": "STORM", "startDay": "24", diff --git a/project/src/generators/WeatherGenerator.ts b/project/src/generators/WeatherGenerator.ts index a4d61904..e8c83fac 100644 --- a/project/src/generators/WeatherGenerator.ts +++ b/project/src/generators/WeatherGenerator.ts @@ -96,21 +96,31 @@ export class WeatherGenerator { time: "", date: "", timestamp: 0, // Added below + sptInRaidTimestamp: 0, // Added below }; this.setCurrentDateTime(result, timestamp); - result.temp = this.getRaidTemperature(currentSeason, result.time); + result.temp = this.getRaidTemperature(currentSeason, result.sptInRaidTimestamp); return result; } - protected getRaidTemperature(currentSeason: Season, currentTimeBsgFormatted: string): number { - // TODO, take into account time of day - const minMax = this.weatherConfig.weather.temp[currentSeason]; + protected getRaidTemperature(currentSeason: Season, inRaidTimestamp: number): number { + // Convert timestamp to date so we can get current hour and check if its day or night + const currentRaidTime = new Date(inRaidTimestamp); + const seasonDayNightTempValues = this.weatherConfig.weather.temp[currentSeason]; + const minMax = this.isNightTime(currentRaidTime.getHours()) + ? seasonDayNightTempValues.night + : seasonDayNightTempValues.day; + return Number.parseFloat(this.randomUtil.getFloat(minMax.min, minMax.max).toPrecision(2)); } + protected isNightTime(currentHour: number) { + return currentHour > 21 && currentHour <= 5; + } + /** * Set IWeather date/time/timestamp values to now * @param weather Object to update @@ -125,6 +135,7 @@ export class WeatherGenerator { weather.timestamp = Math.floor(timestamp ? timestamp : inRaidTime.getTime() / 1000); // matches weather.date weather.date = formattedDate; // matches weather.timestamp weather.time = datetimeBsgFormat; // matches weather.timestamp + weather.sptInRaidTimestamp = inRaidTime.getTime(); } protected getWeightedWindDirection(): WindDirection { diff --git a/project/src/models/eft/weather/IWeatherData.ts b/project/src/models/eft/weather/IWeatherData.ts index 9e9581e6..f521e2ef 100644 --- a/project/src/models/eft/weather/IWeatherData.ts +++ b/project/src/models/eft/weather/IWeatherData.ts @@ -24,4 +24,5 @@ export interface IWeather { time: string; date: string; timestamp: number; + sptInRaidTimestamp: number; } diff --git a/project/src/models/spt/config/IWeatherConfig.ts b/project/src/models/spt/config/IWeatherConfig.ts index 6dd54af6..9daa8341 100644 --- a/project/src/models/spt/config/IWeatherConfig.ts +++ b/project/src/models/spt/config/IWeatherConfig.ts @@ -30,12 +30,17 @@ export interface IWeatherValues { rain: WeatherSettings; rainIntensity: MinMax; fog: WeatherSettings; - temp: Record; + temp: Record; pressure: MinMax; /** Length of each weather period */ timePeriod: WeatherSettings; } +export interface ITempDayNight { + day: MinMax; + night: MinMax; +} + export interface WeatherSettings { values: T[]; weights: number[];