diff --git a/NewHorizons/Builder/General/BaseBuilder.cs b/NewHorizons/Builder/General/BaseBuilder.cs index 38746f52..7669f48f 100644 --- a/NewHorizons/Builder/General/BaseBuilder.cs +++ b/NewHorizons/Builder/General/BaseBuilder.cs @@ -70,6 +70,7 @@ namespace NewHorizons.Builder.General if (config.Base.CenterOfSolarSystem) { + Logger.Log($"Setting center of universe to {config.Name}"); Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => Locator.GetCenterOfTheUniverse()._staticReferenceFrame = owRigidBody, 2); } diff --git a/NewHorizons/Builder/General/PlanetDestroyer.cs b/NewHorizons/Builder/General/PlanetDestroyer.cs index fa6fc5aa..f4b11c0a 100644 --- a/NewHorizons/Builder/General/PlanetDestroyer.cs +++ b/NewHorizons/Builder/General/PlanetDestroyer.cs @@ -35,11 +35,18 @@ namespace NewHorizons.Builder.General public static void RemoveSolarSystem() { + // Stop the sun from killing the player + var sunVolumes = GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN"); + sunVolumes.SetActive(false); + foreach(var name in _solarSystemBodies) { var ao = AstroObjectLocator.GetAstroObject(name); - if (ao != null) RemoveBody(ao); - } + if (ao != null) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => RemoveBody(ao)); + } + + // Bring the sun back because why not + Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => { if (Locator.GetAstroObject(AstroObject.Name.Sun).gameObject.activeInHierarchy) { sunVolumes.SetActive(true); } }, 2); } public static void RemoveBody(AstroObject ao, List toDestroy = null) @@ -109,6 +116,11 @@ namespace NewHorizons.Builder.General GameObject.Find("QuantumIsland_Body").SetActive(false); GameObject.Find("StatueIsland_Body").SetActive(false); GameObject.Find("ConstructionYardIsland_Body").SetActive(false); + GameObject.Find("GabbroShip_Body").SetActive(false); + foreach(var jelly in GameObject.FindObjectsOfType()) + { + jelly.gameObject.SetActive(false); + } } else if(ao.GetAstroObjectName() == AstroObject.Name.WhiteHole) { @@ -118,6 +130,15 @@ namespace NewHorizons.Builder.General else if(ao.GetAstroObjectName() == AstroObject.Name.TimberHearth) { GameObject.Find("MiningRig_Body").SetActive(false); + + foreach(var obj in GameObject.FindObjectsOfType()) + { + GameObject.Destroy(obj); + } + foreach (var obj in GameObject.FindObjectsOfType()) + { + GameObject.Destroy(obj); + } } else if(ao.GetAstroObjectName() == AstroObject.Name.Sun) { @@ -140,7 +161,11 @@ namespace NewHorizons.Builder.General GameObject.Destroy(audioSource); } - GameObject.Find("SunProxy(Clone)/Sun_Proxy_Body").SetActive(false); + foreach(var sunProxy in GameObject.FindObjectsOfType()) + { + Logger.Log($"Destroying SunProxy {sunProxy.gameObject.name}"); + GameObject.Destroy(sunProxy.gameObject); + } } else if(ao.GetAstroObjectName() == AstroObject.Name.DreamWorld) { @@ -157,22 +182,25 @@ namespace NewHorizons.Builder.General break; } } - Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => RemoveProxy(ao.name.Replace("_Body", ""))); + RemoveProxy(ao.name.Replace("_Body", "")); ao.transform.root.gameObject.SetActive(false); + foreach (ProxyBody proxy in GameObject.FindObjectsOfType()) + { + if (proxy?._realObjectTransform?.gameObject == ao.gameObject) + { + GameObject.Destroy(proxy.gameObject); + } + } + HeavenlyBodyBuilder.Remove(ao); } public static void RemoveDistantProxyClones() { - foreach(ProxyBody proxy in GameObject.FindObjectsOfType()) - { - if(proxy.transform.name.Contains("_DistantProxy(Clone")) - { - GameObject.Destroy(proxy.gameObject); - } - } + GameObject.Destroy(GameObject.FindObjectOfType().gameObject); + } private static void RemoveProxy(string name) diff --git a/NewHorizons/Components/ShipLogStarChartMode.cs b/NewHorizons/Components/ShipLogStarChartMode.cs index 2d0bc3aa..cf5971a1 100644 --- a/NewHorizons/Components/ShipLogStarChartMode.cs +++ b/NewHorizons/Components/ShipLogStarChartMode.cs @@ -56,19 +56,9 @@ namespace NewHorizons.Components // Conditions to allow warping into that system (either no planets (stock system) or has a ship spawn point) var flag = false; if (starSystem.Equals("SolarSystem")) flag = true; - else - { - foreach(var body in Main.BodyDict[starSystem]) - { - if(body.Config?.Spawn?.ShipSpawnPoint != null) - { - flag = true; - break; - } - } - } + else if (Main.SystemDict[starSystem].Spawn?.ShipSpawnPoint != null) flag = true; - if(flag) + if (flag && Main.SystemDict[starSystem].Config.canEnterViaWarpDrive) { var card = CreateCard(starSystem, root.transform, new Vector2(x++ * 200, 0)); _starSystemCards.Add(card); diff --git a/NewHorizons/Components/ShipWarpController.cs b/NewHorizons/Components/ShipWarpController.cs index 0d969394..d535e202 100644 --- a/NewHorizons/Components/ShipWarpController.cs +++ b/NewHorizons/Components/ShipWarpController.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; +using NewHorizons.Utility; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Components @@ -25,6 +26,18 @@ namespace NewHorizons.Components private const float size = 14f; + private readonly string _blackHolePath = "TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_TT/Prefab_NOM_WarpTransmitter (1)/BlackHole/BlackHoleSingularity"; + private readonly string _whiteHolePath = "TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_CT/Prefab_NOM_WarpTransmitter/WhiteHole/WhiteHoleSingularity"; + + private GameObject _blackHolePrefab; + private GameObject _whiteHolePrefab; + + public void Init() + { + _blackHolePrefab = GameObject.Find(_blackHolePath); + _whiteHolePrefab = GameObject.Find(_whiteHolePath); + } + public void Start() { MakeBlackHole(); @@ -44,7 +57,8 @@ namespace NewHorizons.Components private void MakeBlackHole() { - var blackHoleShader = GameObject.Find("TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_TT/Prefab_NOM_WarpTransmitter (1)/BlackHole/BlackHoleSingularity").GetComponent().material.shader; + var blackHoleShader = _blackHolePrefab.GetComponent().material.shader; + if (blackHoleShader == null) blackHoleShader = _blackHolePrefab.GetComponent().sharedMaterial.shader; var blackHoleRender = new GameObject("BlackHoleRender"); blackHoleRender.transform.parent = base.transform; @@ -52,10 +66,9 @@ namespace NewHorizons.Components blackHoleRender.transform.localScale = Vector3.one * size; var meshFilter = blackHoleRender.AddComponent(); - meshFilter.mesh = GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent().mesh; + meshFilter.mesh = _blackHolePrefab.GetComponent().mesh; var meshRenderer = blackHoleRender.AddComponent(); - if (blackHoleShader == null) blackHoleShader = GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent().sharedMaterial.shader; meshRenderer.material = new Material(blackHoleShader); meshRenderer.material.SetFloat("_Radius", size * 0.4f); meshRenderer.material.SetFloat("_MaxDistortRadius", size * 0.95f); @@ -68,7 +81,8 @@ namespace NewHorizons.Components private void MakeWhiteHole() { - var whiteHoleShader = GameObject.Find("TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_CT/Prefab_NOM_WarpTransmitter/WhiteHole/WhiteHoleSingularity").GetComponent().material.shader; + var whiteHoleShader = _whiteHolePrefab.GetComponent().material.shader; + if (whiteHoleShader == null) whiteHoleShader = _whiteHolePrefab.GetComponent().sharedMaterial.shader; var whiteHoleRenderer = new GameObject("WhiteHoleRenderer"); whiteHoleRenderer.transform.parent = base.transform; @@ -76,10 +90,9 @@ namespace NewHorizons.Components whiteHoleRenderer.transform.localScale = Vector3.one * size * 2.8f; var meshFilter = whiteHoleRenderer.AddComponent(); - meshFilter.mesh = GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent().mesh; + meshFilter.mesh = _whiteHolePrefab.GetComponent().mesh; var meshRenderer = whiteHoleRenderer.AddComponent(); - if (whiteHoleShader == null) whiteHoleShader = GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent().sharedMaterial.shader; meshRenderer.material = new Material(whiteHoleShader); meshRenderer.sharedMaterial.SetFloat("_Radius", size * 0.4f); meshRenderer.sharedMaterial.SetFloat("_DistortFadeDist", size); diff --git a/NewHorizons/Components/StarLightController.cs b/NewHorizons/Components/StarLightController.cs index a027e3bc..6cb27308 100644 --- a/NewHorizons/Components/StarLightController.cs +++ b/NewHorizons/Components/StarLightController.cs @@ -37,7 +37,7 @@ namespace NewHorizons.Utility Logger.Log($"Removing star from list: {star?.gameObject?.name}"); if (_stars.Contains(star)) { - if (_activeStar.Equals(star)) + if (_activeStar != null && _activeStar.Equals(star)) { _stars.Remove(star); if(_stars.Count > 0) ChangeActiveStar(_stars[0]); diff --git a/NewHorizons/External/Configs/Config.cs b/NewHorizons/External/Configs/Config.cs index a6283bbb..a16d6ec5 100644 --- a/NewHorizons/External/Configs/Config.cs +++ b/NewHorizons/External/Configs/Config.cs @@ -20,8 +20,6 @@ namespace NewHorizons.External.Configs if (property == null) property = GetType().GetProperty(item.Key.ToCamelCase(), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); if (property == null) property = GetType().GetProperty(item.Key.ToTitleCase(), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); - Logger.Log($"Couldn't find [{item.Key}] in [{string.Concat(GetType().GetProperties().Select(x => x.Name))}] for [{GetType()}]"); - if (property != null) { if (property.PropertyType.BaseType == typeof(Module)) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 287ee143..a8480f10 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -17,6 +17,7 @@ using Newtonsoft.Json.Linq; using OWML.Common; using OWML.ModHelper; using OWML.Utils; +using PacificEngine.OW_CommonResources.Game.Player; using System; using System.Collections.Generic; using System.IO; @@ -139,7 +140,8 @@ namespace NewHorizons { Logger.Log("Setting up warp drive"); _shipWarpController = GameObject.Find("Ship_Body").AddComponent(); - Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => StarChartHandler.Init()); + _shipWarpController.Init(); + StarChartHandler.Init(); LoadBody(LoadConfig(this, "AssetBundle/WarpDriveConfig.json")); } @@ -234,16 +236,17 @@ namespace NewHorizons Logger.Log("Done loading bodies"); // I don't know what these do but they look really weird from a distance - Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PlanetDestroyer.RemoveDistantProxyClones()); + Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveDistantProxyClones(), 1); - if(!_currentStarSystem.Equals("SolarSystem")) Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveSolarSystem(), 2); + if(!_currentStarSystem.Equals("SolarSystem")) PlanetDestroyer.RemoveSolarSystem(); var map = GameObject.FindObjectOfType(); if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; Logger.Log($"Is the player warping in? {IsWarping}"); - if (IsWarping && _shipWarpController) Instance.ModHelper.Events.Unity.FireInNUpdates(() => _shipWarpController.WarpIn(WearingSuit), 1); - else Instance.ModHelper.Events.Unity.FireInNUpdates(() => GameObject.FindObjectOfType().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint), 1); + if (IsWarping && _shipWarpController) Instance.ModHelper.Events.Unity.FireInNUpdates(() => _shipWarpController.WarpIn(WearingSuit), 5); + else Instance.ModHelper.Events.Unity.FireInNUpdates(() => GameObject.FindObjectOfType().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint), 5); + IsWarping = false; } @@ -408,7 +411,7 @@ namespace NewHorizons if (!BodyDict.ContainsKey(config.StarSystem)) { // See if theres a star system config - var starSystemConfig = mod.ModHelper.Storage.Load($"{config.StarSystem}.json"); + var starSystemConfig = mod.ModHelper.Storage.Load($"systems/{config.StarSystem}.json"); if (starSystemConfig == null) starSystemConfig = new StarSystemConfig(null); else Logger.Log($"Loaded system config for {config.StarSystem}"); @@ -454,8 +457,8 @@ namespace NewHorizons if (body.Config.Destroy) { var ao = existingPlanet.GetComponent(); - if (ao != null) Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveBody(ao), 5); - else Instance.ModHelper.Events.Unity.FireInNUpdates(() => existingPlanet.SetActive(false), 5); + if (ao != null) Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveBody(ao), 1); + else Instance.ModHelper.Events.Unity.FireInNUpdates(() => existingPlanet.SetActive(false), 1); } else UpdateBody(body, existingPlanet); } @@ -718,7 +721,11 @@ namespace NewHorizons void OnDeath(DeathType _) { // We reset the solar system on death (unless we just killed the player) - if (!_isChangingStarSystem) _currentStarSystem = _defaultStarSystem; + if (!_isChangingStarSystem) + { + _currentStarSystem = _defaultStarSystem; + IsWarping = false; + } } #endregion Change star system }