mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 03:10:45 -05:00
Updated ScavRaidChangesUtil with Improved RaidChangesUtil (!39)
Since my half-baked PR containing a new class, `ScavRaidChangesUtil`, was merged, I figured I should flesh it out a little more. I renamed the class as `RaidChangesUtil` and changed its namespace from `ScavMode` to `InRaid`. The main reason is because the information in this class is still applicable for PMC raids, so the class name/namespace should reflect that. I also allow modders to get more information about the changes that were made and relevant raid information for them. I didn't include methods to retrieve changes made to location exits (for train times) because I didn't see much value in spending the time on it right now. I can always add it sometime in the future. The way I manage `HaveChangesBeenApplied` in the new class is a bit lazy, but I didn't think buffering the values was necessary considering the limited applications for this class. Please let me know if you think this should be improved. I'll add a new class in the new namespace for getting current raid-time information in another PR. Co-authored-by: dwesterwick <dwesterwick@yahoo.com> Reviewed-on: SPT-AKI/Modules#39 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:
parent
b85c27c8a8
commit
55d9574e1d
@ -61,8 +61,10 @@ namespace Aki.SinglePlayer.Patches.ScavMode
|
||||
var json = RequestHandler.PostJson("/singleplayer/settings/getRaidTime", Json.Serialize(request));
|
||||
var serverResult = Json.Deserialize<RaidTimeResponse>(json);
|
||||
|
||||
// Capture the changes that will be made to the raid so they can be easily accessed by modders
|
||||
Utils.InRaid.RaidChangesUtil.UpdateRaidChanges(____raidSettings, serverResult);
|
||||
|
||||
// Set new raid time
|
||||
Utils.ScavMode.ScavRaidChangesUtil.SetRaidTimeReduction(____raidSettings.SelectedLocation.EscapeTimeLimit - serverResult.RaidTimeMinutes);
|
||||
____raidSettings.SelectedLocation.EscapeTimeLimit = serverResult.RaidTimeMinutes;
|
||||
|
||||
// Handle survival time changes
|
||||
@ -82,6 +84,9 @@ namespace Aki.SinglePlayer.Patches.ScavMode
|
||||
AdjustMapExits(____raidSettings.SelectedLocation, serverResult.ExitChanges);
|
||||
}
|
||||
|
||||
// Confirm that all raid changes are complete
|
||||
Utils.InRaid.RaidChangesUtil.ConfirmRaidChanges();
|
||||
|
||||
return true; // Do original method
|
||||
}
|
||||
|
||||
|
79
project/Aki.SinglePlayer/Utils/InRaid/RaidChangesUtil.cs
Normal file
79
project/Aki.SinglePlayer/Utils/InRaid/RaidChangesUtil.cs
Normal file
@ -0,0 +1,79 @@
|
||||
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 reduction in the escape time for the current (or most recent) raid, in minutes
|
||||
/// </summary>
|
||||
public static int RaidTimeReductionMinutes { get; private set; } = 0;
|
||||
|
||||
/// <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;
|
||||
|
||||
RaidTimeReductionMinutes = raidSettings.SelectedLocation.EscapeTimeLimit - 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
namespace Aki.SinglePlayer.Utils.ScavMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Allow mods to access changes made to map settings for Scav raids
|
||||
/// </summary>
|
||||
public static class ScavRaidChangesUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// The reduction in the escape time for the most recently loaded map, in minutes
|
||||
/// </summary>
|
||||
public static int RaidTimeReductionMinutes { get; private set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The reduction in the escape time for the most recently loaded map, in seconds
|
||||
/// </summary>
|
||||
public static int RaidTimeReductionSeconds => RaidTimeReductionMinutes * 60;
|
||||
|
||||
/// <summary>
|
||||
/// Updates the most recent raid-time reduction so it can be accessed by mods.
|
||||
///
|
||||
/// This should be internal because mods shouldn't be able to call it.
|
||||
/// </summary>
|
||||
/// <param name="raidTimeReduction">The raid-time reduction applied to the most recent Scav raid, in minutes</param>
|
||||
internal static void SetRaidTimeReduction(int raidTimeReduction)
|
||||
{
|
||||
RaidTimeReductionMinutes = raidTimeReduction;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user