quantum-space-buddies/QSB/JellyfishSync/Patches/JellyfishPatches.cs

48 lines
1.5 KiB
C#
Raw Normal View History

2021-12-01 09:10:38 +00:00
using HarmonyLib;
2021-12-25 00:47:10 +00:00
using QSB.JellyfishSync.Messages;
2021-12-01 09:10:38 +00:00
using QSB.JellyfishSync.WorldObjects;
2021-12-25 00:47:10 +00:00
using QSB.Messaging;
2021-12-01 09:10:38 +00:00
using QSB.Patches;
using QSB.WorldSync;
2022-03-03 03:46:33 +00:00
namespace QSB.JellyfishSync.Patches;
public class JellyfishPatches : QSBPatch
2021-12-01 09:10:38 +00:00
{
2022-03-03 03:46:33 +00:00
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
2022-01-01 22:19:10 +00:00
2022-03-03 03:46:33 +00:00
[HarmonyPrefix]
[HarmonyPatch(typeof(JellyfishController), nameof(JellyfishController.FixedUpdate))]
public static bool FixedUpdate(JellyfishController __instance)
{
if (!QSBWorldSync.AllObjectsReady)
{
2022-03-03 03:46:33 +00:00
return true;
}
2022-03-03 03:46:33 +00:00
var sqrMagnitude = (__instance._jellyfishBody.GetPosition() - __instance._planetBody.GetPosition()).sqrMagnitude;
if (__instance._isRising)
{
__instance._jellyfishBody.AddAcceleration(__instance.transform.up * __instance._upwardsAcceleration);
if (sqrMagnitude > __instance._upperLimit * __instance._upperLimit)
2021-12-01 10:23:12 +00:00
{
2022-03-03 03:46:33 +00:00
__instance._isRising = false;
__instance._attractiveFluidVolume.SetVolumeActivation(true);
__instance.GetWorldObject<QSBJellyfish>().SendMessage(new JellyfishRisingMessage(false));
return false;
}
2022-03-03 03:46:33 +00:00
}
else
{
__instance._jellyfishBody.AddAcceleration(-__instance.transform.up * __instance._downwardsAcceleration);
if (sqrMagnitude < __instance._lowerLimit * __instance._lowerLimit)
{
2022-03-03 03:46:33 +00:00
__instance._isRising = true;
__instance._attractiveFluidVolume.SetVolumeActivation(false);
__instance.GetWorldObject<QSBJellyfish>().SendMessage(new JellyfishRisingMessage(true));
2021-12-01 10:23:12 +00:00
}
}
2022-03-03 03:46:33 +00:00
return false;
2021-12-01 09:10:38 +00:00
}
}