Updated getRaidTemperature() to take into account the current raid time when choosing temps

This commit is contained in:
Dev 2024-10-17 13:19:35 +01:00
parent 0b729fba11
commit 953acb47a0
4 changed files with 78 additions and 37 deletions

View File

@ -1,7 +1,7 @@
{ {
"acceleration": 7, "acceleration": 7,
"weather": { "weather": {
"generateWeatherAmountHours": 24, "generateWeatherAmountHours": 24,
"clouds": { "clouds": {
"values": [-1, 0, 0.5, 1, 1.5], "values": [-1, 0, 0.5, 1, 1.5],
"weights": [100, 15, 5, 4, 3] "weights": [100, 15, 5, 4, 3]
@ -31,78 +31,102 @@
"weights": [25, 8, 5, 5, 1] "weights": [25, 8, 5, 5, 1]
}, },
"temp": { "temp": {
"0": { "0": {
"min": 17, "day": {
"max": 32 "min": 17,
}, "max": 32
},
"night": {
"min": 14,
"max": 24
}
},
"1": { "1": {
"min": 7, "day": {
"max": 15 "min": 7,
}, "max": 15
},
"night": {
"min": 2,
"max": 12
}
},
"2": { "2": {
"min": -10, "day": {
"max": 5 "min": -10,
}, "max": 5
},
"night": {
"min": -20,
"max": 0
}
},
"3": { "3": {
"min": 1, "day": {
"max": 15 "min": 1,
}, "max": 15
},
"night": {
"min": -10,
"max": 5
}
},
"4": { "4": {
"min": 0, "day": {
"max": 24 "min": 0,
} "max": 24
},
"night": {
"min": -10,
"max": 8
}
}
}, },
"pressure": { "pressure": {
"min": 760, "min": 760,
"max": 780 "max": 780
}, },
"timePeriod": { "timePeriod": {
"values": [15, 30], "values": [15, 30],
"weights": [1, 2] "weights": [1, 2]
} }
}, },
"seasonDates": [ "seasonDates": [{
{
"seasonType": 0, "seasonType": 0,
"name": "SUMMER", "name": "SUMMER",
"startDay": "2", "startDay": "2",
"startMonth": "6", "startMonth": "6",
"endDay": "15", "endDay": "15",
"endMonth": "10" "endMonth": "10"
}, }, {
{
"seasonType": 1, "seasonType": 1,
"name": "AUTUMN", "name": "AUTUMN",
"startDay": "15", "startDay": "15",
"startMonth": "10", "startMonth": "10",
"endDay": "1", "endDay": "1",
"endMonth": "11" "endMonth": "11"
}, }, {
{
"seasonType": 2, "seasonType": 2,
"name": "WINTER_END", "name": "WINTER_END",
"startDay": "1", "startDay": "1",
"startMonth": "11", "startMonth": "11",
"endDay": "31", "endDay": "31",
"endMonth": "12" "endMonth": "12"
}, }, {
{
"seasonType": 2, "seasonType": 2,
"name": "WINTER_START", "name": "WINTER_START",
"startDay": "1", "startDay": "1",
"startMonth": "1", "startMonth": "1",
"endDay": "24", "endDay": "24",
"endMonth": "3" "endMonth": "3"
}, }, {
{
"seasonType": 3, "seasonType": 3,
"name": "SPRING", "name": "SPRING",
"startDay": "25", "startDay": "25",
"startMonth": "3", "startMonth": "3",
"endDay": "2", "endDay": "2",
"endMonth": "6" "endMonth": "6"
}, }, {
{
"seasonType": 4, "seasonType": 4,
"name": "STORM", "name": "STORM",
"startDay": "24", "startDay": "24",

View File

@ -96,21 +96,31 @@ export class WeatherGenerator {
time: "", time: "",
date: "", date: "",
timestamp: 0, // Added below timestamp: 0, // Added below
sptInRaidTimestamp: 0, // Added below
}; };
this.setCurrentDateTime(result, timestamp); this.setCurrentDateTime(result, timestamp);
result.temp = this.getRaidTemperature(currentSeason, result.time); result.temp = this.getRaidTemperature(currentSeason, result.sptInRaidTimestamp);
return result; return result;
} }
protected getRaidTemperature(currentSeason: Season, currentTimeBsgFormatted: string): number { protected getRaidTemperature(currentSeason: Season, inRaidTimestamp: number): number {
// TODO, take into account time of day // Convert timestamp to date so we can get current hour and check if its day or night
const minMax = this.weatherConfig.weather.temp[currentSeason]; 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)); 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 * Set IWeather date/time/timestamp values to now
* @param weather Object to update * @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.timestamp = Math.floor(timestamp ? timestamp : inRaidTime.getTime() / 1000); // matches weather.date
weather.date = formattedDate; // matches weather.timestamp weather.date = formattedDate; // matches weather.timestamp
weather.time = datetimeBsgFormat; // matches weather.timestamp weather.time = datetimeBsgFormat; // matches weather.timestamp
weather.sptInRaidTimestamp = inRaidTime.getTime();
} }
protected getWeightedWindDirection(): WindDirection { protected getWeightedWindDirection(): WindDirection {

View File

@ -24,4 +24,5 @@ export interface IWeather {
time: string; time: string;
date: string; date: string;
timestamp: number; timestamp: number;
sptInRaidTimestamp: number;
} }

View File

@ -30,12 +30,17 @@ export interface IWeatherValues {
rain: WeatherSettings<number>; rain: WeatherSettings<number>;
rainIntensity: MinMax; rainIntensity: MinMax;
fog: WeatherSettings<string>; fog: WeatherSettings<string>;
temp: Record<Season, MinMax>; temp: Record<Season, ITempDayNight>;
pressure: MinMax; pressure: MinMax;
/** Length of each weather period */ /** Length of each weather period */
timePeriod: WeatherSettings<number>; timePeriod: WeatherSettings<number>;
} }
export interface ITempDayNight {
day: MinMax;
night: MinMax;
}
export interface WeatherSettings<T> { export interface WeatherSettings<T> {
values: T[]; values: T[];
weights: number[]; weights: number[];