75 lines
1.8 KiB
C#
Raw Normal View History

using HarmonyLib;
using QSB.Events;
2021-12-14 20:24:02 -08:00
using QSB.OrbSync.WorldObjects;
2020-12-14 20:31:31 +01:00
using QSB.Patches;
2021-12-14 20:24:02 -08:00
using QSB.WorldSync;
2020-09-05 13:24:51 +01:00
namespace QSB.OrbSync.Patches
2020-09-05 13:24:51 +01:00
{
2021-12-14 23:57:21 -08:00
[HarmonyPatch(typeof(NomaiInterfaceOrb))]
2020-12-02 21:29:53 +00:00
public class OrbPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
2020-11-03 21:11:10 +00:00
[HarmonyPostfix]
2021-12-14 23:57:21 -08:00
[HarmonyPatch(nameof(NomaiInterfaceOrb.StartDragFromPosition))]
public static void StartDragFromPosition(NomaiInterfaceOrb __instance)
2020-12-02 21:29:53 +00:00
{
2021-12-15 01:20:51 -08:00
if (!__instance._isBeingDragged)
2020-12-02 21:29:53 +00:00
{
2021-12-14 20:24:02 -08:00
return;
2021-12-13 21:18:16 -08:00
}
2021-12-15 01:20:51 -08:00
if (!WorldObjectManager.AllObjectsReady)
2021-12-14 20:24:02 -08:00
{
return;
}
var qsbOrb = QSBWorldSync.GetWorldFromUnity<QSBOrb>(__instance);
2021-12-15 01:20:51 -08:00
QSBEventManager.FireEvent(EventNames.QSBOrbDrag, qsbOrb, true);
2021-12-13 21:18:16 -08:00
}
2021-12-13 21:52:59 -08:00
[HarmonyPrefix]
2021-12-14 23:57:21 -08:00
[HarmonyPatch(nameof(NomaiInterfaceOrb.CancelDrag))]
public static void CancelDrag(NomaiInterfaceOrb __instance)
2021-12-13 21:18:16 -08:00
{
2021-12-15 01:20:51 -08:00
if (!__instance._isBeingDragged)
2021-12-13 21:18:16 -08:00
{
2021-12-14 20:24:02 -08:00
return;
2020-12-02 21:29:53 +00:00
}
2021-12-15 01:20:51 -08:00
if (!WorldObjectManager.AllObjectsReady)
2021-12-14 20:24:02 -08:00
{
return;
}
var qsbOrb = QSBWorldSync.GetWorldFromUnity<QSBOrb>(__instance);
2021-12-14 23:57:21 -08:00
if (!qsbOrb.TransformSync.HasAuthority)
{
return;
}
2021-12-15 01:20:51 -08:00
QSBEventManager.FireEvent(EventNames.QSBOrbDrag, qsbOrb, false);
2020-12-02 21:29:53 +00:00
}
2020-09-06 09:07:31 +01:00
[HarmonyPrefix]
2021-12-15 01:20:51 -08:00
[HarmonyPatch(nameof(NomaiInterfaceOrb.MoveTowardPosition))]
public static bool MoveTowardPosition(NomaiInterfaceOrb __instance)
2020-12-02 21:29:53 +00:00
{
2021-12-14 20:24:02 -08:00
if (!WorldObjectManager.AllObjectsReady)
{
return true;
}
2021-12-14 23:57:21 -08:00
var qsbOrb = QSBWorldSync.GetWorldFromUnity<QSBOrb>(__instance);
2021-12-15 01:20:51 -08:00
if (qsbOrb.TransformSync.HasAuthority)
2021-12-14 20:24:02 -08:00
{
return true;
}
2021-12-15 01:20:51 -08:00
var pointVelocity = __instance._parentBody.GetPointVelocity(__instance._orbBody.GetPosition());
__instance._orbBody.SetVelocity(pointVelocity);
if (!__instance._applyForcesWhileMoving)
2020-12-02 21:29:53 +00:00
{
2021-12-15 01:20:51 -08:00
__instance._forceApplier.SetApplyForces(false);
2020-12-02 21:29:53 +00:00
}
2021-06-18 22:38:32 +01:00
2020-12-02 21:29:53 +00:00
return false;
}
}
2021-12-13 22:22:19 -08:00
}