implement weather helper

This commit is contained in:
CWX
2025-01-13 21:58:02 +00:00
parent 09914d231f
commit feee6ccf91
+41 -7
View File
@@ -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<WeatherConfig>(ConfigTypes.WEATHER);
}
/// <summary>
/// Get the current in-raid time - does not include an accurate date, only time
/// </summary>
@@ -17,7 +37,14 @@ public class WeatherHelper
/// <returns>Date object of current in-raid time</returns>
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);
}
/// <summary>
@@ -25,13 +52,20 @@ public class WeatherHelper
/// </summary>
/// <param name="timeVariant">PASS OR CURR (from raid settings)</param>
/// <returns>True when nighttime</returns>
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;
}
}