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;
|
2020-09-06 09:07:31 +01: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-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-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-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);
|
2021-12-14 23:57:21 -08:00
|
|
|
|
if (!qsbOrb.TransformSync.HasAuthority)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-12-14 20:24:02 -08:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBOrbUser, 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-14 23:57:21 -08:00
|
|
|
|
[HarmonyPatch(nameof(NomaiInterfaceOrb.CheckSlotCollision))]
|
|
|
|
|
public static bool CheckSlotCollision(NomaiInterfaceOrb __instance,
|
|
|
|
|
bool playAudio)
|
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-14 20:24:02 -08:00
|
|
|
|
if (!qsbOrb.TransformSync.HasAuthority)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-14 23:57:21 -08:00
|
|
|
|
if (__instance._occupiedSlot == null)
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
2021-12-14 23:57:21 -08:00
|
|
|
|
foreach (var slot in __instance._slots)
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
2021-12-14 23:57:21 -08:00
|
|
|
|
if (slot != null && slot.CheckOrbCollision(__instance))
|
|
|
|
|
{
|
|
|
|
|
__instance._occupiedSlot = slot;
|
|
|
|
|
__instance._enterSlotTime = Time.time;
|
|
|
|
|
if (slot.CancelsDragOnCollision())
|
|
|
|
|
{
|
|
|
|
|
__instance.CancelDrag();
|
|
|
|
|
}
|
|
|
|
|
if (playAudio && __instance._orbAudio != null && slot.GetPlayActivationAudio())
|
|
|
|
|
{
|
|
|
|
|
__instance._orbAudio.PlaySlotActivatedClip();
|
|
|
|
|
}
|
2021-12-15 00:10:35 -08:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBOrbSlot, qsbOrb, __instance._occupiedSlot, true, playAudio);
|
2021-12-14 23:57:21 -08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-14 23:57:21 -08:00
|
|
|
|
else if ((!__instance._occupiedSlot.IsAttractive() || __instance._isBeingDragged) && !__instance._occupiedSlot.CheckOrbCollision(__instance))
|
2020-12-02 21:29:53 +00:00
|
|
|
|
{
|
2021-12-15 00:10:35 -08:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBOrbSlot, qsbOrb, __instance._occupiedSlot, false, playAudio);
|
2021-12-14 23:57:21 -08:00
|
|
|
|
__instance._occupiedSlot = null;
|
2020-12-02 21:29:53 +00:00
|
|
|
|
}
|
2021-12-14 23:57:21 -08:00
|
|
|
|
__instance._owCollider.SetActivation(__instance._occupiedSlot == null || !__instance._occupiedSlot.IsAttractive() || __instance._isBeingDragged);
|
2021-06-18 22:38:32 +01:00
|
|
|
|
|
2020-12-02 21:29:53 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-13 22:22:19 -08:00
|
|
|
|
}
|