quantum-space-buddies/QSB/TornadoSync/Patches/TornadoPatches.cs

71 lines
2.0 KiB
C#
Raw Normal View History

2021-12-05 11:41:07 +00:00
using HarmonyLib;
2021-12-25 00:47:10 +00:00
using QSB.Messaging;
2021-12-05 11:41:07 +00:00
using QSB.Patches;
2021-12-25 00:47:10 +00:00
using QSB.TornadoSync.Messages;
2021-12-05 11:41:07 +00:00
using QSB.TornadoSync.WorldObjects;
using QSB.WorldSync;
using UnityEngine;
2021-12-04 14:21:11 +00:00
2022-03-03 03:46:33 +00:00
namespace QSB.TornadoSync.Patches;
public class TornadoPatches : QSBPatch
2021-12-04 14:21:11 +00:00
{
2022-03-03 03:46:33 +00:00
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
2022-03-03 03:46:33 +00:00
[HarmonyPrefix]
[HarmonyPatch(typeof(TornadoController), nameof(TornadoController.FixedUpdate))]
public static bool FixedUpdate(TornadoController __instance)
{
if (QSBCore.IsHost && __instance._secondsUntilFormation > 0f)
{
2022-03-03 03:46:33 +00:00
__instance._secondsUntilFormation -= Time.fixedDeltaTime;
if (__instance._secondsUntilFormation < 0f)
2021-12-05 11:41:07 +00:00
{
2022-03-03 03:46:33 +00:00
__instance.StartFormation();
var qsbTornado = __instance.GetWorldObject<QSBTornado>();
qsbTornado.SendMessage(new TornadoFormStateMessage(qsbTornado.FormState));
return false;
}
2022-03-03 03:46:33 +00:00
}
else
{
if (__instance._tornadoCollapsing)
{
2022-03-03 03:46:33 +00:00
__instance.UpdateCollapse();
}
else if (__instance._tornadoForming)
{
__instance.UpdateFormation();
}
2022-01-01 22:19:10 +00:00
2022-03-03 03:46:33 +00:00
if (__instance._isSectorOccupied)
{
__instance.UpdateAnimation();
if (__instance._wander)
2021-12-05 11:41:07 +00:00
{
2022-03-03 03:46:33 +00:00
var num = Mathf.PerlinNoise(Time.time * __instance._wanderRate, 0f) * 2f - 1f;
var num2 = Mathf.PerlinNoise(Time.time * __instance._wanderRate, 5f) * 2f - 1f;
var localEulerAngles = new Vector3(num * __instance._wanderDegreesX, 0f, num2 * __instance._wanderDegreesZ);
__instance.transform.localEulerAngles = localEulerAngles;
2021-12-05 11:41:07 +00:00
}
}
}
2021-12-05 11:41:07 +00:00
2022-03-03 03:46:33 +00:00
return false;
}
2022-03-03 03:46:33 +00:00
[HarmonyPrefix]
[HarmonyPatch(typeof(TornadoController), nameof(TornadoController.OnEnterCollapseTrigger))]
public static bool OnEnterCollapseTrigger(TornadoController __instance,
GameObject hitObject)
{
if (QSBCore.IsHost && hitObject.GetComponentInParent<OWRigidbody>().GetMass() > 50f)
{
__instance.StartCollapse();
var qsbTornado = __instance.GetWorldObject<QSBTornado>();
qsbTornado.SendMessage(new TornadoFormStateMessage(qsbTornado.FormState));
}
2022-03-03 03:46:33 +00:00
return false;
2021-12-04 14:21:11 +00:00
}
}