100 lines
2.6 KiB
C#
Raw Normal View History

using HarmonyLib;
2021-12-23 01:50:09 -08:00
using QSB.Messaging;
2021-12-23 02:17:56 -08:00
using QSB.OrbSync.Messages;
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;
using UnityEngine;
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
{
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
}
if (!__instance._isBeingDragged)
2021-12-14 20:24:02 -08:00
{
return;
}
var qsbOrb = __instance.GetWorldObject<QSBOrb>();
2021-12-23 01:50:09 -08:00
qsbOrb.SendMessage(new OrbDragMessage(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 bool CancelDrag(NomaiInterfaceOrb __instance)
2021-12-13 21:18:16 -08:00
{
if (!WorldObjectManager.AllObjectsReady)
2021-12-13 21:18:16 -08:00
{
return true;
2020-12-02 21:29:53 +00:00
}
if (!__instance._isBeingDragged)
2021-12-14 20:24:02 -08:00
{
return false;
2021-12-14 20:24:02 -08:00
}
var qsbOrb = __instance.GetWorldObject<QSBOrb>();
2021-12-14 23:57:21 -08:00
if (!qsbOrb.TransformSync.HasAuthority)
{
return false;
2021-12-14 23:57:21 -08:00
}
2021-12-23 01:50:09 -08:00
qsbOrb.SendMessage(new OrbDragMessage(false));
return true;
2020-12-02 21:29:53 +00:00
}
[HarmonyPrefix]
[HarmonyPatch(nameof(NomaiInterfaceOrb.CheckSlotCollision))]
public static bool CheckSlotCollision(NomaiInterfaceOrb __instance)
{
if (!WorldObjectManager.AllObjectsReady)
{
return true;
}
var qsbOrb = __instance.GetWorldObject<QSBOrb>();
if (!qsbOrb.TransformSync.HasAuthority)
{
return false;
}
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-23 01:50:09 -08:00
qsbOrb.SendMessage(new OrbSlotMessage(slotIndex));
break;
}
}
}
else if ((!__instance._occupiedSlot.IsAttractive() || __instance._isBeingDragged) && !__instance._occupiedSlot.CheckOrbCollision(__instance))
{
__instance._occupiedSlot = null;
2021-12-23 01:50:09 -08:00
qsbOrb.SendMessage(new OrbSlotMessage(-1));
}
__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
}