Address review - use _invinicible in its own file, comment orbitlines

This commit is contained in:
xen-42 2025-02-10 10:01:51 -05:00
parent 52f164a458
commit 90cf5880ed
3 changed files with 21 additions and 23 deletions

View File

@ -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<DeathManager>();
private static PlayerResources GetPlayerResouces() => GameObject.FindObjectOfType<PlayerResources>();
static InvulnerabilityHandler()
{
SceneManager.sceneUnloaded += (_) => _invulnerable = false;
}
}
}

View File

@ -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);

View File

@ -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);
}
}
}