From 7bf85b2017285118d87953607a46e1b805837d1f Mon Sep 17 00:00:00 2001 From: Nick Date: Fri, 22 Mar 2024 16:19:23 -0400 Subject: [PATCH] Fix drowning in ship --- .../Fixers/PlayerShipAtmosphereDetectorFix.cs | 33 +++++++++++++++++++ NewHorizons/Main.cs | 1 + 2 files changed, 34 insertions(+) create mode 100644 NewHorizons/Components/Fixers/PlayerShipAtmosphereDetectorFix.cs diff --git a/NewHorizons/Components/Fixers/PlayerShipAtmosphereDetectorFix.cs b/NewHorizons/Components/Fixers/PlayerShipAtmosphereDetectorFix.cs new file mode 100644 index 00000000..25d135c1 --- /dev/null +++ b/NewHorizons/Components/Fixers/PlayerShipAtmosphereDetectorFix.cs @@ -0,0 +1,33 @@ +using NewHorizons.Utility.OWML; +using UnityEngine; + +namespace NewHorizons.Components.Fixers; + +/// +/// Fixes a bug where spawning into the ship would not trigger the hatch entryway, so the player could drown if the ship flew into water +/// +internal class PlayerShipAtmosphereDetectorFix : MonoBehaviour +{ + private PlayerCameraFluidDetector _fluidDetector; + private SimpleFluidVolume _shipAtmosphereVolume; + + public void Start() + { + _fluidDetector = Locator.GetPlayerCameraDetector().GetComponent(); + _shipAtmosphereVolume = Locator.GetShipBody().transform.Find("Volumes/ShipAtmosphereVolume").GetComponent(); + } + + public void Update() + { + if (PlayerState.IsInsideShip()) + { + if (!_fluidDetector._activeVolumes.Contains(_shipAtmosphereVolume)) + { + NHLogger.LogVerbose($"{nameof(PlayerShipAtmosphereDetectorFix)} had to add the ship atmosphere volume [{_shipAtmosphereVolume}] to the fluid detector"); + _fluidDetector.AddVolume(_shipAtmosphereVolume); + } + NHLogger.LogVerbose($"{nameof(PlayerShipAtmosphereDetectorFix)} applied its fix"); + Component.Destroy(this); + } + } +} diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 0314cf61..da1d2795 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -601,6 +601,7 @@ namespace NewHorizons Locator.GetPlayerBody().gameObject.AddComponent(); Locator.GetPlayerBody().gameObject.AddComponent(); Locator.GetPlayerBody().gameObject.AddComponent(); + Locator.GetPlayerBody().gameObject.AddComponent(); PlayerSpawnHandler.OnSystemReady(shouldWarpInFromShip, shouldWarpInFromVessel);