mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
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();
|
|
|
|
if (invulnerable)
|
|
{
|
|
deathManager._invincible = true;
|
|
}
|
|
else
|
|
{
|
|
resources._currentHealth = 100f;
|
|
deathManager._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 !_invulnerable;
|
|
}
|
|
|
|
private static DeathManager GetDeathManager() => GameObject.FindObjectOfType<DeathManager>();
|
|
private static PlayerResources GetPlayerResouces() => GameObject.FindObjectOfType<PlayerResources>();
|
|
|
|
static InvulnerabilityHandler()
|
|
{
|
|
SceneManager.sceneUnloaded += (_) => _invulnerable = false;
|
|
}
|
|
}
|
|
}
|