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

@ -32,24 +32,54 @@
},
"temp": {
"0": {
"day": {
"min": 17,
"max": 32
},
"night": {
"min": 14,
"max": 24
}
},
"1": {
"day": {
"min": 7,
"max": 15
},
"night": {
"min": 2,
"max": 12
}
},
"2": {
"day": {
"min": -10,
"max": 5
},
"night": {
"min": -20,
"max": 0
}
},
"3": {
"day": {
"min": 1,
"max": 15
},
"night": {
"min": -10,
"max": 5
}
},
"4": {
"day": {
"min": 0,
"max": 24
},
"night": {
"min": -10,
"max": 8
}
}
},
"pressure": {
@ -61,48 +91,42 @@
"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",

View File

@ -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 {

View File

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

View File

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