mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Don't use patch, use invincible field on player resources
This commit is contained in:
parent
d1c8d132ae
commit
d5d9200331
@ -5,49 +5,29 @@ using UnityEngine.SceneManagement;
|
|||||||
|
|
||||||
namespace NewHorizons.Handlers
|
namespace NewHorizons.Handlers
|
||||||
{
|
{
|
||||||
[HarmonyPatch]
|
|
||||||
internal class InvulnerabilityHandler
|
internal class InvulnerabilityHandler
|
||||||
{
|
{
|
||||||
private static bool _invulnerableOverride;
|
|
||||||
|
|
||||||
public static void MakeInvulnerable(bool invulnerable)
|
public static void MakeInvulnerable(bool invulnerable)
|
||||||
{
|
{
|
||||||
NHLogger.Log($"Toggling immortality: {invulnerable}");
|
NHLogger.Log($"Toggling immortality: {invulnerable}");
|
||||||
|
|
||||||
// We're setting our own override because we want to ensure that no other mod that can set _invincible can break this for us
|
|
||||||
_invulnerableOverride = invulnerable;
|
|
||||||
var deathManager = GetDeathManager();
|
var deathManager = GetDeathManager();
|
||||||
var resources = GetPlayerResouces();
|
var resources = GetPlayerResouces();
|
||||||
|
|
||||||
if (invulnerable)
|
if (invulnerable)
|
||||||
{
|
{
|
||||||
deathManager._invincible = true;
|
deathManager._invincible = true;
|
||||||
|
resources._invincible = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
resources._currentHealth = 100f;
|
resources._currentHealth = 100f;
|
||||||
deathManager._invincible = false;
|
deathManager._invincible = false;
|
||||||
|
resources._invincible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[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 !_invulnerableOverride;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static DeathManager GetDeathManager() => GameObject.FindObjectOfType<DeathManager>();
|
private static DeathManager GetDeathManager() => GameObject.FindObjectOfType<DeathManager>();
|
||||||
private static PlayerResources GetPlayerResouces() => GameObject.FindObjectOfType<PlayerResources>();
|
private static PlayerResources GetPlayerResouces() => GameObject.FindObjectOfType<PlayerResources>();
|
||||||
|
|
||||||
static InvulnerabilityHandler()
|
|
||||||
{
|
|
||||||
// If the scene unloads when _invulnerableOverride is on it might not get turned off
|
|
||||||
SceneManager.sceneUnloaded += (_) => _invulnerableOverride = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user