50 lines
1.4 KiB
C#
Raw Normal View History

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