Allow rafts to be added to Giant's Deep and add acceleration option (#415)

![image](https://user-images.githubusercontent.com/34462599/194729187-6b9dc001-7ae6-4dcb-9354-3883d9a5ac37.png)
This commit is contained in:
Nick 2022-10-10 12:06:48 -04:00 committed by GitHub
commit 01f719dee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 22 deletions

View File

@ -3,7 +3,6 @@ using NewHorizons.Utility;
using UnityEngine;
using NewHorizons.External.Modules.VariableSize;
using Tessellation;
using NewHorizons.Components.Volumes;
namespace NewHorizons.Builder.Body
{
@ -80,7 +79,7 @@ namespace NewHorizons.Builder.Body
var buoyancyTriggerVolume = buoyancyObject.AddComponent<OWTriggerVolume>();
buoyancyTriggerVolume._owCollider = owCollider;
var fluidVolume = buoyancyObject.AddComponent<NHFluidVolume>();
var fluidVolume = buoyancyObject.AddComponent<RadialFluidVolume>();
fluidVolume._fluidType = FluidVolume.Type.WATER;
fluidVolume._attachedBody = rb;
fluidVolume._triggerVolume = buoyancyTriggerVolume;

View File

@ -1,5 +1,4 @@
using NewHorizons.Components.Volumes;
using NewHorizons.External.Modules;
using NewHorizons.External.Modules;
using NewHorizons.Handlers;
using NewHorizons.Utility;
using UnityEngine;
@ -38,13 +37,15 @@ namespace NewHorizons.Builder.Props
raftController._riverFluid = null;
raftController._sector = sector;
raftController._acceleration = info.acceleration;
sector.OnOccupantEnterSector += raftController.OnOccupantEnterSector;
sector.OnOccupantExitSector += raftController.OnOccupantExitSector;
// Detectors
var fluidDetector = raftObject.transform.Find("Detector_Raft").GetComponent<RaftFluidDetector>();
var waterVolume = planetGO.GetComponentInChildren<NHFluidVolume>();
var waterVolume = planetGO.GetComponentInChildren<RadialFluidVolume>();
fluidDetector._alignmentFluid = waterVolume;
fluidDetector._buoyancy.checkAgainstWaves = true;
// Light sensors
foreach (var lightSensor in raftObject.GetComponentsInChildren<SingleLightSensor>())

View File

@ -1,13 +0,0 @@
using UnityEngine;
namespace NewHorizons.Components.Volumes
{
public class NHFluidVolume : RadialFluidVolume
{
public override float GetDepthAtPosition(Vector3 worldPosition)
{
Vector3 vector = transform.InverseTransformPoint(worldPosition);
float dist = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y);
return dist - _radius;
}
}
}

View File

@ -233,6 +233,11 @@ namespace NewHorizons.External.Modules
/// Position of the raft
/// </summary>
public MVector3 position;
/// <summary>
/// Acceleration of the raft. Default acceleration is 5.
/// </summary>
[DefaultValue(5f)] public float acceleration = 5f;
}
[JsonObject]

View File

@ -1,5 +1,4 @@
using HarmonyLib;
using NewHorizons.Components.Volumes;
using UnityEngine;
namespace NewHorizons.Patches
{
@ -74,17 +73,17 @@ namespace NewHorizons.Patches
}
[HarmonyReversePatch]
[HarmonyPatch(typeof(AsymmetricFluidDetector), "ManagedFixedUpdate")]
[HarmonyPatch(typeof(AsymmetricFluidDetector), nameof(AsymmetricFluidDetector.ManagedFixedUpdate))]
public static void AsymmetricFluidDetector_ManagedFixedUpdate(AsymmetricFluidDetector __instance)
{
// This is like doing base.FixedUpdate
}
[HarmonyPrefix]
[HarmonyPatch(typeof(AlignToSurfaceFluidDetector), "ManagedFixedUpdate")]
[HarmonyPatch(typeof(AlignToSurfaceFluidDetector), nameof(AlignToSurfaceFluidDetector.ManagedFixedUpdate))]
public static bool AlignToSurfaceFluidDetector_ManagedFixedUpdate(AlignToSurfaceFluidDetector __instance)
{
if (!(__instance._alignmentFluid is NHFluidVolume)) return true;
if (__instance._alignmentFluid is not RadialFluidVolume) return true;
// Mostly copy pasting from the AlignWithDirection class
AsymmetricFluidDetector_ManagedFixedUpdate(__instance);
@ -104,5 +103,16 @@ namespace NewHorizons.Patches
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(FluidVolume), nameof(FluidVolume.GetDepthAtPosition))]
public static bool FluidVolume_GetDepthAtPosition(FluidVolume __instance, ref float __result, Vector3 worldPosition)
{
if (__instance is not RadialFluidVolume radialFluidVolume) return true;
Vector3 vector = radialFluidVolume.transform.InverseTransformPoint(worldPosition);
__result = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y) - radialFluidVolume._radius;
return false;
}
}
}

View File

@ -1339,6 +1339,12 @@
"position": {
"description": "Position of the raft",
"$ref": "#/definitions/MVector3"
},
"acceleration": {
"type": "number",
"description": "Acceleration of the raft. Default acceleration is 5.",
"format": "float",
"default": 5.0
}
}
},