From feee6ccf91d269d0e89d330c41d48e36fd335e18 Mon Sep 17 00:00:00 2001 From: CWX Date: Mon, 13 Jan 2025 21:58:02 +0000 Subject: [PATCH] implement weather helper --- Core/Helpers/WeatherHelper.cs | 48 ++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/Core/Helpers/WeatherHelper.cs b/Core/Helpers/WeatherHelper.cs index e93a6b37..9912a883 100644 --- a/Core/Helpers/WeatherHelper.cs +++ b/Core/Helpers/WeatherHelper.cs @@ -1,15 +1,35 @@ using Core.Annotations; +using Core.Models.Enums; +using Core.Models.Spt.Config; +using Core.Servers; +using Core.Utils; +using ILogger = Core.Models.Utils.ILogger; namespace Core.Helpers; [Injectable] public class WeatherHelper { - public WeatherHelper() + private readonly ILogger _logger; + private readonly TimeUtil _timeUtil; + private readonly ConfigServer _configServer; + + private readonly WeatherConfig _weatherConfig; + + public WeatherHelper + ( + ILogger logger, + TimeUtil timeUtil, + ConfigServer configServer + ) { - + _logger = logger; + _timeUtil = timeUtil; + _configServer = configServer; + + _weatherConfig = _configServer.GetConfig(ConfigTypes.WEATHER); } - + /// /// Get the current in-raid time - does not include an accurate date, only time /// @@ -17,7 +37,14 @@ public class WeatherHelper /// Date object of current in-raid time public DateTime GetInRaidTime(double? timestamp = null) { - throw new NotImplementedException(); + // tarkov time = (real time * 7 % 24 hr) + 3 hour + var russiaOffsetMilliseconds = _timeUtil.GetHoursAsSeconds(3) * 1000; + var twentyFourHoursMilliseconds = _timeUtil.GetHoursAsSeconds(24) * 1000; + var currentTimestampMilliSeconds = (timestamp is not null) ? timestamp : _timeUtil.GetTimeStamp(); + + return new DateTime().AddMilliseconds( + (russiaOffsetMilliseconds + russiaOffsetMilliseconds * _weatherConfig.Acceleration) % + twentyFourHoursMilliseconds); } /// @@ -25,13 +52,20 @@ public class WeatherHelper /// /// PASS OR CURR (from raid settings) /// True when nighttime - public bool IsNightTime(DateTime timeVariant) + public bool IsNightTime(DateTimeEnum timeVariant) { - throw new NotImplementedException(); + var time = GetInRaidTime(); + + // getInRaidTime() provides left side value, if player chose right side, set ahead 12 hrs + if (timeVariant == DateTimeEnum.PAST) + time.AddHours(12); + + // Night if after 9pm or before 5am + return time.Hour > 21 || time.Hour < 5; } public bool IsHourAtNightTime(int currentHour) { - throw new NotImplementedException(); + return currentHour > 21 || currentHour <= 5; } }