70 lines
1.8 KiB
C#
Raw Normal View History

2020-12-14 16:24:52 +00:00
using QSB.Events;
2020-12-14 20:31:31 +01:00
using QSB.Patches;
using QSB.Utility;
2021-07-07 09:02:23 +01: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
{
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-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-02-10 19:34:41 +00:00
QSBEventManager.FireEvent(EventNames.QSBOrbUser, QSBWorldSync.OldOrbList.FindIndex(x => x == __instance));
2020-12-02 21:29:53 +00:00
}
}
2020-09-06 09:07:31 +01:00
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)
{
2020-12-11 13:14:58 +00:00
QSBWorldSync.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)
{
2020-12-11 13:14:58 +00:00
QSBWorldSync.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-09-07 20:27:56 +02:00
2020-12-02 21:29:53 +00:00
public override void DoPatches()
{
2021-06-18 21:54:32 +01:00
Postfix(nameof(NomaiInterfaceOrb_StartDragFromPosition));
Prefix(nameof(NomaiInterfaceSlot_CheckOrbCollision));
2021-02-09 17:18:01 +00:00
}
2020-12-02 21:29:53 +00:00
}
2020-12-03 08:28:05 +00:00
}