quantum-space-buddies/QSB/EyeOfTheUniverse/ForestOfGalaxies/Patches/ForestPatches.cs

89 lines
2.5 KiB
C#
Raw Normal View History

2021-12-29 18:12:07 +00:00
using HarmonyLib;
2021-12-30 11:41:59 +00:00
using QSB.EyeOfTheUniverse.ForestOfGalaxies.Messages;
using QSB.Messaging;
2021-12-29 18:12:07 +00:00
using QSB.Patches;
using QSB.Player;
2021-12-30 11:41:59 +00:00
using System.Collections.Generic;
2021-12-29 18:12:07 +00:00
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))
{
2021-12-30 15:35:40 +00:00
foreach (var player in QSBPlayerManager.PlayerList.Where(x => x.FlashlightActive))
2021-12-29 18:12:07 +00:00
{
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)
{
2021-12-30 15:35:40 +00:00
if (player == QSBPlayerManager.LocalPlayer
&& Locator.GetProbe() != null
&& Locator.GetProbe().IsAnchored())
2021-12-29 18:12:07 +00:00
{
var vector = Locator.GetProbe().transform.position - worldPosition;
vector.y = 0f;
if (vector.magnitude < 50f)
{
__result = true;
return false;
}
}
2021-12-30 15:35:40 +00:00
else if (player.Probe != null && player.Probe.IsAnchored())
2021-12-29 18:12:07 +00:00
{
var vector = player.ProbeBody.transform.position - worldPosition;
vector.y = 0f;
if (vector.magnitude < 50f)
{
__result = true;
return false;
}
}
}
}
2021-12-30 15:35:40 +00:00
__result = false;
2021-12-29 18:12:07 +00:00
return false;
}
2021-12-30 11:41:59 +00:00
[HarmonyPrefix]
[HarmonyPatch(typeof(MiniGalaxyController), nameof(MiniGalaxyController.KillGalaxies))]
public static bool KillGalaxiesReplacement(MiniGalaxyController __instance)
{
2021-12-31 02:28:24 +00:00
const float delay = 60f;
2021-12-30 11:41:59 +00:00
__instance._galaxies = __instance.GetComponentsInChildren<MiniGalaxy>(true);
var delayList = new List<float>();
2021-12-31 02:28:24 +00:00
foreach (var galaxy in __instance._galaxies)
2021-12-30 11:41:59 +00:00
{
2021-12-31 02:28:24 +00:00
var rnd = Random.Range(30f, delay);
2021-12-30 11:41:59 +00:00
delayList.Add(rnd);
2021-12-31 02:28:24 +00:00
galaxy.DieAfterSeconds(rnd, true, AudioType.EyeGalaxyBlowAway);
2021-12-30 11:41:59 +00:00
}
new KillGalaxiesMessage(delayList).Send();
2021-12-31 02:28:24 +00:00
__instance._forestIsDarkTime = Time.time + delay + 5f;
2021-12-30 11:41:59 +00:00
__instance.enabled = true;
return false;
}
2021-12-29 18:12:07 +00:00
}
}