mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Avoid NRE in planet destruction (Fixes #116)
This commit is contained in:
parent
31592a042b
commit
10d9556b79
@ -69,28 +69,28 @@ namespace NewHorizons.Handlers
|
||||
|
||||
try
|
||||
{
|
||||
if (ao.GetAstroObjectName() == AstroObject.Name.BrittleHollow)
|
||||
switch(ao._name)
|
||||
{
|
||||
case AstroObject.Name.BrittleHollow:
|
||||
RemoveBody(AstroObjectLocator.GetAstroObject(AstroObject.Name.WhiteHole.ToString()), delete, toDestroy);
|
||||
}
|
||||
else if (ao.GetAstroObjectName() == AstroObject.Name.CaveTwin || ao.GetAstroObjectName() == AstroObject.Name.TowerTwin)
|
||||
{
|
||||
break;
|
||||
case AstroObject.Name.CaveTwin:
|
||||
case AstroObject.Name.TowerTwin:
|
||||
DisableBody(GameObject.Find("FocalBody"), delete);
|
||||
DisableBody(GameObject.Find("SandFunnel_Body"), delete);
|
||||
}
|
||||
else if (ao.GetAstroObjectName() == AstroObject.Name.MapSatellite)
|
||||
{
|
||||
break;
|
||||
case AstroObject.Name.MapSatellite:
|
||||
DisableBody(GameObject.Find("MapSatellite_Body"), delete);
|
||||
}
|
||||
else if (ao.GetAstroObjectName() == AstroObject.Name.GiantsDeep)
|
||||
{
|
||||
break;
|
||||
case AstroObject.Name.GiantsDeep:
|
||||
foreach (var jelly in GameObject.FindObjectsOfType<JellyfishController>())
|
||||
{
|
||||
DisableBody(jelly.gameObject, delete);
|
||||
}
|
||||
}
|
||||
else if (ao.GetAstroObjectName() == AstroObject.Name.TimberHearth)
|
||||
{
|
||||
// Else it will re-eanble the pieces
|
||||
// ao.GetComponent<OrbitalProbeLaunchController>()._realDebrisSectorProxies = null;
|
||||
break;
|
||||
case AstroObject.Name.TimberHearth:
|
||||
// Always just fucking kill this one to stop THE WARP BUG!!!
|
||||
DisableBody(GameObject.Find("StreamingGroup_TH"), true);
|
||||
|
||||
@ -102,9 +102,8 @@ namespace NewHorizons.Handlers
|
||||
{
|
||||
DisableBody(obj.gameObject, true);
|
||||
}
|
||||
}
|
||||
else if (ao.GetAstroObjectName() == AstroObject.Name.Sun)
|
||||
{
|
||||
break;
|
||||
case AstroObject.Name.Sun:
|
||||
var starController = ao.gameObject.GetComponent<StarController>();
|
||||
StarLightController.RemoveStar(starController);
|
||||
GameObject.Destroy(starController);
|
||||
@ -132,18 +131,31 @@ namespace NewHorizons.Handlers
|
||||
|
||||
// Stop the sun from breaking stuff when the supernova gets triggered
|
||||
GlobalMessenger.RemoveListener("TriggerSupernova", ao.GetComponent<SunController>().OnTriggerSupernova);
|
||||
break;
|
||||
}
|
||||
|
||||
// Just delete the children
|
||||
// Always delete the children
|
||||
Logger.Log($"Removing Children of [{ao._name}], [{ao._customName}]");
|
||||
foreach (var child in AstroObjectLocator.GetChildren(ao))
|
||||
{
|
||||
if (child == null) continue;
|
||||
|
||||
Logger.Log($"Removing child [{child.name}] of [{ao._name}]");
|
||||
|
||||
// Ship starts as a child of TH but obvious we want to keep that
|
||||
if (child.name == "Ship_Body") continue;
|
||||
DisableBody(child, true);
|
||||
|
||||
// Some children might be astro objects and as such can have children of their own
|
||||
var childAO = child.GetComponent<AstroObject>();
|
||||
if (childAO != null) RemoveBody(childAO, false, toDestroy);
|
||||
else DisableBody(child, true);
|
||||
}
|
||||
|
||||
// Delete moons
|
||||
// Always delete moons
|
||||
foreach (var obj in AstroObjectLocator.GetMoons(ao))
|
||||
{
|
||||
if (obj == null) continue;
|
||||
|
||||
RemoveBody(obj.GetComponent<AstroObject>(), false, toDestroy);
|
||||
}
|
||||
}
|
||||
@ -188,7 +200,12 @@ namespace NewHorizons.Handlers
|
||||
{
|
||||
if (go == null) return;
|
||||
|
||||
if (delete) GameObject.Destroy(go);
|
||||
Logger.Log($"Removing [{go.name}]");
|
||||
|
||||
if (delete)
|
||||
{
|
||||
GameObject.Destroy(go);
|
||||
}
|
||||
else
|
||||
{
|
||||
go.SetActive(false);
|
||||
|
||||
@ -94,7 +94,7 @@ namespace NewHorizons.Utility
|
||||
if (primary == null) return new GameObject[0];
|
||||
|
||||
var otherChildren = new List<GameObject>();
|
||||
switch (primary.GetAstroObjectName())
|
||||
switch (primary._name)
|
||||
{
|
||||
case AstroObject.Name.TowerTwin:
|
||||
otherChildren.Add(GameObject.Find("TimeLoopRing_Body"));
|
||||
@ -129,7 +129,10 @@ namespace NewHorizons.Utility
|
||||
break;
|
||||
// For some dumb reason the sun station doesn't use AstroObject.Name.SunStation
|
||||
case AstroObject.Name.CustomString:
|
||||
if (primary._customName.Equals("Sun Station")) otherChildren.Add(GameObject.Find("SS_Debris_Body"));
|
||||
if (primary._customName.Equals("Sun Station"))
|
||||
{
|
||||
otherChildren.Add(GameObject.Find("SS_Debris_Body"));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user