From 90cf5880edafb2c885819a2f17a7f07cc7085437 Mon Sep 17 00:00:00 2001 From: xen-42 Date: Mon, 10 Feb 2025 10:01:51 -0500 Subject: [PATCH] Address review - use _invinicible in its own file, comment orbitlines --- .../Handlers/InvulnerabilityHandler.cs | 23 ------------------- NewHorizons/Handlers/PlanetCreationHandler.cs | 2 ++ NewHorizons/Patches/InvincibilityPatches.cs | 19 +++++++++++++++ 3 files changed, 21 insertions(+), 23 deletions(-) create mode 100644 NewHorizons/Patches/InvincibilityPatches.cs diff --git a/NewHorizons/Handlers/InvulnerabilityHandler.cs b/NewHorizons/Handlers/InvulnerabilityHandler.cs index e6f3777a..00df816e 100644 --- a/NewHorizons/Handlers/InvulnerabilityHandler.cs +++ b/NewHorizons/Handlers/InvulnerabilityHandler.cs @@ -1,21 +1,14 @@ -using HarmonyLib; using NewHorizons.Utility.OWML; using UnityEngine; -using UnityEngine.SceneManagement; namespace NewHorizons.Handlers { - [HarmonyPatch] internal class InvulnerabilityHandler { - private static float _defaultImpactDeathSpeed = -1f; - private static bool _invulnerable; - public static void MakeInvulnerable(bool invulnerable) { NHLogger.Log($"Toggling immortality: {invulnerable}"); - _invulnerable = invulnerable; var deathManager = GetDeathManager(); var resources = GetPlayerResouces(); @@ -30,23 +23,7 @@ namespace NewHorizons.Handlers } } - [HarmonyPrefix] - [HarmonyPatch(typeof(DeathManager), nameof(DeathManager.KillPlayer))] - [HarmonyPatch(typeof(PlayerResources), nameof(PlayerResources.ApplyInstantDamage))] - [HarmonyPatch(typeof(PlayerImpactAudio), nameof(PlayerImpactAudio.OnImpact))] - public static bool DeathManager_KillPlayer_Prefix() - { - // Base game _invincible is still overriden by high speed impacts - // We also are avoiding playing impact related effects by just skipping these methods - return !_invulnerable; - } - private static DeathManager GetDeathManager() => GameObject.FindObjectOfType(); private static PlayerResources GetPlayerResouces() => GameObject.FindObjectOfType(); - - static InvulnerabilityHandler() - { - SceneManager.sceneUnloaded += (_) => _invulnerable = false; - } } } diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index e254abef..6898382f 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -514,6 +514,7 @@ namespace NewHorizons.Handlers if (body.Config.Orbit.showOrbitLine && !body.Config.Orbit.isStatic) { + // No map mode at eye if (LoadManager.GetCurrentScene() != OWScene.EyeOfTheUniverse) { OrbitlineBuilder.Make(body.Object, body.Config.Orbit.isMoon, body.Config); @@ -858,6 +859,7 @@ namespace NewHorizons.Handlers var isMoon = newAO.GetAstroObjectType() is AstroObject.Type.Moon or AstroObject.Type.Satellite or AstroObject.Type.SpaceStation; if (body.Config.Orbit.showOrbitLine) { + // No map mode at eye if (LoadManager.GetCurrentScene() != OWScene.EyeOfTheUniverse) { OrbitlineBuilder.Make(go, isMoon, body.Config); diff --git a/NewHorizons/Patches/InvincibilityPatches.cs b/NewHorizons/Patches/InvincibilityPatches.cs new file mode 100644 index 00000000..0a7f58e9 --- /dev/null +++ b/NewHorizons/Patches/InvincibilityPatches.cs @@ -0,0 +1,19 @@ +using HarmonyLib; + +namespace NewHorizons.Patches +{ + [HarmonyPatch] + public static class InvincibilityPatches + { + [HarmonyPrefix] + [HarmonyPatch(typeof(DeathManager), nameof(DeathManager.KillPlayer))] + [HarmonyPatch(typeof(PlayerResources), nameof(PlayerResources.ApplyInstantDamage))] + [HarmonyPatch(typeof(PlayerImpactAudio), nameof(PlayerImpactAudio.OnImpact))] + public static bool DeathManager_KillPlayer_Prefix() + { + // Base game _invincible is still overriden by high speed impacts + // We also are avoiding playing impact related effects by just skipping these methods + return !(Locator.GetDeathManager()?._invincible ?? false); + } + } +}