107 lines
2.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;
using QSB.Utility;
2021-12-14 20:24:02 -08:00
using QSB.WorldSync;
2020-09-06 09:07:31 +01:00
using UnityEngine;
2020-09-05 13:24:51 +01:00
namespace QSB.OrbSync.Patches
2020-09-05 13:24:51 +01:00
{
[HarmonyPatch]
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]
[HarmonyPatch(typeof(NomaiInterfaceOrb), nameof(NomaiInterfaceOrb.StartDragFromPosition))]
2021-12-14 20:24:02 -08:00
public static void NomaiInterfaceOrb_StartDragFromPosition(NomaiInterfaceOrb __instance)
2020-12-02 21:29:53 +00:00
{
2021-12-14 20:24:02 -08:00
if (!WorldObjectManager.AllObjectsReady)
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-14 20:24:02 -08:00
if (!__instance._isBeingDragged)
{
return;
}
var qsbOrb = QSBWorldSync.GetWorldFromUnity<QSBOrb>(__instance);
QSBEventManager.FireEvent(EventNames.QSBOrbUser, qsbOrb, true);
2021-12-13 21:18:16 -08:00
}
2021-12-13 21:52:59 -08:00
[HarmonyPrefix]
2021-12-13 21:18:16 -08:00
[HarmonyPatch(typeof(NomaiInterfaceOrb), nameof(NomaiInterfaceOrb.CancelDrag))]
public static void NomaiInterfaceOrb_CancelDrag(NomaiInterfaceOrb __instance)
{
2021-12-14 20:24:02 -08:00
if (!WorldObjectManager.AllObjectsReady)
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-14 20:24:02 -08:00
if (!__instance._isBeingDragged)
{
return;
}
var qsbOrb = QSBWorldSync.GetWorldFromUnity<QSBOrb>(__instance);
QSBEventManager.FireEvent(EventNames.QSBOrbUser, qsbOrb, false);
2020-12-02 21:29:53 +00:00
}
2020-09-06 09:07:31 +01:00
[HarmonyPrefix]
[HarmonyPatch(typeof(NomaiInterfaceSlot), nameof(NomaiInterfaceSlot.CheckOrbCollision))]
2021-12-14 20:24:02 -08:00
public static bool NomaiInterfaceSlot_CheckOrbCollision(NomaiInterfaceSlot __instance, ref bool __result,
NomaiInterfaceOrb orb)
2020-12-02 21:29:53 +00:00
{
2021-12-14 20:24:02 -08:00
if (!WorldObjectManager.AllObjectsReady)
{
return true;
}
var qsbOrbSlot = QSBWorldSync.GetWorldFromUnity<QSBOrbSlot>(__instance);
var qsbOrb = QSBWorldSync.GetWorldFromUnity<QSBOrb>(orb);
if (!qsbOrb.TransformSync.HasAuthority)
{
return true;
}
if (__instance._ignoreDraggedOrbs && orb.IsBeingDragged())
2020-12-02 21:29:53 +00:00
{
__result = false;
return false;
}
2021-06-18 22:38:32 +01:00
2020-12-02 21:29:53 +00:00
var orbDistance = Vector3.Distance(orb.transform.position, __instance.transform.position);
2021-12-14 20:24:02 -08:00
var triggerRadius = orb.IsBeingDragged() ? __instance._exitRadius : __instance._radius;
if (__instance._occupyingOrb == null && orbDistance < __instance._radius)
2020-12-02 21:29:53 +00:00
{
2021-12-14 20:24:02 -08:00
__instance._occupyingOrb = orb;
2020-12-02 21:29:53 +00:00
if (Time.timeSinceLevelLoad > 1f)
{
2021-12-14 20:24:02 -08:00
__instance.RaiseEvent(nameof(__instance.OnSlotActivated), __instance);
QSBEventManager.FireEvent(EventNames.QSBOrbSlot, qsbOrbSlot, qsbOrb, true);
2020-12-02 21:29:53 +00:00
}
2021-06-18 22:38:32 +01:00
2020-12-02 21:29:53 +00:00
__result = true;
return false;
}
2021-06-18 22:38:32 +01:00
2021-12-14 20:24:02 -08:00
if (__instance._occupyingOrb == null || __instance._occupyingOrb != orb)
2020-12-02 21:29:53 +00:00
{
__result = false;
return false;
}
2021-06-18 22:38:32 +01:00
2020-12-02 21:29:53 +00:00
if (orbDistance > triggerRadius)
{
2021-12-14 20:24:02 -08:00
__instance._occupyingOrb = null;
__instance.RaiseEvent(nameof(__instance.OnSlotDeactivated), __instance);
QSBEventManager.FireEvent(EventNames.QSBOrbSlot, qsbOrbSlot, qsbOrb, false);
2020-12-02 21:29:53 +00:00
__result = false;
return false;
}
2021-06-18 22:38:32 +01:00
2020-12-02 21:29:53 +00:00
__result = true;
return false;
}
}
2021-12-13 22:22:19 -08:00
}