2021-10-15 21:06:51 +01:00
|
|
|
|
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;
|
2021-12-15 02:25:13 -08:00
|
|
|
|
using UnityEngine;
|
2020-09-05 13:24:51 +01:00
|
|
|
|
|
2020-12-31 12:10:55 +00: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
|
|
|
|
|
2021-10-15 21:06:51 +01: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
|
|
|
|
|
2021-10-15 21:06:51 +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-15 02:25:13 -08:00
|
|
|
|
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(nameof(NomaiInterfaceOrb.CheckSlotCollision))]
|
|
|
|
|
public static bool CheckSlotCollision(NomaiInterfaceOrb __instance)
|
|
|
|
|
{
|
|
|
|
|
if (!WorldObjectManager.AllObjectsReady)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
var qsbOrb = QSBWorldSync.GetWorldFromUnity<QSBOrb>(__instance);
|
|
|
|
|
if (!qsbOrb.TransformSync.HasAuthority)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (__instance._occupiedSlot == null)
|
|
|
|
|
{
|
|
|
|
|
for (var slotIndex = 0; slotIndex < __instance._slots.Length; slotIndex++)
|
|
|
|
|
{
|
|
|
|
|
var slot = __instance._slots[slotIndex];
|
|
|
|
|
if (slot != null && slot.CheckOrbCollision(__instance))
|
|
|
|
|
{
|
|
|
|
|
__instance._occupiedSlot = slot;
|
|
|
|
|
__instance._enterSlotTime = Time.time;
|
|
|
|
|
if (slot.CancelsDragOnCollision())
|
|
|
|
|
{
|
|
|
|
|
__instance.CancelDrag();
|
|
|
|
|
}
|
|
|
|
|
if (__instance._orbAudio != null && slot.GetPlayActivationAudio())
|
|
|
|
|
{
|
|
|
|
|
__instance._orbAudio.PlaySlotActivatedClip();
|
|
|
|
|
}
|
2021-12-17 16:53:23 -08:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBOrbSlot, qsbOrb, slotIndex);
|
2021-12-15 02:25:13 -08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if ((!__instance._occupiedSlot.IsAttractive() || __instance._isBeingDragged) && !__instance._occupiedSlot.CheckOrbCollision(__instance))
|
|
|
|
|
{
|
|
|
|
|
__instance._occupiedSlot = null;
|
2021-12-17 16:53:23 -08:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBOrbSlot, qsbOrb, -1);
|
2021-12-15 02:25:13 -08:00
|
|
|
|
}
|
|
|
|
|
__instance._owCollider.SetActivation(__instance._occupiedSlot == null || !__instance._occupiedSlot.IsAttractive() || __instance._isBeingDragged);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
2021-12-13 22:22:19 -08:00
|
|
|
|
}
|