Let stars explode sans remnant, fix proxy exploding on its own. Fixes #718

This commit is contained in:
Nick 2023-08-26 23:20:15 -04:00
parent b61c25ff35
commit 44dbed9e97
3 changed files with 48 additions and 30 deletions

View File

@ -200,7 +200,7 @@ namespace NewHorizons.Components.SizeControllers
var secondsElapsed = TimeLoop.GetSecondsElapsed(); var secondsElapsed = TimeLoop.GetSecondsElapsed();
var lifespanInSeconds = lifespan * 60; var lifespanInSeconds = lifespan * 60;
if (willExplode && secondsElapsed >= lifespanInSeconds) if (!isProxy && willExplode && secondsElapsed >= lifespanInSeconds)
{ {
var timeAfter = secondsElapsed - lifespanInSeconds; var timeAfter = secondsElapsed - lifespanInSeconds;
if (timeAfter <= collapseTime) if (timeAfter <= collapseTime)
@ -271,7 +271,8 @@ namespace NewHorizons.Components.SizeControllers
_surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t); _surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t);
// After the collapse is done we go supernova // 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() private void UpdateSupernova()
@ -364,10 +365,7 @@ namespace NewHorizons.Components.SizeControllers
_surface._materials[0].CopyPropertiesFromMaterial(_collapseStartSurfaceMaterial); _surface._materials[0].CopyPropertiesFromMaterial(_collapseStartSurfaceMaterial);
if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) oneShotSource.PlayOneShot(AudioType.Sun_Collapse); if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) oneShotSource.PlayOneShot(AudioType.Sun_Collapse);
if (_proxy != null) _proxy?.StartCollapse();
{
_proxy.StartCollapse();
}
} }
public void StopCollapse() public void StopCollapse()
@ -380,7 +378,7 @@ namespace NewHorizons.Components.SizeControllers
_isCollapsing = false; _isCollapsing = false;
_surface._materials[0].CopyPropertiesFromMaterial(_endSurfaceMaterial); _surface._materials[0].CopyPropertiesFromMaterial(_endSurfaceMaterial);
if (_proxy != null) _proxy.StopCollapse(); _proxy?.StopCollapse();
} }
public void StartSupernova() public void StartSupernova()
@ -394,19 +392,24 @@ namespace NewHorizons.Components.SizeControllers
supernova.Activate(); supernova.Activate();
_isSupernova = true; _isSupernova = true;
_supernovaStartTime = Time.time; _supernovaStartTime = Time.time;
if (atmosphere != null) atmosphere.SetActive(false); 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);
if (_proxy != null) if (destructionVolume != null)
{ {
_proxy.StartSupernova(); destructionVolume._deathType = DeathType.Supernova;
// When the supernova starts some effects start on, we have to refresh their states
var nhproxy = _proxy.GetComponentInParent<NHProxy>();
nhproxy.ToggleRendering(!nhproxy._outOfRange);
} }
if (planetDestructionVolume != null)
{
planetDestructionVolume._deathType = DeathType.Supernova;
}
if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld())
{
oneShotSource.PlayOneShot(AudioType.Sun_Explosion);
}
_proxy?.StartSupernova();
} }
public void StopSupernova() public void StopSupernova()
@ -416,26 +419,33 @@ namespace NewHorizons.Components.SizeControllers
NHLogger.LogVerbose($"{gameObject.transform.root.name} stopped supernova"); NHLogger.LogVerbose($"{gameObject.transform.root.name} stopped supernova");
SupernovaStop.Invoke(); SupernovaStop.Invoke();
if (supernova != null) supernova.Deactivate(); supernova?.Deactivate();
_isSupernova = false; _isSupernova = false;
if (atmosphere != null) atmosphere.SetActive(true); atmosphere?.SetActive(true);
if (destructionVolume != null) if (destructionVolume != null)
{ {
destructionVolume._deathType = DeathType.Energy; destructionVolume._deathType = DeathType.Energy;
destructionVolume.transform.localScale = Vector3.one; destructionVolume.transform.localScale = Vector3.one;
} }
if (planetDestructionVolume != null) if (planetDestructionVolume != null)
{ {
planetDestructionVolume._deathType = DeathType.Energy; planetDestructionVolume._deathType = DeathType.Energy;
planetDestructionVolume.transform.localScale = Vector3.one; planetDestructionVolume.transform.localScale = Vector3.one;
} }
if (heatVolume != null) heatVolume.transform.localScale = Vector3.one;
if (heatVolume != null)
{
heatVolume.transform.localScale = Vector3.one;
}
gameObject.SetActive(true); gameObject.SetActive(true);
transform.localScale = Vector3.one; transform.localScale = Vector3.one;
_surface._materials[0] = _surfaceMaterial; _surface._materials[0] = _surfaceMaterial;
_surface.transform.localScale = Vector3.one; _surface.transform.localScale = Vector3.one;
if (_proxy != null) _proxy.StopSupernova(); _proxy?.StopSupernova();
} }
public bool IsCollapsing() => _isCollapsing; public bool IsCollapsing() => _isCollapsing;
@ -472,7 +482,11 @@ namespace NewHorizons.Components.SizeControllers
{ {
base.FixedUpdate(); base.FixedUpdate();
UpdateMainSequence(); 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 else
{ {

View File

@ -35,12 +35,19 @@ namespace NewHorizons.Components.Stars
public void Activate() public void Activate()
{ {
enabled = true; enabled = true;
shockwave.enabled = _renderingEnabled;
for (int i = 0; i < explosionParticles.Length; i++) var proxy = IsProxy() ? this.GetComponentInParent<NHProxy>() : null;
if (proxy == null || proxy._renderingEnabled)
{ {
explosionParticles[i].Play(); shockwave.enabled = _renderingEnabled;
_cachedParticleRenderers[i].enabled = _renderingEnabled; for (int i = 0; i < explosionParticles.Length; i++)
{
explosionParticles[i].Play();
_cachedParticleRenderers[i].enabled = _renderingEnabled;
}
} }
_time = 0.0f; _time = 0.0f;
_currentSupernovaScale = supernovaScale.Evaluate(0.0f); _currentSupernovaScale = supernovaScale.Evaluate(0.0f);
_localSupernovaMat = new Material(supernovaMaterial); _localSupernovaMat = new Material(supernovaMaterial);

View File

@ -18,6 +18,7 @@ using System.Linq;
using UnityEngine; using UnityEngine;
using NewHorizons.Streaming; using NewHorizons.Streaming;
using Newtonsoft.Json; using Newtonsoft.Json;
using NewHorizons.External.Modules.VariableSize;
namespace NewHorizons.Handlers namespace NewHorizons.Handlers
{ {
@ -604,10 +605,6 @@ namespace NewHorizons.Handlers
remnantGO.SetActive(false); remnantGO.SetActive(false);
starEvolutionController.SetStellarRemnant(remnantGO); starEvolutionController.SetStellarRemnant(remnantGO);
} }
else
{
starEvolutionController.willExplode = false;
}
} }
} }