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

119 lines
3.7 KiB
C#
Raw Permalink 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;
2022-03-03 03:46:33 +00:00
namespace QSB.EyeOfTheUniverse.ForestOfGalaxies.Patches;
2023-07-28 18:30:57 +00:00
public class ForestPatches : QSBPatch
2021-12-29 18:12:07 +00:00
{
2022-03-03 03:46:33 +00:00
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPrefix]
[HarmonyPatch(typeof(OldGrowthForestController), nameof(OldGrowthForestController.CheckIllumination))]
public static bool CheckIlluminationReplacement(Vector3 worldPosition, out bool __result)
2021-12-29 18:12:07 +00:00
{
2022-03-03 03:46:33 +00:00
if (Locator.GetFlashlight().IsFlashlightOn() || QSBPlayerManager.PlayerList.Any(x => x.FlashlightActive))
{
foreach (var player in QSBPlayerManager.PlayerList.Where(x => x.FlashlightActive))
{
var vector = player.Body.transform.position - worldPosition;
vector.y = 0f;
if (vector.magnitude < 50f)
{
__result = true;
return false;
}
}
}
2021-12-29 18:12:07 +00:00
2022-03-03 03:46:33 +00:00
if ((Locator.GetProbe() != null && Locator.GetProbe().IsAnchored())
|| QSBPlayerManager.PlayerList.Where(x => !x.IsLocalPlayer).Any(x => x.Probe != null && x.Probe.IsAnchored()))
2021-12-29 18:12:07 +00:00
{
2022-03-03 03:46:33 +00:00
foreach (var player in QSBPlayerManager.PlayerList)
2021-12-29 18:12:07 +00:00
{
2022-03-03 03:46:33 +00:00
if (player.IsLocalPlayer
&& Locator.GetProbe() != null
&& Locator.GetProbe().IsAnchored())
2021-12-29 18:12:07 +00:00
{
2022-03-03 03:46:33 +00:00
var vector = Locator.GetProbe().transform.position - worldPosition;
2021-12-29 18:12:07 +00:00
vector.y = 0f;
if (vector.magnitude < 50f)
{
__result = true;
return false;
}
}
2022-03-03 03:46:33 +00:00
else if (player.Probe != null && player.Probe.IsAnchored())
2021-12-29 18:12:07 +00:00
{
2022-03-03 03:46:33 +00:00
var vector = player.ProbeBody.transform.position - worldPosition;
vector.y = 0f;
if (vector.magnitude < 50f)
{
2022-03-03 03:46:33 +00:00
__result = true;
return false;
2021-12-29 18:12:07 +00:00
}
}
}
}
2022-01-01 22:19:10 +00:00
2022-03-03 03:46:33 +00:00
__result = false;
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(MiniGalaxyController), nameof(MiniGalaxyController.KillGalaxies))]
public static bool KillGalaxiesReplacement(MiniGalaxyController __instance)
{
const float delay = 60f;
__instance._galaxies = __instance.GetComponentsInChildren<MiniGalaxy>(true);
var delayList = new List<float>();
foreach (var galaxy in __instance._galaxies)
{
2022-03-03 03:46:33 +00:00
var rnd = Random.Range(30f, delay);
delayList.Add(rnd);
galaxy.DieAfterSeconds(rnd, true, AudioType.EyeGalaxyBlowAway);
}
2021-12-30 11:41:59 +00:00
2022-03-03 03:46:33 +00:00
new KillGalaxiesMessage(delayList).Send();
__instance._forestIsDarkTime = Time.time + delay + 5f;
__instance.enabled = true;
2021-12-31 05:17:59 +00:00
2022-03-03 03:46:33 +00:00
return false;
}
2022-01-01 22:19:10 +00:00
2022-03-03 03:46:33 +00:00
[HarmonyPrefix]
[HarmonyPatch(typeof(PlayerCloneController), nameof(PlayerCloneController.FixedUpdate))]
public static bool CloneFixedUpdate(PlayerCloneController __instance)
{
var playerTransform = Locator.GetPlayerTransform();
var vector = __instance.transform.parent.InverseTransformPoint(playerTransform.position);
var b = __instance._localMirrorPos - vector;
var position = __instance._localMirrorPos + b;
position.y = vector.y;
__instance.transform.position = __instance.transform.parent.TransformPoint(position);
var normalized = (__instance.transform.position - playerTransform.position).normalized;
var forward = Vector3.Reflect(playerTransform.forward, normalized);
var upwards = Vector3.Reflect(playerTransform.up, normalized);
__instance.transform.rotation = Quaternion.LookRotation(forward, upwards);
var num = Vector3.Distance(__instance.transform.position, playerTransform.position);
if (!__instance._warpFlickerActivated && num < 10f)
{
2022-03-03 03:46:33 +00:00
__instance._warpFlickerActivated = true;
__instance._warpTime = Time.time + 0.5f;
GlobalMessenger<float, float>.FireEvent(OWEvents.FlickerOffAndOn, 0.5f, 0.5f);
new EyeCloneSeenMessage().Send();
}
2022-03-03 03:46:33 +00:00
if (__instance._warpPlayerNextFrame)
{
__instance.WarpPlayerToCampfire();
}
2022-03-03 03:46:33 +00:00
return false;
2021-12-29 18:12:07 +00:00
}
}