Fix drowning in ship

This commit is contained in:
Nick 2024-03-22 16:19:23 -04:00
parent 67a9684eb3
commit 7bf85b2017
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,33 @@
using NewHorizons.Utility.OWML;
using UnityEngine;
namespace NewHorizons.Components.Fixers;
/// <summary>
/// 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
/// </summary>
internal class PlayerShipAtmosphereDetectorFix : MonoBehaviour
{
private PlayerCameraFluidDetector _fluidDetector;
private SimpleFluidVolume _shipAtmosphereVolume;
public void Start()
{
_fluidDetector = Locator.GetPlayerCameraDetector().GetComponent<PlayerCameraFluidDetector>();
_shipAtmosphereVolume = Locator.GetShipBody().transform.Find("Volumes/ShipAtmosphereVolume").GetComponent<SimpleFluidVolume>();
}
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);
}
}
}

View File

@ -601,6 +601,7 @@ namespace NewHorizons
Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>();
Locator.GetPlayerBody().gameObject.AddComponent<DebugPropPlacer>();
Locator.GetPlayerBody().gameObject.AddComponent<DebugMenu>();
Locator.GetPlayerBody().gameObject.AddComponent<PlayerShipAtmosphereDetectorFix>();
PlayerSpawnHandler.OnSystemReady(shouldWarpInFromShip, shouldWarpInFromVessel);