From 8185a8871d92df9a353e6909cc118e902c4757b8 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 25 Aug 2022 21:02:16 -0400 Subject: [PATCH] Fix everything --- NewHorizons/Builder/Body/StarBuilder.cs | 176 ++++++++---------- .../StarEvolutionController.cs | 31 +-- .../Components/StellarDeathController.cs | 76 ++++---- NewHorizons/Handlers/PlanetCreationHandler.cs | 6 +- .../Handlers/SupernovaEffectHandler.cs | 3 +- NewHorizons/Patches/ProxyBodyPatches.cs | 2 +- 6 files changed, 142 insertions(+), 152 deletions(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index 108aef7a..e976f800 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -7,6 +7,8 @@ using NewHorizons.External.Modules.VariableSize; using Logger = NewHorizons.Utility.Logger; using OWML.ModHelper; using OWML.Common; +using UnityEngine.InputSystem.XR; +using System.Linq; namespace NewHorizons.Builder.Body { @@ -23,11 +25,7 @@ namespace NewHorizons.Builder.Body public static (GameObject, StarController, StarEvolutionController) Make(GameObject planetGO, Sector sector, StarModule starModule, IModBehaviour mod, bool isStellarRemnant) { - var starGO = MakeStarGraphics(planetGO, sector, starModule, mod); - - starGO.SetActive(false); - - var ramp = starGO.GetComponentInChildren().sharedMaterial.GetTexture(ColorRamp); + var (starGO, starEvolutionController, supernova) = SharedStarGeneration(planetGO, sector, mod, starModule, isStellarRemnant); var sunAudio = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform); sunAudio.transform.localPosition = Vector3.zero; @@ -112,6 +110,7 @@ namespace NewHorizons.Builder.Body planetDestructionVolume.AddComponent(); planetDestructionVolume.AddComponent()._deathType = DeathType.Energy; + // Star light var sunLight = new GameObject("StarLight"); sunLight.transform.parent = starGO.transform; sunLight.transform.localPosition = Vector3.zero; @@ -138,6 +137,7 @@ namespace NewHorizons.Builder.Body proxyShadowLight.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); proxyShadowLight._light = light; + // Star controller (works on atmospheric shaders) StarController starController = null; if (starModule.solarLuminosity != 0 && starModule.hasStarController) { @@ -152,49 +152,19 @@ namespace NewHorizons.Builder.Body starController.IsStellarRemnant = isStellarRemnant; } - // TODO: A lot of this is shared with the proxy generation, we should merge that - // Could go into the star graphics method - var starEvolutionController = starGO.AddComponent(); - if (starModule.curve != null) starEvolutionController.SetScaleCurve(starModule.curve); - starEvolutionController.size = starModule.size; starEvolutionController.atmosphere = sunAtmosphere; starEvolutionController.controller = starController; - starEvolutionController.startColour = starModule.tint; - starEvolutionController.endColour = starModule.endTint; starEvolutionController.supernovaColour = starModule.supernovaTint; - starEvolutionController.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp; starFluidVolume.SetStarEvolutionController(starEvolutionController); - if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture)) - { - starEvolutionController.collapseRamp = ImageUtilities.GetTexture(mod, starModule.starCollapseRampTexture); - } + surfaceAudio.SetStarEvolutionController(starEvolutionController); - if (!isStellarRemnant) - { - var supernova = MakeSupernova(starGO, starModule); - starEvolutionController.supernovaSize = starModule.supernovaSize; - var duration = starModule.supernovaSize / starModule.supernovaSpeed; - starEvolutionController.supernovaTime = duration; - starEvolutionController.supernovaScaleEnd = duration; - starEvolutionController.supernovaScaleStart = duration * 0.9f; - starEvolutionController.deathType = starModule.stellarDeathType; - - starEvolutionController.supernova = supernova; - - starEvolutionController.willExplode = starModule.stellarDeathType != StellarDeathType.None; - starEvolutionController.lifespan = starModule.lifespan; - starEvolutionController.heatVolume = heatVolume.GetComponent(); - starEvolutionController.destructionVolume = deathVolume.GetComponent(); - starEvolutionController.planetDestructionVolume = planetDestructionVolume.GetComponent(); - starEvolutionController.starFluidVolume = starFluidVolume; - starEvolutionController.oneShotSource = sunAudio.transform.Find("OneShotAudio_Sun")?.GetComponent(); - } - else - { - starEvolutionController.willExplode = false; - } + starEvolutionController.heatVolume = heatVolume.GetComponent(); + starEvolutionController.destructionVolume = deathVolume.GetComponent(); + starEvolutionController.planetDestructionVolume = planetDestructionVolume.GetComponent(); + starEvolutionController.starFluidVolume = starFluidVolume; + starEvolutionController.oneShotSource = sunAudio.transform.Find("OneShotAudio_Sun")?.GetComponent(); var shockLayerRuleset = sector.gameObject.AddComponent(); shockLayerRuleset._type = ShockLayerRuleset.ShockType.Radial; @@ -211,58 +181,70 @@ namespace NewHorizons.Builder.Body public static GameObject MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule, IModBehaviour mod, bool isStellarRemnant) { - var starGO = MakeStarGraphics(proxyGO, null, starModule, mod); - var ramp = starGO.GetComponentInChildren().sharedMaterial.GetTexture(ColorRamp); + var (starGO, controller, supernova) = SharedStarGeneration(proxyGO, null, mod, starModule, isStellarRemnant); - var controller = starGO.AddComponent(); - if (starModule.curve != null) controller.SetScaleCurve(starModule.curve); - controller.size = starModule.size; - controller.startColour = starModule.tint; - controller.endColour = starModule.endTint; + controller.isProxy = true; - controller.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp; - if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture)) - { - controller.collapseRamp = ImageUtilities.GetTexture(mod, starModule.starCollapseRampTexture); - } - controller.enabled = true; - starGO.SetActive(true); + // Planet can have multiple stars on them, so find the one that is also a remnant / not a remnant + // This will bug out if we make quantum stars. Will have to figure that out eventually. + var mainController = planet.GetComponentsInChildren(true).Where(x => x.isRemnant == isStellarRemnant).FirstOrDefault(); + mainController.SetProxy(controller); // Remnants can't go supernova - if (!isStellarRemnant) + if (supernova != null) { - var supernova = MakeSupernova(starGO, starModule, true); + supernova.SetIsProxy(true); - supernova.SetIsProxy(true); - - starGO.SetActive(false); - - controller.isProxy = true; - - controller.supernovaSize = starModule.supernovaSize; - var duration = starModule.supernovaSize / starModule.supernovaSpeed; - controller.supernovaTime = duration; - controller.supernovaScaleEnd = duration; - controller.supernovaScaleStart = duration * 0.9f; - controller.deathType = starModule.stellarDeathType; - controller.supernova = supernova; - - controller.supernovaColour = starModule.supernovaTint; - controller.willExplode = starModule.stellarDeathType != StellarDeathType.None; - controller.lifespan = starModule.lifespan; - - var main = planet.GetComponentInChildren(true); - main.SetProxy(controller); - supernova._main = main.supernova; - } - else - { - controller.willExplode = false; + supernova.mainStellerDeathController = mainController.supernova; } return starGO; } + private static (GameObject, StarEvolutionController, StellarDeathController) SharedStarGeneration(GameObject planetGO, Sector sector, IModBehaviour mod, StarModule starModule, bool isStellarRemnant) + { + var starGO = MakeStarGraphics(planetGO, sector, starModule, mod); + starGO.SetActive(false); + + var ramp = starGO.GetComponentInChildren(true).sharedMaterial.GetTexture(ColorRamp); + + var starEvolutionController = starGO.AddComponent(); + starEvolutionController.isRemnant = isStellarRemnant; + if (starModule.curve != null) starEvolutionController.SetScaleCurve(starModule.curve); + starEvolutionController.size = starModule.size; + starEvolutionController.startColour = starModule.tint; + starEvolutionController.endColour = starModule.endTint; + + starEvolutionController.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp; + if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture)) + { + starEvolutionController.collapseRamp = ImageUtilities.GetTexture(mod, starModule.starCollapseRampTexture); + } + + StellarDeathController supernova = null; + var willExplode = !isStellarRemnant && starModule.stellarDeathType != StellarDeathType.None; + if (willExplode) + { + supernova = MakeSupernova(starGO, starModule); + + starEvolutionController.supernovaSize = starModule.supernovaSize; + var duration = starModule.supernovaSize / starModule.supernovaSpeed; + starEvolutionController.supernovaTime = duration; + starEvolutionController.supernovaScaleEnd = duration; + starEvolutionController.supernovaScaleStart = duration * 0.9f; + starEvolutionController.deathType = starModule.stellarDeathType; + starEvolutionController.supernova = supernova; + starEvolutionController.supernovaColour = starModule.supernovaTint; + starEvolutionController.lifespan = starModule.lifespan; + } + starEvolutionController.willExplode = willExplode; + + starEvolutionController.enabled = true; + starGO.SetActive(true); + + return (starGO, starEvolutionController, supernova); + } + public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, StarModule starModule, IModBehaviour mod) { if (_colorOverTime == null) _colorOverTime = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/StarColorOverTime.png"); @@ -346,26 +328,26 @@ namespace NewHorizons.Builder.Body var supernova = supernovaGO.GetComponent(); var stellarDeath = supernovaGO.AddComponent(); stellarDeath.enabled = false; - stellarDeath._surface = starGO.GetComponentInChildren(); + stellarDeath.surface = starGO.GetComponentInChildren(true); var duration = starModule.supernovaSize / starModule.supernovaSpeed; - stellarDeath._supernovaScale = new AnimationCurve(new Keyframe(0, 200, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(duration, starModule.supernovaSize, 1758.508f, 1758.508f, 1f / 3f, 1f / 3f)); - stellarDeath._supernovaAlpha = new AnimationCurve(new Keyframe(duration * 0.1f, 1, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(duration * 0.3f, 1.0002f, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(duration, 0, -0.0578f, 1 / 3f, -0.0578f, 1 / 3f)); - stellarDeath._explosionParticles = supernova._explosionParticles; - stellarDeath._shockwave = supernova._shockwave; - stellarDeath._shockwaveLength = supernova._shockwaveLength; - stellarDeath._shockwaveAlpha = supernova._shockwaveAlpha; - stellarDeath._shockwaveScale = supernova._shockwaveScale; - stellarDeath._supernovaMaterial = supernova._supernovaMaterial; + stellarDeath.supernovaScale = new AnimationCurve(new Keyframe(0, 200, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(duration, starModule.supernovaSize, 1758.508f, 1758.508f, 1f / 3f, 1f / 3f)); + stellarDeath.supernovaAlpha = new AnimationCurve(new Keyframe(duration * 0.1f, 1, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(duration * 0.3f, 1.0002f, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(duration, 0, -0.0578f, 1 / 3f, -0.0578f, 1 / 3f)); + stellarDeath.explosionParticles = supernova._explosionParticles; + stellarDeath.shockwave = supernova._shockwave; + stellarDeath.shockwaveLength = supernova._shockwaveLength; + stellarDeath.shockwaveAlpha = supernova._shockwaveAlpha; + stellarDeath.shockwaveScale = supernova._shockwaveScale; + stellarDeath.supernovaMaterial = supernova._supernovaMaterial; GameObject.Destroy(supernova); if (starModule.supernovaTint != null) { var colour = starModule.supernovaTint.ToColor(); - var supernovaMaterial = new Material(stellarDeath._supernovaMaterial); + var supernovaMaterial = new Material(stellarDeath.supernovaMaterial); var ramp = ImageUtilities.LerpGreyscaleImage(ImageUtilities.GetTexture(Main.Instance, "Assets/textures/Effects_SUN_Supernova_d.png"), Color.white, colour); supernovaMaterial.SetTexture(ColorRamp, ramp); - stellarDeath._supernovaMaterial = supernovaMaterial; + stellarDeath.supernovaMaterial = supernovaMaterial; // Motes var moteMaterial = supernovaGO.GetComponentInChildren().material; @@ -393,10 +375,10 @@ namespace NewHorizons.Builder.Body audioSource.spatialBlend = 1; audioSource.volume = 0.5f; audioSource.velocityUpdateMode = AudioVelocityUpdateMode.Fixed; - stellarDeath._audioSource = supernovaWallAudio.AddComponent(); - stellarDeath._audioSource._audioSource = audioSource; - stellarDeath._audioSource._audioLibraryClip = AudioType.Sun_SupernovaWall_LP; - stellarDeath._audioSource.SetTrack(OWAudioMixer.TrackName.EndTimes_SFX); + stellarDeath.audioSource = supernovaWallAudio.AddComponent(); + stellarDeath.audioSource._audioSource = audioSource; + stellarDeath.audioSource._audioLibraryClip = AudioType.Sun_SupernovaWall_LP; + stellarDeath.audioSource.SetTrack(OWAudioMixer.TrackName.EndTimes_SFX); } supernovaGO.SetActive(true); diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 0b55df8e..770e4033 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -17,6 +17,7 @@ namespace NewHorizons.Components.SizeControllers public class StarEvolutionController : SizeController { public bool isProxy; + public bool isRemnant; public GameObject atmosphere; public StarController controller; @@ -86,8 +87,12 @@ namespace NewHorizons.Components.SizeControllers private Color _currentColour; + private TessellatedSphereRenderer _surface; + private void Start() { + _surface = GetComponentInChildren(true); + _rigidbody = this.GetAttachedOWRigidbody(); var sun = GameObject.FindObjectOfType(); @@ -163,7 +168,7 @@ namespace NewHorizons.Components.SizeControllers } _flareEmitter = GetComponentInChildren(); - _surfaceMaterial = supernova._surface._materials[0]; + _surfaceMaterial = _surface._materials[0]; if (!isProxy) SupernovaEffectHandler.RegisterStar(this); @@ -189,7 +194,7 @@ namespace NewHorizons.Components.SizeControllers public void SetProxy(StarEvolutionController proxy) { _proxy = proxy; - _proxy.supernova.SetIsProxy(true); + _proxy.supernova?.SetIsProxy(true); } private void UpdateMainSequence() @@ -204,21 +209,21 @@ namespace NewHorizons.Components.SizeControllers if (t < 1f) { _currentColour = Color.Lerp(_startColour, _endColour, t); - supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, t); - supernova._surface._materials[0].SetFloat(ColorTime, t); + _surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, t); + _surface._materials[0].SetFloat(ColorTime, t); } else { _currentColour = _endColour; - supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, 1); - supernova._surface._materials[0].SetFloat(ColorTime, 1); + _surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, 1); + _surface._materials[0].SetFloat(ColorTime, 1); } } else { _currentColour = _startColour; - supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, 0); - supernova._surface._materials[0].SetFloat(ColorTime, 0); + _surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, 0); + _surface._materials[0].SetFloat(ColorTime, 0); } if (_flareEmitter != null) _flareEmitter._tint = _currentColour; @@ -234,7 +239,7 @@ namespace NewHorizons.Components.SizeControllers _currentColour = Color.Lerp(_endColour, Color.white, t); - supernova._surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t); + _surface._materials[0].Lerp(_collapseStartSurfaceMaterial, _collapseEndSurfaceMaterial, t); // After the collapse is done we go supernova if (_collapseTimer > collapseTime) StartSupernova(); @@ -324,7 +329,7 @@ namespace NewHorizons.Components.SizeControllers _isCollapsing = true; _collapseStartSize = CurrentScale; _collapseTimer = 0f; - supernova._surface._materials[0].CopyPropertiesFromMaterial(_collapseStartSurfaceMaterial); + _surface._materials[0].CopyPropertiesFromMaterial(_collapseStartSurfaceMaterial); if (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) oneShotSource.PlayOneShot(AudioType.Sun_Collapse); if (_proxy != null) _proxy.StartCollapse(); @@ -338,7 +343,7 @@ namespace NewHorizons.Components.SizeControllers CollapseStop.Invoke(); _isCollapsing = false; - supernova._surface._materials[0].CopyPropertiesFromMaterial(_endSurfaceMaterial); + _surface._materials[0].CopyPropertiesFromMaterial(_endSurfaceMaterial); if (_proxy != null) _proxy.StopCollapse(); } @@ -384,8 +389,8 @@ namespace NewHorizons.Components.SizeControllers if (heatVolume != null) heatVolume.transform.localScale = Vector3.one; gameObject.SetActive(true); transform.localScale = Vector3.one; - supernova._surface._materials[0] = _surfaceMaterial; - supernova._surface.transform.localScale = Vector3.one; + _surface._materials[0] = _surfaceMaterial; + _surface.transform.localScale = Vector3.one; if (_proxy != null) _proxy.StopSupernova(); } diff --git a/NewHorizons/Components/StellarDeathController.cs b/NewHorizons/Components/StellarDeathController.cs index c209cb29..30ccb698 100644 --- a/NewHorizons/Components/StellarDeathController.cs +++ b/NewHorizons/Components/StellarDeathController.cs @@ -7,19 +7,20 @@ namespace NewHorizons.Components { public class StellarDeathController : MonoBehaviour { - public ParticleSystem[] _explosionParticles; - public MeshRenderer _shockwave; - public float _shockwaveLength = 5f; - public AnimationCurve _shockwaveScale = AnimationCurve.Linear(0.0f, 0.0f, 1f, 100000f); - public AnimationCurve _shockwaveAlpha = AnimationCurve.Linear(0.0f, 1f, 1f, 0.0f); + public ParticleSystem[] explosionParticles; + public MeshRenderer shockwave; + public float shockwaveLength = 5f; + public AnimationCurve shockwaveScale = AnimationCurve.Linear(0.0f, 0.0f, 1f, 100000f); + public AnimationCurve shockwaveAlpha = AnimationCurve.Linear(0.0f, 1f, 1f, 0.0f); - public TessellatedSphereRenderer _surface; - public Material _supernovaMaterial; - public AnimationCurve _supernovaScale = new AnimationCurve(new Keyframe(0, 200, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(45, 50000, 1758.508f, 1758.508f, 1f / 3f, 1f / 3f)); - public AnimationCurve _supernovaAlpha = new AnimationCurve(new Keyframe(5, 1, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(15, 1.0002f, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(50, 0, -0.0578f, 1 / 3f, -0.0578f, 1 / 3f)); + public TessellatedSphereRenderer surface; + public Material supernovaMaterial; + public AnimationCurve supernovaScale = new AnimationCurve(new Keyframe(0, 200, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(45, 50000, 1758.508f, 1758.508f, 1f / 3f, 1f / 3f)); + public AnimationCurve supernovaAlpha = new AnimationCurve(new Keyframe(5, 1, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(15, 1.0002f, 0, 0, 1f / 3f, 1f / 3f), new Keyframe(50, 0, -0.0578f, 1 / 3f, -0.0578f, 1 / 3f)); + + public OWAudioSource audioSource; + public StellarDeathController mainStellerDeathController; - public OWAudioSource _audioSource; - public StellarDeathController _main; private float _time; private float _currentSupernovaScale; private Material _localSupernovaMat; @@ -28,58 +29,59 @@ namespace NewHorizons.Components public void Awake() { - _cachedParticleRenderers = new ParticleSystemRenderer[_explosionParticles.Length]; - for (int index = 0; index < _explosionParticles.Length; ++index) - _cachedParticleRenderers[index] = _explosionParticles[index].GetComponent(); + _cachedParticleRenderers = new ParticleSystemRenderer[explosionParticles.Length]; + for (int index = 0; index < explosionParticles.Length; ++index) + _cachedParticleRenderers[index] = explosionParticles[index].GetComponent(); } public void Activate() { enabled = true; - _shockwave.enabled = true; - foreach (var particle in _explosionParticles) particle.Play(); + shockwave.enabled = true; + foreach (var particle in explosionParticles) particle.Play(); _time = 0.0f; - _currentSupernovaScale = _supernovaScale.Evaluate(0.0f); - _localSupernovaMat = new Material(_supernovaMaterial); - _surface.sharedMaterial = _localSupernovaMat; + _currentSupernovaScale = supernovaScale.Evaluate(0.0f); + _localSupernovaMat = new Material(supernovaMaterial); + surface.sharedMaterial = _localSupernovaMat; - if (_audioSource == null) return; + if (audioSource == null) return; - _audioSource.AssignAudioLibraryClip(AudioType.Sun_SupernovaWall_LP); - _audioSource.SetLocalVolume(0); - _audioSource.Play(); + audioSource.AssignAudioLibraryClip(AudioType.Sun_SupernovaWall_LP); + audioSource.SetLocalVolume(0); + audioSource.Play(); } public void Deactivate() { enabled = false; - _shockwave.enabled = false; + shockwave.enabled = false; - if (_audioSource == null) return; + if (audioSource == null) return; - _audioSource.SetLocalVolume(0); - _audioSource.Stop(); + audioSource.SetLocalVolume(0); + audioSource.Stop(); } public void FixedUpdate() { - if (_main != null) _time = _main._time; + if (mainStellerDeathController != null) _time = mainStellerDeathController._time; else _time += Time.deltaTime; - float shockwaveTime = Mathf.Clamp01(_time / _shockwaveLength); - _shockwave.transform.localScale = Vector3.one * _shockwaveScale.Evaluate(shockwaveTime); - _shockwave.material.color = Color.Lerp(Color.black, _shockwave.sharedMaterial.color, _shockwaveAlpha.Evaluate(shockwaveTime)); - _currentSupernovaScale = _supernovaScale.Evaluate(_time); - _surface.transform.localScale = Vector3.one * _currentSupernovaScale; - _localSupernovaMat.color = Color.Lerp(Color.black, _supernovaMaterial.color, _supernovaAlpha.Evaluate(_time)); + + float shockwaveTime = Mathf.Clamp01(_time / shockwaveLength); + shockwave.transform.localScale = Vector3.one * shockwaveScale.Evaluate(shockwaveTime); + shockwave.material.color = Color.Lerp(Color.black, shockwave.sharedMaterial.color, shockwaveAlpha.Evaluate(shockwaveTime)); + _currentSupernovaScale = supernovaScale.Evaluate(_time); + surface.transform.localScale = Vector3.one * _currentSupernovaScale; + _localSupernovaMat.color = Color.Lerp(Color.black, supernovaMaterial.color, supernovaAlpha.Evaluate(_time)); float distanceToPlayer = PlayerState.InDreamWorld() ? 20000f : (Vector3.Distance(transform.position, Locator.GetPlayerCamera().transform.position) - GetSupernovaRadius()); if (_isProxy) return; - if (_audioSource != null) + if (audioSource != null) { float dt = Mathf.InverseLerp(12000f, 0.0f, distanceToPlayer); - _audioSource.SetLocalVolume(Mathf.Lerp(0.0f, 1f, dt * dt) * Mathf.InverseLerp(0.0f, 5f, _time)); + audioSource.SetLocalVolume(Mathf.Lerp(0.0f, 1f, dt * dt) * Mathf.InverseLerp(0.0f, 5f, _time)); } RumbleManager.UpdateSupernova(distanceToPlayer); @@ -99,7 +101,7 @@ namespace NewHorizons.Components public void SetRenderingEnabled(bool renderingEnabled) { if (!enabled) return; - _shockwave.enabled = renderingEnabled; + shockwave.enabled = renderingEnabled; SetParticlesVisibility(renderingEnabled); } } diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 28b78382..37a9c5e0 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -508,12 +508,12 @@ namespace NewHorizons.Handlers if (body.Config.Star != null) { - var (star, starController, starEvolutionController) = StarBuilder.Make(go, sector, body.Config.Star, body.Mod, false); + var (star, starController, starEvolutionController) = StarBuilder.Make(go, sector, body.Config.Star, body.Mod, body.Config.isStellarRemnant); if (starController != null) StarLightController.AddStar(starController); - // If it has an evolution controller that means it will die -> we make a remnant - if (starEvolutionController != null) + // If it has an evolution controller that means it will die -> we make a remnant (unless its a remnant) + if (starEvolutionController != null && !body.Config.isStellarRemnant) { GameObject remnantGO; diff --git a/NewHorizons/Handlers/SupernovaEffectHandler.cs b/NewHorizons/Handlers/SupernovaEffectHandler.cs index 82c9ad44..7048ee80 100644 --- a/NewHorizons/Handlers/SupernovaEffectHandler.cs +++ b/NewHorizons/Handlers/SupernovaEffectHandler.cs @@ -108,11 +108,12 @@ namespace NewHorizons.Handlers public static SunController GetSunController() => _sunController; - public static bool InPointInsideAnySupernova(Vector3 position) + public static bool IsPointInsideAnySupernova(Vector3 position) { foreach (var starEvolutionController in _starEvolutionControllers) { if (!IsStarActive(starEvolutionController)) continue; + if (starEvolutionController.supernova == null) continue; var distanceSqr = (position - starEvolutionController.transform.position).sqrMagnitude; var size = starEvolutionController.GetSupernovaRadius(); diff --git a/NewHorizons/Patches/ProxyBodyPatches.cs b/NewHorizons/Patches/ProxyBodyPatches.cs index e1f1bb81..5cd3feec 100644 --- a/NewHorizons/Patches/ProxyBodyPatches.cs +++ b/NewHorizons/Patches/ProxyBodyPatches.cs @@ -47,7 +47,7 @@ namespace NewHorizons.Patches } else { - __result = SupernovaEffectHandler.InPointInsideAnySupernova(__instance._realObjectTransform.position); + __result = SupernovaEffectHandler.IsPointInsideAnySupernova(__instance._realObjectTransform.position); return false; } }