diff --git a/project/Aki.SinglePlayer/Utils/InRaid/RaidChangesUtil.cs b/project/Aki.SinglePlayer/Utils/InRaid/RaidChangesUtil.cs index a55dc0e..0fb2510 100644 --- a/project/Aki.SinglePlayer/Utils/InRaid/RaidChangesUtil.cs +++ b/project/Aki.SinglePlayer/Utils/InRaid/RaidChangesUtil.cs @@ -29,10 +29,30 @@ namespace Aki.SinglePlayer.Utils.InRaid /// public static string LocationId { get; private set; } = string.Empty; + /// + /// The original escape time for the current (or most recent) raid, in minutes + /// + public static int OriginalEscapeTimeMinutes { get; private set; } = int.MaxValue; + + /// + /// The original escape time for the current (or most recent) raid, in seconds + /// + public static int OriginalEscapeTimeSeconds => OriginalEscapeTimeMinutes * 60; + + /// + /// The updated escape time for the current (or most recent) raid, in minutes + /// + public static int NewEscapeTimeMinutes { get; private set; } = int.MaxValue; + + /// + /// The updated escape time for the current (or most recent) raid, in seconds + /// + public static int NewEscapeTimeSeconds => NewEscapeTimeMinutes * 60; + /// /// The reduction in the escape time for the current (or most recent) raid, in minutes /// - public static int RaidTimeReductionMinutes { get; private set; } = 0; + public static int RaidTimeReductionMinutes => OriginalEscapeTimeMinutes - NewEscapeTimeMinutes; /// /// The reduction in the escape time for the current (or most recent) raid, in seconds @@ -58,7 +78,8 @@ namespace Aki.SinglePlayer.Utils.InRaid LocationId = raidSettings.SelectedLocation.Id; - RaidTimeReductionMinutes = raidSettings.SelectedLocation.EscapeTimeLimit - raidChanges.RaidTimeMinutes; + OriginalEscapeTimeMinutes = raidSettings.SelectedLocation.EscapeTimeLimit; + NewEscapeTimeMinutes = raidChanges.RaidTimeMinutes; SurvivalTimeReductionSeconds = 0; if (raidChanges.NewSurviveTimeSeconds.HasValue) diff --git a/project/Aki.SinglePlayer/Utils/InRaid/RaidTimeUtil.cs b/project/Aki.SinglePlayer/Utils/InRaid/RaidTimeUtil.cs new file mode 100644 index 0000000..2fc54e4 --- /dev/null +++ b/project/Aki.SinglePlayer/Utils/InRaid/RaidTimeUtil.cs @@ -0,0 +1,58 @@ +using Comfort.Common; +using EFT; +using System; + +namespace Aki.SinglePlayer.Utils.InRaid +{ + /// + /// Allow modders to access information about the current raid time, especially if its reduced for Scav raids + /// + public static class RaidTimeUtil + { + /// + /// Calculates the seconds remaining in the current raid + /// + /// Seconds remaining in the raid + /// Thrown if there is no raid in progress + public static float GetRemainingRaidSeconds() + { + if (!Singleton.Instance.GameTimer.Started()) + { + throw new InvalidOperationException("The raid-time remaining can only be calculated when a raid is in-progress"); + } + + float remainingTimeSeconds = Singleton.Instance.GameTimer.EscapeTimeSeconds(); + + // Until the raid starts, remainingTimeSeconds is TimeSpan.MaxValue, so it needs to be reduced to the actual starting raid time + return Math.Min(remainingTimeSeconds, RaidChangesUtil.NewEscapeTimeSeconds); + } + + /// + /// Calculates the fraction of raid-time remaining relative to the original escape time for the map. + /// 1.0 = the raid just started, and 0.0 = the raid is over (and you're MIA). + /// + /// The fraction of raid-time remaining (0.0 - 1.0) relative to the original escape time for the map + public static float GetRaidTimeRemainingFraction() + { + return GetRemainingRaidSeconds() / RaidChangesUtil.OriginalEscapeTimeSeconds; + } + + /// + /// Calculates the seconds since the player spawned into the raid + /// + /// Seconds since the player spawned into the raid + public static float GetSecondsSinceSpawning() + { + return Singleton.Instance.GameTimer.PastTimeSeconds(); + } + + /// + /// Calculates the elapsed seconds in the raid from the original escape time for the map. + /// + /// Elapsed seconds in the raid + public static float GetElapsedRaidSeconds() + { + return RaidChangesUtil.RaidTimeReductionSeconds + GetSecondsSinceSpawning(); + } + } +}