Allow rafts to change water fluids and stop NRE if one isn't set (#862)

## Bug fixes
- Rafts spawned with New Horizons update their "alignment volume" when
they enter water volumes, allowing them to move between different bodies
of water or be spawned on planets without oceans. Fixes #846 .
This commit is contained in:
Noah Pilarski 2024-05-20 14:25:39 -04:00 committed by GitHub
commit 981ba7e6ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 43 additions and 1 deletions

View File

@ -417,6 +417,11 @@ namespace NewHorizons.Builder.Props
{
component.gameObject.AddComponent<AnglerAnimFixer>();
}
// Add custom logic to NH-spawned rafts to handle fluid changes
else if (component is RaftController raft)
{
component.gameObject.AddComponent<NHRaftController>();
}
}
/// <summary>

View File

@ -1,3 +1,4 @@
using NewHorizons.Components.Props;
using NewHorizons.External.Modules.Props.EchoesOfTheEye;
using NewHorizons.Handlers;
using NewHorizons.Utility;
@ -73,6 +74,8 @@ namespace NewHorizons.Builder.Props
sector.OnSectorOccupantsUpdated += lightSensor.OnSectorOccupantsUpdated;
}
var nhRaftController = raftObject.AddComponent<NHRaftController>();
var achievementObject = new GameObject("AchievementVolume");
achievementObject.transform.SetParent(raftObject.transform, false);

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace NewHorizons.Components.Props
{
public class NHRaftController : MonoBehaviour
{
RaftController raft;
public void OnEnable()
{
raft = GetComponent<RaftController>();
raft._fluidDetector.OnEnterFluid += OnEnterFluid;
}
public void OnDisable()
{
raft._fluidDetector.OnEnterFluid -= OnEnterFluid;
}
private void OnEnterFluid(FluidVolume volume)
{
if (volume.GetFluidType() == FluidVolume.Type.WATER)
{
raft._fluidDetector._alignmentFluid = volume;
}
}
}
}

View File

@ -63,7 +63,8 @@ namespace NewHorizons.Patches.EchoesOfTheEyePatches
if (__instance._playerInEffectsRange)
{
// All this to change what fluidVolume we use on this line
float num = __instance._fluidDetector.InFluidType(FluidVolume.Type.WATER) ? __instance._fluidDetector._alignmentFluid.GetFractionSubmerged(__instance._fluidDetector) : 0f;
FluidVolume volume = __instance._fluidDetector._alignmentFluid;
float num = __instance._fluidDetector.InFluidType(FluidVolume.Type.WATER) && volume != null ? volume.GetFractionSubmerged(__instance._fluidDetector) : 0f;
bool allowMovement = num > 0.25f && num < 1f;
__instance._effectsController.UpdateMovementAudio(allowMovement, __instance._lightSensors);
__instance._effectsController.UpdateGroundedAudio(__instance._fluidDetector);