-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/Outer-Wilds-New-Horizons/new…
…-horizons into dev
- Loading branch information
Showing
4 changed files
with
68 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,52 @@ | ||
using HarmonyLib; | ||
using NewHorizons.Utility.OWML; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
|
||
namespace NewHorizons.Handlers | ||
{ | ||
[HarmonyPatch] | ||
internal class InvulnerabilityHandler | ||
{ | ||
private static float _defaultImpactDeathSpeed = -1f; | ||
Check warning on line 11 in NewHorizons/Handlers/InvulnerabilityHandler.cs
|
||
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) | ||
{ | ||
if (_defaultImpactDeathSpeed == -1f) | ||
_defaultImpactDeathSpeed = deathManager._impactDeathSpeed; | ||
|
||
deathManager._impactDeathSpeed = Mathf.Infinity; | ||
deathManager._invincible = true; | ||
} | ||
else | ||
{ | ||
deathManager._impactDeathSpeed = _defaultImpactDeathSpeed; | ||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters