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 UnityEngine;
using NewHorizons.External.Modules.VariableSize; using NewHorizons.External.Modules.VariableSize;
using Tessellation; using Tessellation;
using NewHorizons.Components.Volumes;
namespace NewHorizons.Builder.Body namespace NewHorizons.Builder.Body
{ {
@ -80,7 +79,7 @@ namespace NewHorizons.Builder.Body
var buoyancyTriggerVolume = buoyancyObject.AddComponent<OWTriggerVolume>(); var buoyancyTriggerVolume = buoyancyObject.AddComponent<OWTriggerVolume>();
buoyancyTriggerVolume._owCollider = owCollider; buoyancyTriggerVolume._owCollider = owCollider;
var fluidVolume = buoyancyObject.AddComponent<NHFluidVolume>(); var fluidVolume = buoyancyObject.AddComponent<RadialFluidVolume>();
fluidVolume._fluidType = FluidVolume.Type.WATER; fluidVolume._fluidType = FluidVolume.Type.WATER;
fluidVolume._attachedBody = rb; fluidVolume._attachedBody = rb;
fluidVolume._triggerVolume = buoyancyTriggerVolume; 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.Handlers;
using NewHorizons.Utility; using NewHorizons.Utility;
using UnityEngine; using UnityEngine;
@ -38,13 +37,15 @@ namespace NewHorizons.Builder.Props
raftController._riverFluid = null; raftController._riverFluid = null;
raftController._sector = sector; raftController._sector = sector;
raftController._acceleration = info.acceleration;
sector.OnOccupantEnterSector += raftController.OnOccupantEnterSector; sector.OnOccupantEnterSector += raftController.OnOccupantEnterSector;
sector.OnOccupantExitSector += raftController.OnOccupantExitSector; sector.OnOccupantExitSector += raftController.OnOccupantExitSector;
// Detectors // Detectors
var fluidDetector = raftObject.transform.Find("Detector_Raft").GetComponent<RaftFluidDetector>(); var fluidDetector = raftObject.transform.Find("Detector_Raft").GetComponent<RaftFluidDetector>();
var waterVolume = planetGO.GetComponentInChildren<NHFluidVolume>(); var waterVolume = planetGO.GetComponentInChildren<RadialFluidVolume>();
fluidDetector._alignmentFluid = waterVolume; fluidDetector._alignmentFluid = waterVolume;
fluidDetector._buoyancy.checkAgainstWaves = true;
// Light sensors // Light sensors
foreach (var lightSensor in raftObject.GetComponentsInChildren<SingleLightSensor>()) 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 /// Position of the raft
/// </summary> /// </summary>
public MVector3 position; public MVector3 position;
/// <summary>
/// Acceleration of the raft. Default acceleration is 5.
/// </summary>
[DefaultValue(5f)] public float acceleration = 5f;
} }
[JsonObject] [JsonObject]

View File

@ -1,5 +1,4 @@
using HarmonyLib; using HarmonyLib;
using NewHorizons.Components.Volumes;
using UnityEngine; using UnityEngine;
namespace NewHorizons.Patches namespace NewHorizons.Patches
{ {
@ -74,17 +73,17 @@ namespace NewHorizons.Patches
} }
[HarmonyReversePatch] [HarmonyReversePatch]
[HarmonyPatch(typeof(AsymmetricFluidDetector), "ManagedFixedUpdate")] [HarmonyPatch(typeof(AsymmetricFluidDetector), nameof(AsymmetricFluidDetector.ManagedFixedUpdate))]
public static void AsymmetricFluidDetector_ManagedFixedUpdate(AsymmetricFluidDetector __instance) public static void AsymmetricFluidDetector_ManagedFixedUpdate(AsymmetricFluidDetector __instance)
{ {
// This is like doing base.FixedUpdate // This is like doing base.FixedUpdate
} }
[HarmonyPrefix] [HarmonyPrefix]
[HarmonyPatch(typeof(AlignToSurfaceFluidDetector), "ManagedFixedUpdate")] [HarmonyPatch(typeof(AlignToSurfaceFluidDetector), nameof(AlignToSurfaceFluidDetector.ManagedFixedUpdate))]
public static bool AlignToSurfaceFluidDetector_ManagedFixedUpdate(AlignToSurfaceFluidDetector __instance) 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 // Mostly copy pasting from the AlignWithDirection class
AsymmetricFluidDetector_ManagedFixedUpdate(__instance); AsymmetricFluidDetector_ManagedFixedUpdate(__instance);
@ -104,5 +103,16 @@ namespace NewHorizons.Patches
return false; 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": { "position": {
"description": "Position of the raft", "description": "Position of the raft",
"$ref": "#/definitions/MVector3" "$ref": "#/definitions/MVector3"
},
"acceleration": {
"type": "number",
"description": "Acceleration of the raft. Default acceleration is 5.",
"format": "float",
"default": 5.0
} }
} }
}, },