mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using NewHorizons.Utility.OWML;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
namespace NewHorizons.Handlers
|
|
{
|
|
internal class InvulnerabilityHandler
|
|
{
|
|
/// <summary>
|
|
/// Used in patches
|
|
/// </summary>
|
|
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();
|
|
|
|
if (invulnerable)
|
|
{
|
|
deathManager._invincible = true;
|
|
resources._invincible = true;
|
|
}
|
|
else
|
|
{
|
|
resources._currentHealth = 100f;
|
|
deathManager._invincible = false;
|
|
resources._invincible = false;
|
|
}
|
|
}
|
|
|
|
private static DeathManager GetDeathManager() => GameObject.FindObjectOfType<DeathManager>();
|
|
private static PlayerResources GetPlayerResouces() => GameObject.FindObjectOfType<PlayerResources>();
|
|
|
|
static InvulnerabilityHandler()
|
|
{
|
|
// If the scene unloads when Invincible is on it might not get turned off
|
|
SceneManager.sceneUnloaded += (_) => Invincible = false;
|
|
}
|
|
}
|
|
}
|