0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
DanW e2ff77a2b3 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>
2023-12-03 15:22:28 +00:00

101 lines
4.1 KiB
C#

using Aki.SinglePlayer.Patches.ScavMode;
using EFT;
using System;
namespace Aki.SinglePlayer.Utils.InRaid
{
/// <summary>
/// Allow modders to access changes made to the current (or most recent) raid
/// </summary>
public static class RaidChangesUtil
{
/// <summary>
/// The UTC time when raid changes were last applied
/// </summary>
public static DateTime RaidChangesAppliedUtcTime { get; private set; } = DateTime.MinValue;
/// <summary>
/// If raid changes have been completed
/// </summary>
public static bool HaveChangesBeenApplied => RaidChangesAppliedUtcTime != DateTime.MinValue;
/// <summary>
/// If the most recent raid was a Scav run
/// </summary>
public static bool IsScavRaid { get; private set; } = false;
/// <summary>
/// The location ID of the map for the current (or most recent) raid
/// </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 => OriginalEscapeTimeMinutes - NewEscapeTimeMinutes;
/// <summary>
/// The reduction in the escape time for the current (or most recent) raid, in seconds
/// </summary>
public static int RaidTimeReductionSeconds => RaidTimeReductionMinutes * 60;
/// <summary>
/// The reduction in the minimum time you must stay in the raid to get a "Survived" status (unless your XP is high enough) for the current (or most recent) raid
/// </summary>
public static int SurvivalTimeReductionSeconds { get; private set; } = 0;
/// <summary>
/// Update the changes that will be made for the raid. This should be called just before applying changes.
/// </summary>
/// <param name="raidSettings">The raid settings for the raid that will be altered</param>
/// <param name="raidChanges">The changes that will be made to the raid</param>
internal static void UpdateRaidChanges(RaidSettings raidSettings, RaidTimeResponse raidChanges)
{
// Reset so HaveChangesBeenApplied=false while changes are being applied
RaidChangesAppliedUtcTime = DateTime.MinValue;
IsScavRaid = raidSettings.IsScav;
LocationId = raidSettings.SelectedLocation.Id;
OriginalEscapeTimeMinutes = raidSettings.SelectedLocation.EscapeTimeLimit;
NewEscapeTimeMinutes = raidChanges.RaidTimeMinutes;
SurvivalTimeReductionSeconds = 0;
if (raidChanges.NewSurviveTimeSeconds.HasValue)
{
SurvivalTimeReductionSeconds += raidChanges.OriginalSurvivalTimeSeconds - raidChanges.NewSurviveTimeSeconds.Value;
}
}
/// <summary>
/// This should be called just after all raid changes have been completed
/// </summary>
internal static void ConfirmRaidChanges()
{
// This will also set HaveChangesBeenApplied=true
RaidChangesAppliedUtcTime = DateTime.UtcNow;
}
}
}