Allow spawned rafts to change water fluids and prevent NRE if one isn't set

This commit is contained in:
Joshua Thome 2024-05-18 07:49:48 -05:00
parent 70f3e92b56
commit 2e68c57e66
4 changed files with 43 additions and 1 deletions

View File

@ -417,6 +417,11 @@ namespace NewHorizons.Builder.Props
{ {
component.gameObject.AddComponent<AnglerAnimFixer>(); 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> /// <summary>

View File

@ -1,3 +1,4 @@
using NewHorizons.Components.Props;
using NewHorizons.External.Modules.Props.EchoesOfTheEye; using NewHorizons.External.Modules.Props.EchoesOfTheEye;
using NewHorizons.Handlers; using NewHorizons.Handlers;
using NewHorizons.Utility; using NewHorizons.Utility;
@ -73,6 +74,8 @@ namespace NewHorizons.Builder.Props
sector.OnSectorOccupantsUpdated += lightSensor.OnSectorOccupantsUpdated; sector.OnSectorOccupantsUpdated += lightSensor.OnSectorOccupantsUpdated;
} }
var nhRaftController = raftObject.AddComponent<NHRaftController>();
var achievementObject = new GameObject("AchievementVolume"); var achievementObject = new GameObject("AchievementVolume");
achievementObject.transform.SetParent(raftObject.transform, false); 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) if (__instance._playerInEffectsRange)
{ {
// All this to change what fluidVolume we use on this line // 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; bool allowMovement = num > 0.25f && num < 1f;
__instance._effectsController.UpdateMovementAudio(allowMovement, __instance._lightSensors); __instance._effectsController.UpdateMovementAudio(allowMovement, __instance._lightSensors);
__instance._effectsController.UpdateGroundedAudio(__instance._fluidDetector); __instance._effectsController.UpdateGroundedAudio(__instance._fluidDetector);