diff --git a/project/Aki.SinglePlayer/Patches/ScavMode/ScavLateStartPatch.cs b/project/Aki.SinglePlayer/Patches/ScavMode/ScavLateStartPatch.cs index 79d9a8d..762bf33 100644 --- a/project/Aki.SinglePlayer/Patches/ScavMode/ScavLateStartPatch.cs +++ b/project/Aki.SinglePlayer/Patches/ScavMode/ScavLateStartPatch.cs @@ -61,8 +61,10 @@ namespace Aki.SinglePlayer.Patches.ScavMode var json = RequestHandler.PostJson("/singleplayer/settings/getRaidTime", Json.Serialize(request)); var serverResult = Json.Deserialize(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 } diff --git a/project/Aki.SinglePlayer/Utils/InRaid/RaidChangesUtil.cs b/project/Aki.SinglePlayer/Utils/InRaid/RaidChangesUtil.cs new file mode 100644 index 0000000..a55dc0e --- /dev/null +++ b/project/Aki.SinglePlayer/Utils/InRaid/RaidChangesUtil.cs @@ -0,0 +1,79 @@ +using Aki.SinglePlayer.Patches.ScavMode; +using EFT; +using System; + +namespace Aki.SinglePlayer.Utils.InRaid +{ + /// + /// Allow modders to access changes made to the current (or most recent) raid + /// + public static class RaidChangesUtil + { + /// + /// The UTC time when raid changes were last applied + /// + public static DateTime RaidChangesAppliedUtcTime { get; private set; } = DateTime.MinValue; + + /// + /// If raid changes have been completed + /// + public static bool HaveChangesBeenApplied => RaidChangesAppliedUtcTime != DateTime.MinValue; + + /// + /// If the most recent raid was a Scav run + /// + public static bool IsScavRaid { get; private set; } = false; + + /// + /// The location ID of the map for the current (or most recent) raid + /// + public static string LocationId { get; private set; } = string.Empty; + + /// + /// The reduction in the escape time for the current (or most recent) raid, in minutes + /// + public static int RaidTimeReductionMinutes { get; private set; } = 0; + + /// + /// The reduction in the escape time for the current (or most recent) raid, in seconds + /// + public static int RaidTimeReductionSeconds => RaidTimeReductionMinutes * 60; + + /// + /// 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 + /// + public static int SurvivalTimeReductionSeconds { get; private set; } = 0; + + /// + /// Update the changes that will be made for the raid. This should be called just before applying changes. + /// + /// The raid settings for the raid that will be altered + /// The changes that will be made to the raid + 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; + } + } + + /// + /// This should be called just after all raid changes have been completed + /// + internal static void ConfirmRaidChanges() + { + // This will also set HaveChangesBeenApplied=true + RaidChangesAppliedUtcTime = DateTime.UtcNow; + } + } +} diff --git a/project/Aki.SinglePlayer/Utils/ScavMode/ScavRaidChangesUtil.cs b/project/Aki.SinglePlayer/Utils/ScavMode/ScavRaidChangesUtil.cs deleted file mode 100644 index 5bc5e32..0000000 --- a/project/Aki.SinglePlayer/Utils/ScavMode/ScavRaidChangesUtil.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace Aki.SinglePlayer.Utils.ScavMode -{ - /// - /// Allow mods to access changes made to map settings for Scav raids - /// - public static class ScavRaidChangesUtil - { - /// - /// The reduction in the escape time for the most recently loaded map, in minutes - /// - public static int RaidTimeReductionMinutes { get; private set; } = 0; - - /// - /// The reduction in the escape time for the most recently loaded map, in seconds - /// - public static int RaidTimeReductionSeconds => RaidTimeReductionMinutes * 60; - - /// - /// 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. - /// - /// The raid-time reduction applied to the most recent Scav raid, in minutes - internal static void SetRaidTimeReduction(int raidTimeReduction) - { - RaidTimeReductionMinutes = raidTimeReduction; - } - } -}