Weather refactor (#596)

* First pass at Weather generation refactor

* Moved generation logic around

* Added seasonal variability support

* Expanded weather generation to use DI system and allow easier modding

* Updated weather weight values

Converted records into classes

* Added fallback when generator isn't found

* Fixed colliding lambda

Added method comments

* Cleanup of weather code

* Adjusted `weatherPresetWeight` values

---------

Co-authored-by: Chomp <dev@dev.sp-tarkov.com>
This commit is contained in:
Chomp
2025-09-30 12:23:46 +00:00
committed by GitHub
parent f8b2b52afc
commit 836112dc50
12 changed files with 514 additions and 271 deletions
@@ -1,37 +1,58 @@
using SPTarkov.DI.Annotations;
using SPTarkov.Server.Core.Extensions;
using SPTarkov.Server.Core.Generators;
using SPTarkov.Server.Core.Helpers;
using SPTarkov.Server.Core.Models.Common;
using SPTarkov.Server.Core.Models.Eft.Weather;
using SPTarkov.Server.Core.Models.Enums;
using SPTarkov.Server.Core.Models.Spt.Config;
using SPTarkov.Server.Core.Models.Spt.Weather;
using SPTarkov.Server.Core.Servers;
using SPTarkov.Server.Core.Services;
using SPTarkov.Server.Core.Utils;
using SPTarkov.Server.Core.Utils.Cloners;
namespace SPTarkov.Server.Core.Controllers;
[Injectable]
public class WeatherController(
TimeUtil timeUtil,
WeatherGenerator weatherGenerator,
SeasonalEventService seasonalEventService,
RaidWeatherService raidWeatherService
RaidWeatherService raidWeatherService,
WeatherHelper weatherHelper,
ConfigServer configServer,
ICloner cloner
)
{
protected readonly WeatherConfig WeatherConfig = configServer.GetConfig<WeatherConfig>();
/// <summary>
/// Handle client/weather
/// </summary>
/// <returns>WeatherData</returns>
public WeatherData Generate()
{
var currentSeason = seasonalEventService.GetActiveWeatherSeason();
// Prep object to send to client
var result = new WeatherData
{
Acceleration = 0,
Time = string.Empty,
Date = string.Empty,
Weather = null,
Season = Season.AUTUMN,
Season = currentSeason,
};
weatherGenerator.CalculateGameTime(result);
result.Weather = weatherGenerator.GenerateWeather(result.Season.Value);
// Assign now in a bsg-style formatted string to result object property
result.Date = timeUtil.GetDateTimeNow().FormatToBsgDate();
// Get server uptime seconds multiplied by a multiplier and add to current time as seconds
result.Time = weatherHelper.GetInRaidTime().GetBsgFormattedWeatherTime();
result.Acceleration = WeatherConfig.Acceleration;
var presetWeights = cloner.Clone(weatherGenerator.GetWeatherPresetWeightsBySeason(currentSeason));
result.Weather = weatherGenerator.GenerateWeather(result.Season.Value, ref presetWeights);
return result;
}