using Comfort.Common;
using EFT;
using System;
namespace SPT.SinglePlayer.Utils.InRaid
{
///
/// Allow modders to access information about the current raid time, especially if its reduced for Scav raids
///
public static class RaidTimeUtil
{
///
/// Determines if a raid has loaded by checking if a GameTimer instance has been created for one
///
public static bool HasRaidLoaded()
{
return Singleton.Instance?.GameTimer != null;
}
///
/// Determines if a raid is in-progress by checking if the GameTimer has started
///
public static bool HasRaidStarted()
{
return Singleton.Instance.GameTimer.Started();
}
///
/// Calculates the seconds remaining in the current raid.
/// Please ensure is true, or this will throw an exception.
///
/// Seconds remaining in the raid
/// Thrown if there is no raid in progress
public static float GetRemainingRaidSeconds()
{
if (!HasRaidLoaded())
{
throw new InvalidOperationException("The raid-time remaining can only be calculated when a raid is in-progress");
}
if (!HasRaidStarted())
{
return RaidChangesUtil.NewEscapeTimeSeconds;
}
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).
/// Please ensure is true, or this will throw an exception.
///
/// The fraction of raid-time remaining (0.0 - 1.0) relative to the original escape time for the map
/// Thrown if there is no raid in progress
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();
}
}
}