From 6c4d8a3bfcac305f6f93c1a4c0fe56247af1a726 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 14 Aug 2023 16:42:33 -0400 Subject: [PATCH] Make methods for following up on destruction --- .../Handlers/PlanetDestructionHandler.cs | 113 ++++++++++-------- 1 file changed, 63 insertions(+), 50 deletions(-) diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index e8377893..06688680 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -82,11 +82,10 @@ namespace NewHorizons.Handlers // force call update here to make it switch to an active star. idk why we didnt have to do this before SunLightEffectsController.Instance.Update(); - // Since we didn't call RemoveBody on the Stranger have to call this here + // Since we didn't call RemoveBody on the all planets there are some we have to call here StrangerRemoved(); - - // Don't forget to fix THE WARP BUG - DisableBody(SearchUtilities.Find("StreamingGroup_TH"), true); + TimberHearthRemoved(); + SunRemoved(); }, 2); // Have to wait or shit goes wild foreach (var streamingAssetBundle in StreamingManager.s_activeBundles) @@ -119,11 +118,6 @@ namespace NewHorizons.Handlers { NHLogger.LogVerbose($"Removing [{ao.name}]"); - if (ao.GetAstroObjectName() == AstroObject.Name.RingWorld) - { - StrangerRemoved(); - } - if (ao.gameObject == null || !ao.gameObject.activeInHierarchy) { NHLogger.LogVerbose($"[{ao.name}] was already removed"); @@ -153,63 +147,31 @@ namespace NewHorizons.Handlers DisableBody(fragment.gameObject, delete); } break; + case AstroObject.Name.CaveTwin: case AstroObject.Name.TowerTwin: DisableBody(SearchUtilities.Find("FocalBody"), delete); DisableBody(SearchUtilities.Find("SandFunnel_Body", false), delete); break; + case AstroObject.Name.GiantsDeep: // Might prevent leftover jellyfish from existing // Might also prevent people from using their own jellyfish however + + // TODO: Make this only affect those on GD? foreach (var jelly in UnityEngine.Object.FindObjectsOfType()) { DisableBody(jelly.gameObject, delete); } - // Else it will re-eanble the pieces - // ao.GetComponent()._realDebrisSectorProxies = null; break; case AstroObject.Name.TimberHearth: - // Always just fucking kill this one to stop THE WARP BUG!!! - DisableBody(SearchUtilities.Find("StreamingGroup_TH"), true); - - foreach (var obj in UnityEngine.Object.FindObjectsOfType()) - { - DisableBody(obj.gameObject, true); - } - foreach (var obj in UnityEngine.Object.FindObjectsOfType()) - { - DisableBody(obj.gameObject, true); - } + TimberHearthRemoved(); break; case AstroObject.Name.Sun: - var starController = ao.gameObject.GetComponent(); - SunLightEffectsController.RemoveStar(starController); - SunLightEffectsController.RemoveStarLight(ao.transform.Find("Sector_SUN/Effects_SUN/SunLight").GetComponent()); - UnityEngine.Object.Destroy(starController); - - var audio = ao.GetComponentInChildren(); - UnityEngine.Object.Destroy(audio); - - foreach (var owAudioSource in ao.GetComponentsInChildren()) - { - owAudioSource.Stop(); - UnityEngine.Object.Destroy(owAudioSource); - } - - foreach (var audioSource in ao.GetComponentsInChildren()) - { - audioSource.Stop(); - UnityEngine.Object.Destroy(audioSource); - } - - foreach (var sunProxy in UnityEngine.Object.FindObjectsOfType()) - { - NHLogger.LogVerbose($"Destroying SunProxy {sunProxy.gameObject.name}"); - UnityEngine.Object.Destroy(sunProxy.gameObject); - } - - // Stop the sun from breaking stuff when the supernova gets triggered - GlobalMessenger.RemoveListener("TriggerSupernova", ao.GetComponent().OnTriggerSupernova); + SunRemoved(); + break; + case AstroObject.Name.RingWorld: + StrangerRemoved(); break; } @@ -244,6 +206,7 @@ namespace NewHorizons.Handlers } // Deal with proxies + // TODO: There has to be a better way of doing this foreach (var p in UnityEngine.Object.FindObjectsOfType()) { if (p._originalBody == ao.gameObject) @@ -265,6 +228,56 @@ namespace NewHorizons.Handlers } } + private static void SunRemoved() + { + var sun = SearchUtilities.Find("Sun_Body").GetComponent(); + + var starController = sun.gameObject.GetComponent(); + SunLightEffectsController.RemoveStar(starController); + SunLightEffectsController.RemoveStarLight(sun.transform.Find("Sector_SUN/Effects_SUN/SunLight").GetComponent()); + UnityEngine.Object.Destroy(starController); + + var audio = sun.GetComponentInChildren(); + UnityEngine.Object.Destroy(audio); + + foreach (var owAudioSource in sun.GetComponentsInChildren()) + { + owAudioSource.Stop(); + UnityEngine.Object.Destroy(owAudioSource); + } + + foreach (var audioSource in sun.GetComponentsInChildren()) + { + audioSource.Stop(); + UnityEngine.Object.Destroy(audioSource); + } + + foreach (var sunProxy in UnityEngine.Object.FindObjectsOfType()) + { + NHLogger.LogVerbose($"Destroying SunProxy {sunProxy.gameObject.name}"); + UnityEngine.Object.Destroy(sunProxy.gameObject); + } + + // Stop the sun from breaking stuff when the supernova gets triggered + GlobalMessenger.RemoveListener("TriggerSupernova", sun.GetComponent().OnTriggerSupernova); + } + + private static void TimberHearthRemoved() + { + // Always just fucking kill this one to stop THE WARP BUG!!! + DisableBody(SearchUtilities.Find("StreamingGroup_TH"), true); + + // TODO: These should only destroy those that are on TH + foreach (var obj in UnityEngine.Object.FindObjectsOfType()) + { + DisableBody(obj.gameObject, true); + } + foreach (var obj in UnityEngine.Object.FindObjectsOfType()) + { + DisableBody(obj.gameObject, true); + } + } + public static void RemoveAllProxies() { UnityEngine.Object.Destroy(UnityEngine.Object.FindObjectOfType().gameObject);