add forest patches

This commit is contained in:
Mister_Nebula 2021-12-29 18:12:07 +00:00
parent 1eb7ca4315
commit 30604faee8
2 changed files with 78 additions and 4 deletions

View File

@ -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;
}
}
}

View File

@ -21,6 +21,7 @@ namespace QSB.Tools.ProbeTool
private SingularityWarpEffect _warpEffect; private SingularityWarpEffect _warpEffect;
private bool _isRetrieving; private bool _isRetrieving;
private PlayerInfo _owner; private PlayerInfo _owner;
private bool _anchored;
public RulesetDetector GetRulesetDetector() public RulesetDetector GetRulesetDetector()
=> _rulesetDetector; => _rulesetDetector;
@ -56,6 +57,9 @@ namespace QSB.Tools.ProbeTool
public bool IsLaunched() public bool IsLaunched()
=> gameObject.activeSelf; => gameObject.activeSelf;
public bool IsAnchored()
=> IsLaunched() && _anchored;
public void HandleEvent(ProbeEvent probeEvent) public void HandleEvent(ProbeEvent probeEvent)
{ {
if (_owner == null) if (_owner == null)
@ -67,19 +71,23 @@ namespace QSB.Tools.ProbeTool
switch (probeEvent) switch (probeEvent)
{ {
case ProbeEvent.Launch: case ProbeEvent.Launch:
_anchored = false;
gameObject.SetActive(true);
transform.position = _owner.ProbeLauncher.transform.position;
transform.rotation = _owner.ProbeLauncher.transform.rotation;
if (OnLaunchProbe == null) if (OnLaunchProbe == null)
{ {
DebugLog.ToConsole($"Warning - OnLaunchProbe is null!", OWML.Common.MessageType.Warning); DebugLog.ToConsole($"Warning - OnLaunchProbe is null!", OWML.Common.MessageType.Warning);
break; break;
} }
gameObject.SetActive(true);
transform.position = _owner.ProbeLauncher.transform.position;
transform.rotation = _owner.ProbeLauncher.transform.rotation;
OnLaunchProbe(); OnLaunchProbe();
break; break;
case ProbeEvent.Anchor: case ProbeEvent.Anchor:
_anchored = true;
if (OnAnchorProbe == null) if (OnAnchorProbe == null)
{ {
DebugLog.ToConsole($"Warning - OnAnchorProbe is null!", OWML.Common.MessageType.Warning); DebugLog.ToConsole($"Warning - OnAnchorProbe is null!", OWML.Common.MessageType.Warning);
@ -89,9 +97,11 @@ namespace QSB.Tools.ProbeTool
OnAnchorProbe(); OnAnchorProbe();
break; break;
case ProbeEvent.Unanchor: case ProbeEvent.Unanchor:
_anchored = false;
OnUnanchorProbe(); OnUnanchorProbe();
break; break;
case ProbeEvent.Retrieve: case ProbeEvent.Retrieve:
_anchored = false;
if (OnRetrieveProbe == null) if (OnRetrieveProbe == null)
{ {
DebugLog.ToConsole($"Warning - OnRetrieveProbe is null!", OWML.Common.MessageType.Warning); DebugLog.ToConsole($"Warning - OnRetrieveProbe is null!", OWML.Common.MessageType.Warning);
@ -101,6 +111,7 @@ namespace QSB.Tools.ProbeTool
OnRetrieveProbe(); OnRetrieveProbe();
break; break;
case ProbeEvent.Destroy: case ProbeEvent.Destroy:
_anchored = false;
Destroy(gameObject); Destroy(gameObject);
if (OnProbeDestroyed == null) if (OnProbeDestroyed == null)