0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 02:30:44 -05:00

Created RaidTimeUtil class to allow modders to retrieve "real" raid-time information (!40)

Added `RaidTimeUtil` which provides the following public methods:
* `GetRemainingRaidSeconds()`: Get the seconds remaining in the raid
* `GetRaidTimeRemainingFraction()`: Get the fraction of time remaining in the raid (relative to the original escape time for the map)
* `GetElapsedRaidSeconds()`: Get the elapsed seconds in the raid (relative to the original escape time for the map)
* `GetSecondsSinceSpawning()`: Get the elapsed seconds since spawning into the raid

This will allow modders to do things based on raid time, even after changes have been made for Scav raids.

The new class required several properties to be added to the existing `RaidChangesUtil` because apparently I can never stop messing with that class...

Co-authored-by: dwesterwick <dwesterwick@yahoo.com>
Reviewed-on: SPT-AKI/Modules#40
Co-authored-by: DanW <danw@noreply.dev.sp-tarkov.com>
Co-committed-by: DanW <danw@noreply.dev.sp-tarkov.com>
This commit is contained in:
DanW 2023-12-03 15:22:28 +00:00 committed by chomp
parent 30c12fd0ab
commit e2ff77a2b3
2 changed files with 81 additions and 2 deletions

View File

@ -29,10 +29,30 @@ namespace Aki.SinglePlayer.Utils.InRaid
/// </summary>
public static string LocationId { get; private set; } = string.Empty;
/// <summary>
/// The original escape time for the current (or most recent) raid, in minutes
/// </summary>
public static int OriginalEscapeTimeMinutes { get; private set; } = int.MaxValue;
/// <summary>
/// The original escape time for the current (or most recent) raid, in seconds
/// </summary>
public static int OriginalEscapeTimeSeconds => OriginalEscapeTimeMinutes * 60;
/// <summary>
/// The updated escape time for the current (or most recent) raid, in minutes
/// </summary>
public static int NewEscapeTimeMinutes { get; private set; } = int.MaxValue;
/// <summary>
/// The updated escape time for the current (or most recent) raid, in seconds
/// </summary>
public static int NewEscapeTimeSeconds => NewEscapeTimeMinutes * 60;
/// <summary>
/// The reduction in the escape time for the current (or most recent) raid, in minutes
/// </summary>
public static int RaidTimeReductionMinutes { get; private set; } = 0;
public static int RaidTimeReductionMinutes => OriginalEscapeTimeMinutes - NewEscapeTimeMinutes;
/// <summary>
/// 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)

View File

@ -0,0 +1,58 @@
using Comfort.Common;
using EFT;
using System;
namespace Aki.SinglePlayer.Utils.InRaid
{
/// <summary>
/// Allow modders to access information about the current raid time, especially if its reduced for Scav raids
/// </summary>
public static class RaidTimeUtil
{
/// <summary>
/// Calculates the seconds remaining in the current raid
/// </summary>
/// <returns>Seconds remaining in the raid</returns>
/// <exception cref="InvalidOperationException">Thrown if there is no raid in progress</exception>
public static float GetRemainingRaidSeconds()
{
if (!Singleton<AbstractGame>.Instance.GameTimer.Started())
{
throw new InvalidOperationException("The raid-time remaining can only be calculated when a raid is in-progress");
}
float remainingTimeSeconds = Singleton<AbstractGame>.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);
}
/// <summary>
/// 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).
/// </summary>
/// <returns>The fraction of raid-time remaining (0.0 - 1.0) relative to the original escape time for the map</returns>
public static float GetRaidTimeRemainingFraction()
{
return GetRemainingRaidSeconds() / RaidChangesUtil.OriginalEscapeTimeSeconds;
}
/// <summary>
/// Calculates the seconds since the player spawned into the raid
/// </summary>
/// <returns>Seconds since the player spawned into the raid</returns>
public static float GetSecondsSinceSpawning()
{
return Singleton<AbstractGame>.Instance.GameTimer.PastTimeSeconds();
}
/// <summary>
/// Calculates the elapsed seconds in the raid from the original escape time for the map.
/// </summary>
/// <returns>Elapsed seconds in the raid</returns>
public static float GetElapsedRaidSeconds()
{
return RaidChangesUtil.RaidTimeReductionSeconds + GetSecondsSinceSpawning();
}
}
}