diff --git a/NewHorizons/Handlers/SupernovaEffectHandler.cs b/NewHorizons/Handlers/SupernovaEffectHandler.cs index 900471fd..6d4c84c7 100644 --- a/NewHorizons/Handlers/SupernovaEffectHandler.cs +++ b/NewHorizons/Handlers/SupernovaEffectHandler.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using UnityEngine; namespace NewHorizons.Handlers { @@ -85,6 +86,25 @@ namespace NewHorizons.Handlers public static SunController GetSunController() => _sunController; - public static bool InPointInsideSunSupernova(NHSupernovaPlanetEffectController supernovaPlanetEffectController) => _sunController != null && (supernovaPlanetEffectController.transform.position - _sunController.transform.position).sqrMagnitude < 2500000000f;//(50000f*50000f); + public static bool InPointInsideAnySupernova(Vector3 position) + { + foreach (StarEvolutionController starEvolutionController in _starEvolutionControllers) + { + if (starEvolutionController == null) continue; + if (!(starEvolutionController.gameObject.activeSelf && starEvolutionController.gameObject.activeInHierarchy)) continue; + float distance = (position - starEvolutionController.transform.position).sqrMagnitude; + float size = starEvolutionController.GetSupernovaRadius(); + if (distance < (size * size)) return true; + } + + if (_sunController != null && _sunController.gameObject.activeSelf) + { + float distance = (position - _sunController.transform.position).sqrMagnitude; + float size = _sunController.GetSupernovaRadius(); + if (distance < (size * size)) return true; + } + + return false; + } } } diff --git a/NewHorizons/Patches/ProxyBodyPatches.cs b/NewHorizons/Patches/ProxyBodyPatches.cs index 804c6682..79864610 100644 --- a/NewHorizons/Patches/ProxyBodyPatches.cs +++ b/NewHorizons/Patches/ProxyBodyPatches.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NewHorizons.Handlers; using NewHorizons.Utility; using System; using System.Runtime.CompilerServices; @@ -34,6 +35,14 @@ namespace NewHorizons.Patches __instance._outOfRange = false; } + [HarmonyPrefix] + [HarmonyPatch(typeof(ProxyBody), nameof(ProxyBody.IsObjectInSupernova))] + public static bool ProxyBody_IsObjectInSupernova(ProxyBody __instance, ref bool __result) + { + __result = SupernovaEffectHandler.InPointInsideAnySupernova(__instance._realObjectTransform.position); + return false; + } + // Mobius why doesn't ProxyOrbiter inherit from ProxyBody [HarmonyPrefix] [HarmonyPatch(typeof(ProxyOrbiter), nameof(ProxyOrbiter.Awake))]