diff --git a/NewHorizons/Handlers/InvulnerabilityHandler.cs b/NewHorizons/Handlers/InvulnerabilityHandler.cs index 3649cf70..cacc9e19 100644 --- a/NewHorizons/Handlers/InvulnerabilityHandler.cs +++ b/NewHorizons/Handlers/InvulnerabilityHandler.cs @@ -1,4 +1,3 @@ -using HarmonyLib; using NewHorizons.Utility.OWML; using UnityEngine; using UnityEngine.SceneManagement; @@ -7,10 +6,16 @@ namespace NewHorizons.Handlers { internal class InvulnerabilityHandler { + /// + /// Used in patches + /// + public static bool Invincible { get; private set; } + public static void MakeInvulnerable(bool invulnerable) { NHLogger.Log($"Toggling immortality: {invulnerable}"); + Invincible = invulnerable; var deathManager = GetDeathManager(); var resources = GetPlayerResouces(); @@ -29,5 +34,11 @@ namespace NewHorizons.Handlers private static DeathManager GetDeathManager() => GameObject.FindObjectOfType(); private static PlayerResources GetPlayerResouces() => GameObject.FindObjectOfType(); + + static InvulnerabilityHandler() + { + // If the scene unloads when Invincible is on it might not get turned off + SceneManager.sceneUnloaded += (_) => Invincible = false; + } } } diff --git a/NewHorizons/Patches/PlayerImpactAudioPatches.cs b/NewHorizons/Patches/PlayerImpactAudioPatches.cs new file mode 100644 index 00000000..bf583229 --- /dev/null +++ b/NewHorizons/Patches/PlayerImpactAudioPatches.cs @@ -0,0 +1,21 @@ +using HarmonyLib; +using NewHorizons.Handlers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.Patches; + +[HarmonyPatch] +public static class PlayerImpactAudioPatches +{ + [HarmonyPrefix] + [HarmonyPatch(typeof(PlayerImpactAudio), nameof(PlayerImpactAudio.OnImpact))] + public static bool PlayerImpactAudio_OnImpact() + { + // DeathManager and PlayerResources _invincible stops player dying but you still hear the impact sounds which is annoying so we disable them + return !InvulnerabilityHandler.Invincible; + } +}