Make methods for following up on destruction

This commit is contained in:
Nick 2023-08-14 16:42:33 -04:00
parent aae7afc26b
commit 6c4d8a3bfc

View File

@ -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 // force call update here to make it switch to an active star. idk why we didnt have to do this before
SunLightEffectsController.Instance.Update(); 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(); StrangerRemoved();
TimberHearthRemoved();
// Don't forget to fix THE WARP BUG SunRemoved();
DisableBody(SearchUtilities.Find("StreamingGroup_TH"), true);
}, 2); // Have to wait or shit goes wild }, 2); // Have to wait or shit goes wild
foreach (var streamingAssetBundle in StreamingManager.s_activeBundles) foreach (var streamingAssetBundle in StreamingManager.s_activeBundles)
@ -119,11 +118,6 @@ namespace NewHorizons.Handlers
{ {
NHLogger.LogVerbose($"Removing [{ao.name}]"); NHLogger.LogVerbose($"Removing [{ao.name}]");
if (ao.GetAstroObjectName() == AstroObject.Name.RingWorld)
{
StrangerRemoved();
}
if (ao.gameObject == null || !ao.gameObject.activeInHierarchy) if (ao.gameObject == null || !ao.gameObject.activeInHierarchy)
{ {
NHLogger.LogVerbose($"[{ao.name}] was already removed"); NHLogger.LogVerbose($"[{ao.name}] was already removed");
@ -153,63 +147,31 @@ namespace NewHorizons.Handlers
DisableBody(fragment.gameObject, delete); DisableBody(fragment.gameObject, delete);
} }
break; break;
case AstroObject.Name.CaveTwin: case AstroObject.Name.CaveTwin:
case AstroObject.Name.TowerTwin: case AstroObject.Name.TowerTwin:
DisableBody(SearchUtilities.Find("FocalBody"), delete); DisableBody(SearchUtilities.Find("FocalBody"), delete);
DisableBody(SearchUtilities.Find("SandFunnel_Body", false), delete); DisableBody(SearchUtilities.Find("SandFunnel_Body", false), delete);
break; break;
case AstroObject.Name.GiantsDeep: case AstroObject.Name.GiantsDeep:
// Might prevent leftover jellyfish from existing // Might prevent leftover jellyfish from existing
// Might also prevent people from using their own jellyfish however // 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<JellyfishController>()) foreach (var jelly in UnityEngine.Object.FindObjectsOfType<JellyfishController>())
{ {
DisableBody(jelly.gameObject, delete); DisableBody(jelly.gameObject, delete);
} }
// Else it will re-eanble the pieces
// ao.GetComponent<OrbitalProbeLaunchController>()._realDebrisSectorProxies = null;
break; break;
case AstroObject.Name.TimberHearth: case AstroObject.Name.TimberHearth:
// Always just fucking kill this one to stop THE WARP BUG!!! TimberHearthRemoved();
DisableBody(SearchUtilities.Find("StreamingGroup_TH"), true);
foreach (var obj in UnityEngine.Object.FindObjectsOfType<DayNightTracker>())
{
DisableBody(obj.gameObject, true);
}
foreach (var obj in UnityEngine.Object.FindObjectsOfType<VillageMusicVolume>())
{
DisableBody(obj.gameObject, true);
}
break; break;
case AstroObject.Name.Sun: case AstroObject.Name.Sun:
var starController = ao.gameObject.GetComponent<StarController>(); SunRemoved();
SunLightEffectsController.RemoveStar(starController); break;
SunLightEffectsController.RemoveStarLight(ao.transform.Find("Sector_SUN/Effects_SUN/SunLight").GetComponent<Light>()); case AstroObject.Name.RingWorld:
UnityEngine.Object.Destroy(starController); StrangerRemoved();
var audio = ao.GetComponentInChildren<SunSurfaceAudioController>();
UnityEngine.Object.Destroy(audio);
foreach (var owAudioSource in ao.GetComponentsInChildren<OWAudioSource>())
{
owAudioSource.Stop();
UnityEngine.Object.Destroy(owAudioSource);
}
foreach (var audioSource in ao.GetComponentsInChildren<AudioSource>())
{
audioSource.Stop();
UnityEngine.Object.Destroy(audioSource);
}
foreach (var sunProxy in UnityEngine.Object.FindObjectsOfType<SunProxy>())
{
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<SunController>().OnTriggerSupernova);
break; break;
} }
@ -244,6 +206,7 @@ namespace NewHorizons.Handlers
} }
// Deal with proxies // Deal with proxies
// TODO: There has to be a better way of doing this
foreach (var p in UnityEngine.Object.FindObjectsOfType<ProxyOrbiter>()) foreach (var p in UnityEngine.Object.FindObjectsOfType<ProxyOrbiter>())
{ {
if (p._originalBody == ao.gameObject) if (p._originalBody == ao.gameObject)
@ -265,6 +228,56 @@ namespace NewHorizons.Handlers
} }
} }
private static void SunRemoved()
{
var sun = SearchUtilities.Find("Sun_Body").GetComponent<AstroObject>();
var starController = sun.gameObject.GetComponent<StarController>();
SunLightEffectsController.RemoveStar(starController);
SunLightEffectsController.RemoveStarLight(sun.transform.Find("Sector_SUN/Effects_SUN/SunLight").GetComponent<Light>());
UnityEngine.Object.Destroy(starController);
var audio = sun.GetComponentInChildren<SunSurfaceAudioController>();
UnityEngine.Object.Destroy(audio);
foreach (var owAudioSource in sun.GetComponentsInChildren<OWAudioSource>())
{
owAudioSource.Stop();
UnityEngine.Object.Destroy(owAudioSource);
}
foreach (var audioSource in sun.GetComponentsInChildren<AudioSource>())
{
audioSource.Stop();
UnityEngine.Object.Destroy(audioSource);
}
foreach (var sunProxy in UnityEngine.Object.FindObjectsOfType<SunProxy>())
{
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<SunController>().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<DayNightTracker>())
{
DisableBody(obj.gameObject, true);
}
foreach (var obj in UnityEngine.Object.FindObjectsOfType<VillageMusicVolume>())
{
DisableBody(obj.gameObject, true);
}
}
public static void RemoveAllProxies() public static void RemoveAllProxies()
{ {
UnityEngine.Object.Destroy(UnityEngine.Object.FindObjectOfType<DistantProxyManager>().gameObject); UnityEngine.Object.Destroy(UnityEngine.Object.FindObjectOfType<DistantProxyManager>().gameObject);