48 lines
1.7 KiB
C#
Raw Normal View History

using HarmonyLib;
using QSB.Events;
using QSB.EyeOfTheUniverse.InstrumentSync.WorldObjects;
using QSB.Patches;
using QSB.WorldSync;
2021-12-24 15:27:36 +00:00
using UnityEngine;
2021-12-23 22:58:16 +00:00
namespace QSB.EyeOfTheUniverse.InstrumentSync.Patches
{
internal class QuantumInstrumentPatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPostfix]
2021-12-24 15:27:36 +00:00
[HarmonyPatch(typeof(QuantumInstrument), nameof(QuantumInstrument.OnPressInteract))]
public static void OnPressInteract(QuantumInstrument __instance)
=> QSBEventManager.FireEvent(EventNames.QSBGatherInstrument, QSBWorldSync.GetWorldFromUnity<QSBQuantumInstrument>(__instance));
2021-12-24 15:27:36 +00:00
[HarmonyPrefix]
[HarmonyPatch(typeof(QuantumInstrument), nameof(QuantumInstrument.Update))]
public static bool Update(QuantumInstrument __instance)
{
if (__instance._gatherWithScope && !__instance._waitToFlickerOut)
{
__instance._scopeGatherPrompt.SetVisibility(false);
if (Locator.GetToolModeSwapper().GetSignalScope().InZoomMode()
&& Vector3.Angle(__instance.transform.position - Locator.GetPlayerCamera().transform.position, Locator.GetPlayerCamera().transform.forward) < 1f)
{
__instance._scopeGatherPrompt.SetVisibility(true);
if (OWInput.IsNewlyPressed(InputLibrary.interact, InputMode.All))
{
__instance.Gather();
QSBEventManager.FireEvent(EventNames.QSBGatherInstrument, QSBWorldSync.GetWorldFromUnity<QSBQuantumInstrument>(__instance));
Locator.GetPromptManager().RemoveScreenPrompt(__instance._scopeGatherPrompt);
}
}
}
if (__instance._waitToFlickerOut && Time.time > __instance._flickerOutTime)
{
__instance.FinishGather();
}
return false;
}
}
}