using SPTarkov.DI.Annotations; using SPTarkov.Server.Core.Models.Enums; using SPTarkov.Server.Core.Models.Spt.Config; using SPTarkov.Server.Core.Models.Utils; using SPTarkov.Server.Core.Servers; using SPTarkov.Server.Core.Utils; namespace SPTarkov.Server.Core.Helpers; [Injectable] public class WeatherHelper(ISptLogger logger, TimeUtil timeUtil, ConfigServer configServer) { protected readonly WeatherConfig WeatherConfig = configServer.GetConfig(); /// /// Assumes current time /// Get the current in-raid time - does not include an accurate date, only time /// /// Date object of current in-raid time public DateTime GetInRaidTime() { return GetInRaidTime(timeUtil.GetTimeStamp()); } /// /// Get the current in-raid time - does not include an accurate date, only time /// /// Fixed timestamp /// Date object of current in-raid time public DateTime GetInRaidTime(long timestamp) { // tarkov time = (real time * 7 % 24 hr) + 3 hour var russiaOffsetSeconds = timeUtil.GetHoursAsSeconds(3); var twentyFourHoursSeconds = timeUtil.GetHoursAsSeconds(24); var currentTimestampSeconds = timestamp; var tarkovTime = timeUtil.GetUtcDateTimeFromTimeStamp( (long)(russiaOffsetSeconds + currentTimestampSeconds * WeatherConfig.Acceleration) % twentyFourHoursSeconds ); return tarkovTime; } /// /// Is the current raid at nighttime /// /// PASS OR CURR (from raid settings) /// map name. E.g. factory4_day /// True when nighttime public bool IsNightTime(DateTimeEnum timeVariant, string mapLocation) { switch (mapLocation) { // Factory differs from other maps, has static times case "factory4_night": return true; case "factory4_day": return false; } var time = GetInRaidTime(); // getInRaidTime() provides left side value, if player chose right side, set ahead 12 hrs if (timeVariant == DateTimeEnum.PAST) { time = time.AddHours(12); } // Night if after 9pm or before 5am return time.Hour is > 21 or < 5; } /// /// Is the provided hour at night, nighttime is after 2100 and before 0600 /// /// Hour to check /// True if nighttime hour public bool IsHourAtNightTime(int currentHour) { return currentHour is > 21 or <= 5; } }