From 44dbed9e9724693b0a6ac556b7fec91dd42921db Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 26 Aug 2023 23:20:15 -0400 Subject: [PATCH] Let stars explode sans remnant, fix proxy exploding on its own. Fixes #718 --- .../StarEvolutionController.cs | 58 ++++++++++++------- .../Stars/StellarDeathController.cs | 15 +++-- NewHorizons/Handlers/PlanetCreationHandler.cs | 5 +- 3 files changed, 48 insertions(+), 30 deletions(-) diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index ecb273b1..067618db 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -200,7 +200,7 @@ namespace NewHorizons.Components.SizeControllers var secondsElapsed = TimeLoop.GetSecondsElapsed(); var lifespanInSeconds = lifespan * 60; - if (willExplode && secondsElapsed >= lifespanInSeconds) + if (!isProxy && willExplode && secondsElapsed >= lifespanInSeconds) { var timeAfter = secondsElapsed - lifespanInSeconds; if (timeAfter <= collapseTime) @@ -271,7 +271,8 @@ namespace NewHorizons.Components.SizeControllers _surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t); // After the collapse is done we go supernova - if (_collapseTimer > collapseTime) StartSupernova(); + // Main star will call this on the proxy + if (!isProxy && _collapseTimer > collapseTime) StartSupernova(); } private void UpdateSupernova() @@ -364,10 +365,7 @@ namespace NewHorizons.Components.SizeControllers _surface._materials[0].CopyPropertiesFromMaterial(_collapseStartSurfaceMaterial); if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) oneShotSource.PlayOneShot(AudioType.Sun_Collapse); - if (_proxy != null) - { - _proxy.StartCollapse(); - } + _proxy?.StartCollapse(); } public void StopCollapse() @@ -380,7 +378,7 @@ namespace NewHorizons.Components.SizeControllers _isCollapsing = false; _surface._materials[0].CopyPropertiesFromMaterial(_endSurfaceMaterial); - if (_proxy != null) _proxy.StopCollapse(); + _proxy?.StopCollapse(); } public void StartSupernova() @@ -394,19 +392,24 @@ namespace NewHorizons.Components.SizeControllers supernova.Activate(); _isSupernova = true; _supernovaStartTime = Time.time; - if (atmosphere != null) atmosphere.SetActive(false); - if (destructionVolume != null) destructionVolume._deathType = DeathType.Supernova; - if (planetDestructionVolume != null) planetDestructionVolume._deathType = DeathType.Supernova; - if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) oneShotSource.PlayOneShot(AudioType.Sun_Explosion); + atmosphere?.SetActive(false); - if (_proxy != null) + if (destructionVolume != null) { - _proxy.StartSupernova(); - - // When the supernova starts some effects start on, we have to refresh their states - var nhproxy = _proxy.GetComponentInParent(); - nhproxy.ToggleRendering(!nhproxy._outOfRange); + destructionVolume._deathType = DeathType.Supernova; } + + if (planetDestructionVolume != null) + { + planetDestructionVolume._deathType = DeathType.Supernova; + } + + if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) + { + oneShotSource.PlayOneShot(AudioType.Sun_Explosion); + } + + _proxy?.StartSupernova(); } public void StopSupernova() @@ -416,26 +419,33 @@ namespace NewHorizons.Components.SizeControllers NHLogger.LogVerbose($"{gameObject.transform.root.name} stopped supernova"); SupernovaStop.Invoke(); - if (supernova != null) supernova.Deactivate(); + supernova?.Deactivate(); _isSupernova = false; - if (atmosphere != null) atmosphere.SetActive(true); + atmosphere?.SetActive(true); + if (destructionVolume != null) { destructionVolume._deathType = DeathType.Energy; destructionVolume.transform.localScale = Vector3.one; } + if (planetDestructionVolume != null) { planetDestructionVolume._deathType = DeathType.Energy; planetDestructionVolume.transform.localScale = Vector3.one; } - if (heatVolume != null) heatVolume.transform.localScale = Vector3.one; + + if (heatVolume != null) + { + heatVolume.transform.localScale = Vector3.one; + } + gameObject.SetActive(true); transform.localScale = Vector3.one; _surface._materials[0] = _surfaceMaterial; _surface.transform.localScale = Vector3.one; - if (_proxy != null) _proxy.StopSupernova(); + _proxy?.StopSupernova(); } public bool IsCollapsing() => _isCollapsing; @@ -472,7 +482,11 @@ namespace NewHorizons.Components.SizeControllers { base.FixedUpdate(); UpdateMainSequence(); - if (willExplode && (TimeLoop.GetMinutesElapsed() / lifespan) >= 1) StartCollapse(); + // Proxy will have its collapse triggered by the main star component + if (!isProxy && willExplode && (TimeLoop.GetMinutesElapsed() / lifespan) >= 1) + { + StartCollapse(); + } } else { diff --git a/NewHorizons/Components/Stars/StellarDeathController.cs b/NewHorizons/Components/Stars/StellarDeathController.cs index 33e913e4..39294b17 100644 --- a/NewHorizons/Components/Stars/StellarDeathController.cs +++ b/NewHorizons/Components/Stars/StellarDeathController.cs @@ -35,12 +35,19 @@ namespace NewHorizons.Components.Stars public void Activate() { enabled = true; - shockwave.enabled = _renderingEnabled; - for (int i = 0; i < explosionParticles.Length; i++) + + var proxy = IsProxy() ? this.GetComponentInParent() : null; + + if (proxy == null || proxy._renderingEnabled) { - explosionParticles[i].Play(); - _cachedParticleRenderers[i].enabled = _renderingEnabled; + shockwave.enabled = _renderingEnabled; + for (int i = 0; i < explosionParticles.Length; i++) + { + explosionParticles[i].Play(); + _cachedParticleRenderers[i].enabled = _renderingEnabled; + } } + _time = 0.0f; _currentSupernovaScale = supernovaScale.Evaluate(0.0f); _localSupernovaMat = new Material(supernovaMaterial); diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 623a2371..9b73c8ba 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -18,6 +18,7 @@ using System.Linq; using UnityEngine; using NewHorizons.Streaming; using Newtonsoft.Json; +using NewHorizons.External.Modules.VariableSize; namespace NewHorizons.Handlers { @@ -604,10 +605,6 @@ namespace NewHorizons.Handlers remnantGO.SetActive(false); starEvolutionController.SetStellarRemnant(remnantGO); } - else - { - starEvolutionController.willExplode = false; - } } }