using NewHorizons.Utility; using OWML.Utils; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.General { static class PlanetDestroyer { public static void RemoveBody(AstroObject ao, List toDestroy = null) { Logger.Log($"Removing {ao.name}"); if (ao.gameObject == null || !ao.gameObject.activeInHierarchy) return; if (toDestroy == null) toDestroy = new List(); if (toDestroy.Contains(ao)) { Logger.LogError($"Possible infinite recursion in RemoveBody: {ao.name} might be it's own primary body?"); return; } toDestroy.Add(ao); if (ao.GetAstroObjectName() == AstroObject.Name.BrittleHollow) RemoveBody(AstroObjectLocator.GetAstroObject(AstroObject.Name.WhiteHole), toDestroy); // Check if any other objects depend on it and remove them too var aoArray = AstroObjectLocator.GetAllAstroObjects(); foreach (AstroObject obj in aoArray) { if (obj?.gameObject == null || !obj.gameObject.activeInHierarchy) { AstroObjectLocator.RemoveAstroObject(obj); continue; } if (ao.Equals(obj.GetPrimaryBody())) { AstroObjectLocator.RemoveAstroObject(obj); RemoveBody(obj, toDestroy); } } if (ao.GetAstroObjectName() == AstroObject.Name.CaveTwin || ao.GetAstroObjectName() == AstroObject.Name.TowerTwin) { var focalBody = GameObject.Find("FocalBody"); if (focalBody != null) focalBody.SetActive(false); } if (ao.GetAstroObjectName() == AstroObject.Name.MapSatellite) { var msb = GameObject.Find("MapSatellite_Body"); if (msb != null) msb.SetActive(false); } if (ao.GetAstroObjectName() == AstroObject.Name.TowerTwin) GameObject.Find("TimeLoopRing_Body").SetActive(false); if (ao.GetAstroObjectName() == AstroObject.Name.ProbeCannon) { GameObject.Find("NomaiProbe_Body").SetActive(false); GameObject.Find("CannonMuzzle_Body").SetActive(false); GameObject.Find("FakeCannonMuzzle_Body (1)").SetActive(false); GameObject.Find("CannonBarrel_Body").SetActive(false); GameObject.Find("FakeCannonBarrel_Body (1)").SetActive(false); GameObject.Find("Debris_Body (1)").SetActive(false); } if (ao.GetAstroObjectName() == AstroObject.Name.SunStation) { GameObject.Find("SS_Debris_Body").SetActive(false); } if (ao.GetAstroObjectName() == AstroObject.Name.GiantsDeep) { GameObject.Find("BrambleIsland_Body").SetActive(false); GameObject.Find("GabbroIsland_Body").SetActive(false); GameObject.Find("QuantumIsland_Body").SetActive(false); GameObject.Find("StatueIsland_Body").SetActive(false); GameObject.Find("ConstructionYardIsland_Body").SetActive(false); } if (ao.GetAstroObjectName() == AstroObject.Name.WhiteHole) { GameObject.Find("WhiteholeStation_Body").SetActive(false); GameObject.Find("WhiteholeStationSuperstructure_Body").SetActive(false); } if (ao.GetAstroObjectName() == AstroObject.Name.TimberHearth) { GameObject.Find("MiningRig_Body").SetActive(false); } // Deal with proxies foreach (var p in GameObject.FindObjectsOfType()) { if (p.GetValue("_originalBody") == ao.gameObject) { p.gameObject.SetActive(false); break; } } Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => RemoveProxy(ao.name.Replace("_Body", ""))); ao.transform.root.gameObject.SetActive(false); } public static void RemoveDistantProxyClones() { foreach(ProxyBody proxy in GameObject.FindObjectsOfType()) { if(proxy.transform.name.Contains("_DistantProxy(Clone")) { GameObject.Destroy(proxy.gameObject); } } } private static void RemoveProxy(string name) { if (name.Equals("TowerTwin")) name = "AshTwin"; if (name.Equals("CaveTwin")) name = "EmberTwin"; var distantProxy = GameObject.Find(name + "_DistantProxy"); var distantProxyClone = GameObject.Find(name + "_DistantProxy(Clone)"); if (distantProxy != null) GameObject.Destroy(distantProxy.gameObject); if (distantProxyClone != null) GameObject.Destroy(distantProxyClone.gameObject); } } }