47 lines
1.6 KiB
C#
Raw Normal View History

using HarmonyLib;
2021-12-24 20:37:42 -08:00
using QSB.EyeOfTheUniverse.InstrumentSync.Messages;
using QSB.EyeOfTheUniverse.InstrumentSync.WorldObjects;
2021-12-24 20:37:42 -08:00
using QSB.Messaging;
using QSB.Patches;
using QSB.WorldSync;
2021-12-24 15:27:36 +00:00
using UnityEngine;
2021-12-23 22:58:16 +00:00
2022-03-02 19:46:33 -08:00
namespace QSB.EyeOfTheUniverse.InstrumentSync.Patches;
2023-07-28 19:30:57 +01:00
public class QuantumInstrumentPatches : QSBPatch
{
2022-03-02 19:46:33 -08:00
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
2022-03-02 19:46:33 -08:00
[HarmonyPostfix]
[HarmonyPatch(typeof(QuantumInstrument), nameof(QuantumInstrument.OnPressInteract))]
public static void OnPressInteract(QuantumInstrument __instance)
=> __instance.GetWorldObject<QSBQuantumInstrument>().SendMessage(new GatherInstrumentMessage());
2021-12-24 15:27:36 +00:00
2022-03-02 19:46:33 -08:00
[HarmonyPrefix]
[HarmonyPatch(typeof(QuantumInstrument), nameof(QuantumInstrument.Update))]
public static bool Update(QuantumInstrument __instance)
{
if (__instance._gatherWithScope && !__instance._waitToFlickerOut)
2021-12-24 15:27:36 +00:00
{
2022-03-02 19:46:33 -08:00
__instance._scopeGatherPrompt.SetVisibility(false);
if (Locator.GetToolModeSwapper().GetSignalScope().InZoomMode()
&& Vector3.Angle(__instance.transform.position - Locator.GetPlayerCamera().transform.position, Locator.GetPlayerCamera().transform.forward) < 1f)
2021-12-24 15:27:36 +00:00
{
2022-03-02 19:46:33 -08:00
__instance._scopeGatherPrompt.SetVisibility(true);
if (OWInput.IsNewlyPressed(InputLibrary.interact))
2021-12-24 15:27:36 +00:00
{
2022-03-02 19:46:33 -08:00
__instance.Gather();
__instance.GetWorldObject<QSBQuantumInstrument>().SendMessage(new GatherInstrumentMessage());
Locator.GetPromptManager().RemoveScreenPrompt(__instance._scopeGatherPrompt);
2021-12-24 15:27:36 +00:00
}
}
2022-03-02 19:46:33 -08:00
}
2021-12-24 15:27:36 +00:00
2022-03-02 19:46:33 -08:00
if (__instance._waitToFlickerOut && Time.time > __instance._flickerOutTime)
{
__instance.FinishGather();
}
2022-03-02 19:46:33 -08:00
return false;
}
}