From 30604faee8fecb64a4e765b782c9a70e097af90d Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 29 Dec 2021 18:12:07 +0000 Subject: [PATCH] add forest patches --- .../ForestOfGalaxies/Patches/ForestPatches.cs | 63 +++++++++++++++++++ QSB/Tools/ProbeTool/QSBProbe.cs | 19 ++++-- 2 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 QSB/EyeOfTheUniverse/ForestOfGalaxies/Patches/ForestPatches.cs diff --git a/QSB/EyeOfTheUniverse/ForestOfGalaxies/Patches/ForestPatches.cs b/QSB/EyeOfTheUniverse/ForestOfGalaxies/Patches/ForestPatches.cs new file mode 100644 index 00000000..8e4de694 --- /dev/null +++ b/QSB/EyeOfTheUniverse/ForestOfGalaxies/Patches/ForestPatches.cs @@ -0,0 +1,63 @@ +using HarmonyLib; +using QSB.Patches; +using QSB.Player; +using System.Linq; +using UnityEngine; + +namespace QSB.EyeOfTheUniverse.ForestOfGalaxies.Patches +{ + internal class ForestPatches : QSBPatch + { + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + [HarmonyPrefix] + [HarmonyPatch(typeof(OldGrowthForestController), nameof(OldGrowthForestController.CheckIllumination))] + public static bool CheckIlluminationReplacement(Vector3 worldPosition, ref bool __result) + { + if (Locator.GetFlashlight().IsFlashlightOn() || QSBPlayerManager.PlayerList.Any(x => x.FlashlightActive)) + { + foreach (var player in QSBPlayerManager.PlayerList) + { + var vector = player.Body.transform.position - worldPosition; + vector.y = 0f; + if (vector.magnitude < 50f) + { + __result = true; + return false; + } + } + } + + if ((Locator.GetProbe() != null && Locator.GetProbe().IsAnchored()) + || QSBPlayerManager.PlayerList.Where(x => x != QSBPlayerManager.LocalPlayer).Any(x => x.Probe != null && x.Probe.IsAnchored())) + { + foreach (var player in QSBPlayerManager.PlayerList) + { + if (player == QSBPlayerManager.LocalPlayer) + { + var vector = Locator.GetProbe().transform.position - worldPosition; + vector.y = 0f; + if (vector.magnitude < 50f) + { + __result = true; + return false; + } + } + else + { + var vector = player.ProbeBody.transform.position - worldPosition; + vector.y = 0f; + if (vector.magnitude < 50f) + { + __result = true; + return false; + } + } + } + } + + __result = true; + return false; + } + } +} diff --git a/QSB/Tools/ProbeTool/QSBProbe.cs b/QSB/Tools/ProbeTool/QSBProbe.cs index 4c5f43b6..3eb18542 100644 --- a/QSB/Tools/ProbeTool/QSBProbe.cs +++ b/QSB/Tools/ProbeTool/QSBProbe.cs @@ -21,6 +21,7 @@ namespace QSB.Tools.ProbeTool private SingularityWarpEffect _warpEffect; private bool _isRetrieving; private PlayerInfo _owner; + private bool _anchored; public RulesetDetector GetRulesetDetector() => _rulesetDetector; @@ -56,6 +57,9 @@ namespace QSB.Tools.ProbeTool public bool IsLaunched() => gameObject.activeSelf; + public bool IsAnchored() + => IsLaunched() && _anchored; + public void HandleEvent(ProbeEvent probeEvent) { if (_owner == null) @@ -67,19 +71,23 @@ namespace QSB.Tools.ProbeTool switch (probeEvent) { case ProbeEvent.Launch: + _anchored = false; + + gameObject.SetActive(true); + transform.position = _owner.ProbeLauncher.transform.position; + transform.rotation = _owner.ProbeLauncher.transform.rotation; + if (OnLaunchProbe == null) { DebugLog.ToConsole($"Warning - OnLaunchProbe is null!", OWML.Common.MessageType.Warning); break; } - gameObject.SetActive(true); - transform.position = _owner.ProbeLauncher.transform.position; - transform.rotation = _owner.ProbeLauncher.transform.rotation; - OnLaunchProbe(); break; case ProbeEvent.Anchor: + _anchored = true; + if (OnAnchorProbe == null) { DebugLog.ToConsole($"Warning - OnAnchorProbe is null!", OWML.Common.MessageType.Warning); @@ -89,9 +97,11 @@ namespace QSB.Tools.ProbeTool OnAnchorProbe(); break; case ProbeEvent.Unanchor: + _anchored = false; OnUnanchorProbe(); break; case ProbeEvent.Retrieve: + _anchored = false; if (OnRetrieveProbe == null) { DebugLog.ToConsole($"Warning - OnRetrieveProbe is null!", OWML.Common.MessageType.Warning); @@ -101,6 +111,7 @@ namespace QSB.Tools.ProbeTool OnRetrieveProbe(); break; case ProbeEvent.Destroy: + _anchored = false; Destroy(gameObject); if (OnProbeDestroyed == null)