fix gathering instruments

This commit is contained in:
Mister_Nebula 2021-12-24 15:27:36 +00:00
parent 96fd427bfb
commit 41972f232e

View File

@ -3,6 +3,7 @@ using QSB.Events;
using QSB.EyeOfTheUniverse.InstrumentSync.WorldObjects;
using QSB.Patches;
using QSB.WorldSync;
using UnityEngine;
namespace QSB.EyeOfTheUniverse.InstrumentSync.Patches
{
@ -11,8 +12,36 @@ namespace QSB.EyeOfTheUniverse.InstrumentSync.Patches
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPostfix]
[HarmonyPatch(typeof(QuantumInstrument), nameof(QuantumInstrument.Gather))]
public static void Gather(QuantumInstrument __instance)
[HarmonyPatch(typeof(QuantumInstrument), nameof(QuantumInstrument.OnPressInteract))]
public static void OnPressInteract(QuantumInstrument __instance)
=> QSBEventManager.FireEvent(EventNames.QSBGatherInstrument, QSBWorldSync.GetWorldFromUnity<QSBQuantumInstrument>(__instance));
[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;
}
}
}