84 lines
2.3 KiB
C#
Raw Normal View History

using HarmonyLib;
using QSB.Events;
2020-12-14 20:31:31 +01:00
using QSB.Patches;
using QSB.Utility;
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-06-18 21:54:32 +01:00
public static void NomaiInterfaceOrb_StartDragFromPosition(bool __result, NomaiInterfaceOrb __instance)
2020-12-02 21:29:53 +00:00
{
if (__result)
{
2021-12-13 21:18:16 -08:00
var index = OrbManager.Orbs.IndexOf(__instance);
if (index != -1)
{
QSBEventManager.FireEvent(EventNames.QSBOrbUser, index, true);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(NomaiInterfaceOrb), nameof(NomaiInterfaceOrb.CancelDrag))]
public static void NomaiInterfaceOrb_CancelDrag(NomaiInterfaceOrb __instance)
{
var index = OrbManager.Orbs.IndexOf(__instance);
if (index != -1)
{
QSBEventManager.FireEvent(EventNames.QSBOrbUser, index, 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-06-18 21:54:32 +01:00
public static bool NomaiInterfaceSlot_CheckOrbCollision(ref bool __result, NomaiInterfaceSlot __instance, NomaiInterfaceOrb orb,
2020-12-02 21:29:53 +00:00
bool ____ignoreDraggedOrbs, float ____radius, float ____exitRadius, ref NomaiInterfaceOrb ____occupyingOrb)
{
if (____ignoreDraggedOrbs && orb.IsBeingDragged())
{
__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);
var triggerRadius = orb.IsBeingDragged() ? ____exitRadius : ____radius;
if (____occupyingOrb == null && orbDistance < ____radius)
{
____occupyingOrb = orb;
if (Time.timeSinceLevelLoad > 1f)
{
2021-12-13 21:18:16 -08:00
OrbManager.HandleSlotStateChange(__instance, orb, true);
__instance.RaiseEvent("OnSlotActivated", __instance);
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
2020-12-02 21:29:53 +00:00
if (____occupyingOrb == null || ____occupyingOrb != orb)
{
__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-13 21:18:16 -08:00
OrbManager.HandleSlotStateChange(__instance, orb, false);
2020-12-02 21:29:53 +00:00
____occupyingOrb = null;
2021-07-07 09:02:23 +01:00
__instance.RaiseEvent("OnSlotDeactivated", __instance);
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;
}
}
2020-12-03 08:28:05 +00:00
}