Fix everything

This commit is contained in:
Nick 2022-08-25 21:02:16 -04:00
parent b637a50439
commit 8185a8871d
6 changed files with 142 additions and 152 deletions

View File

@ -7,6 +7,8 @@ using NewHorizons.External.Modules.VariableSize;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
using OWML.ModHelper; using OWML.ModHelper;
using OWML.Common; using OWML.Common;
using UnityEngine.InputSystem.XR;
using System.Linq;
namespace NewHorizons.Builder.Body 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) public static (GameObject, StarController, StarEvolutionController) Make(GameObject planetGO, Sector sector, StarModule starModule, IModBehaviour mod, bool isStellarRemnant)
{ {
var starGO = MakeStarGraphics(planetGO, sector, starModule, mod); var (starGO, starEvolutionController, supernova) = SharedStarGeneration(planetGO, sector, mod, starModule, isStellarRemnant);
starGO.SetActive(false);
var ramp = starGO.GetComponentInChildren<TessellatedSphereRenderer>().sharedMaterial.GetTexture(ColorRamp);
var sunAudio = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform); var sunAudio = Object.Instantiate(SearchUtilities.Find("Sun_Body/Sector_SUN/Audio_SUN"), starGO.transform);
sunAudio.transform.localPosition = Vector3.zero; sunAudio.transform.localPosition = Vector3.zero;
@ -112,6 +110,7 @@ namespace NewHorizons.Builder.Body
planetDestructionVolume.AddComponent<OWTriggerVolume>(); planetDestructionVolume.AddComponent<OWTriggerVolume>();
planetDestructionVolume.AddComponent<StarDestructionVolume>()._deathType = DeathType.Energy; planetDestructionVolume.AddComponent<StarDestructionVolume>()._deathType = DeathType.Energy;
// Star light
var sunLight = new GameObject("StarLight"); var sunLight = new GameObject("StarLight");
sunLight.transform.parent = starGO.transform; sunLight.transform.parent = starGO.transform;
sunLight.transform.localPosition = Vector3.zero; 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>()); proxyShadowLight.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent<ProxyShadowLight>());
proxyShadowLight._light = light; proxyShadowLight._light = light;
// Star controller (works on atmospheric shaders)
StarController starController = null; StarController starController = null;
if (starModule.solarLuminosity != 0 && starModule.hasStarController) if (starModule.solarLuminosity != 0 && starModule.hasStarController)
{ {
@ -152,49 +152,19 @@ namespace NewHorizons.Builder.Body
starController.IsStellarRemnant = isStellarRemnant; 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<StarEvolutionController>();
if (starModule.curve != null) starEvolutionController.SetScaleCurve(starModule.curve);
starEvolutionController.size = starModule.size;
starEvolutionController.atmosphere = sunAtmosphere; starEvolutionController.atmosphere = sunAtmosphere;
starEvolutionController.controller = starController; starEvolutionController.controller = starController;
starEvolutionController.startColour = starModule.tint;
starEvolutionController.endColour = starModule.endTint;
starEvolutionController.supernovaColour = starModule.supernovaTint; starEvolutionController.supernovaColour = starModule.supernovaTint;
starEvolutionController.normalRamp = !string.IsNullOrEmpty(starModule.starRampTexture) ? ImageUtilities.GetTexture(mod, starModule.starRampTexture) : ramp;
starFluidVolume.SetStarEvolutionController(starEvolutionController); starFluidVolume.SetStarEvolutionController(starEvolutionController);
if (!string.IsNullOrEmpty(starModule.starCollapseRampTexture))
{
starEvolutionController.collapseRamp = ImageUtilities.GetTexture(mod, starModule.starCollapseRampTexture);
}
surfaceAudio.SetStarEvolutionController(starEvolutionController); 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<HeatHazardVolume>(); starEvolutionController.heatVolume = heatVolume.GetComponent<HeatHazardVolume>();
starEvolutionController.destructionVolume = deathVolume.GetComponent<DestructionVolume>(); starEvolutionController.destructionVolume = deathVolume.GetComponent<DestructionVolume>();
starEvolutionController.planetDestructionVolume = planetDestructionVolume.GetComponent<StarDestructionVolume>(); starEvolutionController.planetDestructionVolume = planetDestructionVolume.GetComponent<StarDestructionVolume>();
starEvolutionController.starFluidVolume = starFluidVolume; starEvolutionController.starFluidVolume = starFluidVolume;
starEvolutionController.oneShotSource = sunAudio.transform.Find("OneShotAudio_Sun")?.GetComponent<OWAudioSource>(); starEvolutionController.oneShotSource = sunAudio.transform.Find("OneShotAudio_Sun")?.GetComponent<OWAudioSource>();
}
else
{
starEvolutionController.willExplode = false;
}
var shockLayerRuleset = sector.gameObject.AddComponent<ShockLayerRuleset>(); var shockLayerRuleset = sector.gameObject.AddComponent<ShockLayerRuleset>();
shockLayerRuleset._type = ShockLayerRuleset.ShockType.Radial; 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) public static GameObject MakeStarProxy(GameObject planet, GameObject proxyGO, StarModule starModule, IModBehaviour mod, bool isStellarRemnant)
{ {
var starGO = MakeStarGraphics(proxyGO, null, starModule, mod); var (starGO, controller, supernova) = SharedStarGeneration(proxyGO, null, mod, starModule, isStellarRemnant);
var ramp = starGO.GetComponentInChildren<TessellatedSphereRenderer>().sharedMaterial.GetTexture(ColorRamp);
var controller = starGO.AddComponent<StarEvolutionController>();
if (starModule.curve != null) controller.SetScaleCurve(starModule.curve);
controller.size = starModule.size;
controller.startColour = starModule.tint;
controller.endColour = starModule.endTint;
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);
// Remnants can't go supernova
if (!isStellarRemnant)
{
var supernova = MakeSupernova(starGO, starModule, true);
supernova.SetIsProxy(true);
starGO.SetActive(false);
controller.isProxy = true; controller.isProxy = true;
controller.supernovaSize = starModule.supernovaSize; // Planet can have multiple stars on them, so find the one that is also a remnant / not a remnant
var duration = starModule.supernovaSize / starModule.supernovaSpeed; // This will bug out if we make quantum stars. Will have to figure that out eventually.
controller.supernovaTime = duration; var mainController = planet.GetComponentsInChildren<StarEvolutionController>(true).Where(x => x.isRemnant == isStellarRemnant).FirstOrDefault();
controller.supernovaScaleEnd = duration; mainController.SetProxy(controller);
controller.supernovaScaleStart = duration * 0.9f;
controller.deathType = starModule.stellarDeathType;
controller.supernova = supernova;
controller.supernovaColour = starModule.supernovaTint; // Remnants can't go supernova
controller.willExplode = starModule.stellarDeathType != StellarDeathType.None; if (supernova != null)
controller.lifespan = starModule.lifespan;
var main = planet.GetComponentInChildren<StarEvolutionController>(true);
main.SetProxy(controller);
supernova._main = main.supernova;
}
else
{ {
controller.willExplode = false; supernova.SetIsProxy(true);
supernova.mainStellerDeathController = mainController.supernova;
} }
return starGO; 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<TessellatedSphereRenderer>(true).sharedMaterial.GetTexture(ColorRamp);
var starEvolutionController = starGO.AddComponent<StarEvolutionController>();
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) public static GameObject MakeStarGraphics(GameObject rootObject, Sector sector, StarModule starModule, IModBehaviour mod)
{ {
if (_colorOverTime == null) _colorOverTime = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/StarColorOverTime.png"); if (_colorOverTime == null) _colorOverTime = ImageUtilities.GetTexture(Main.Instance, "Assets/textures/StarColorOverTime.png");
@ -346,26 +328,26 @@ namespace NewHorizons.Builder.Body
var supernova = supernovaGO.GetComponent<SupernovaEffectController>(); var supernova = supernovaGO.GetComponent<SupernovaEffectController>();
var stellarDeath = supernovaGO.AddComponent<StellarDeathController>(); var stellarDeath = supernovaGO.AddComponent<StellarDeathController>();
stellarDeath.enabled = false; stellarDeath.enabled = false;
stellarDeath._surface = starGO.GetComponentInChildren<TessellatedSphereRenderer>(); stellarDeath.surface = starGO.GetComponentInChildren<TessellatedSphereRenderer>(true);
var duration = starModule.supernovaSize / starModule.supernovaSpeed; 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.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.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.explosionParticles = supernova._explosionParticles;
stellarDeath._shockwave = supernova._shockwave; stellarDeath.shockwave = supernova._shockwave;
stellarDeath._shockwaveLength = supernova._shockwaveLength; stellarDeath.shockwaveLength = supernova._shockwaveLength;
stellarDeath._shockwaveAlpha = supernova._shockwaveAlpha; stellarDeath.shockwaveAlpha = supernova._shockwaveAlpha;
stellarDeath._shockwaveScale = supernova._shockwaveScale; stellarDeath.shockwaveScale = supernova._shockwaveScale;
stellarDeath._supernovaMaterial = supernova._supernovaMaterial; stellarDeath.supernovaMaterial = supernova._supernovaMaterial;
GameObject.Destroy(supernova); GameObject.Destroy(supernova);
if (starModule.supernovaTint != null) if (starModule.supernovaTint != null)
{ {
var colour = starModule.supernovaTint.ToColor(); 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); var ramp = ImageUtilities.LerpGreyscaleImage(ImageUtilities.GetTexture(Main.Instance, "Assets/textures/Effects_SUN_Supernova_d.png"), Color.white, colour);
supernovaMaterial.SetTexture(ColorRamp, ramp); supernovaMaterial.SetTexture(ColorRamp, ramp);
stellarDeath._supernovaMaterial = supernovaMaterial; stellarDeath.supernovaMaterial = supernovaMaterial;
// Motes // Motes
var moteMaterial = supernovaGO.GetComponentInChildren<ParticleSystemRenderer>().material; var moteMaterial = supernovaGO.GetComponentInChildren<ParticleSystemRenderer>().material;
@ -393,10 +375,10 @@ namespace NewHorizons.Builder.Body
audioSource.spatialBlend = 1; audioSource.spatialBlend = 1;
audioSource.volume = 0.5f; audioSource.volume = 0.5f;
audioSource.velocityUpdateMode = AudioVelocityUpdateMode.Fixed; audioSource.velocityUpdateMode = AudioVelocityUpdateMode.Fixed;
stellarDeath._audioSource = supernovaWallAudio.AddComponent<OWAudioSource>(); stellarDeath.audioSource = supernovaWallAudio.AddComponent<OWAudioSource>();
stellarDeath._audioSource._audioSource = audioSource; stellarDeath.audioSource._audioSource = audioSource;
stellarDeath._audioSource._audioLibraryClip = AudioType.Sun_SupernovaWall_LP; stellarDeath.audioSource._audioLibraryClip = AudioType.Sun_SupernovaWall_LP;
stellarDeath._audioSource.SetTrack(OWAudioMixer.TrackName.EndTimes_SFX); stellarDeath.audioSource.SetTrack(OWAudioMixer.TrackName.EndTimes_SFX);
} }
supernovaGO.SetActive(true); supernovaGO.SetActive(true);

View File

@ -17,6 +17,7 @@ namespace NewHorizons.Components.SizeControllers
public class StarEvolutionController : SizeController public class StarEvolutionController : SizeController
{ {
public bool isProxy; public bool isProxy;
public bool isRemnant;
public GameObject atmosphere; public GameObject atmosphere;
public StarController controller; public StarController controller;
@ -86,8 +87,12 @@ namespace NewHorizons.Components.SizeControllers
private Color _currentColour; private Color _currentColour;
private TessellatedSphereRenderer _surface;
private void Start() private void Start()
{ {
_surface = GetComponentInChildren<TessellatedSphereRenderer>(true);
_rigidbody = this.GetAttachedOWRigidbody(); _rigidbody = this.GetAttachedOWRigidbody();
var sun = GameObject.FindObjectOfType<SunController>(); var sun = GameObject.FindObjectOfType<SunController>();
@ -163,7 +168,7 @@ namespace NewHorizons.Components.SizeControllers
} }
_flareEmitter = GetComponentInChildren<SolarFlareEmitter>(); _flareEmitter = GetComponentInChildren<SolarFlareEmitter>();
_surfaceMaterial = supernova._surface._materials[0]; _surfaceMaterial = _surface._materials[0];
if (!isProxy) SupernovaEffectHandler.RegisterStar(this); if (!isProxy) SupernovaEffectHandler.RegisterStar(this);
@ -189,7 +194,7 @@ namespace NewHorizons.Components.SizeControllers
public void SetProxy(StarEvolutionController proxy) public void SetProxy(StarEvolutionController proxy)
{ {
_proxy = proxy; _proxy = proxy;
_proxy.supernova.SetIsProxy(true); _proxy.supernova?.SetIsProxy(true);
} }
private void UpdateMainSequence() private void UpdateMainSequence()
@ -204,21 +209,21 @@ namespace NewHorizons.Components.SizeControllers
if (t < 1f) if (t < 1f)
{ {
_currentColour = Color.Lerp(_startColour, _endColour, t); _currentColour = Color.Lerp(_startColour, _endColour, t);
supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, t); _surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, t);
supernova._surface._materials[0].SetFloat(ColorTime, t); _surface._materials[0].SetFloat(ColorTime, t);
} }
else else
{ {
_currentColour = _endColour; _currentColour = _endColour;
supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, 1); _surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, 1);
supernova._surface._materials[0].SetFloat(ColorTime, 1); _surface._materials[0].SetFloat(ColorTime, 1);
} }
} }
else else
{ {
_currentColour = _startColour; _currentColour = _startColour;
supernova._surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, 0); _surface._materials[0].Lerp(_startSurfaceMaterial, _endSurfaceMaterial, 0);
supernova._surface._materials[0].SetFloat(ColorTime, 0); _surface._materials[0].SetFloat(ColorTime, 0);
} }
if (_flareEmitter != null) _flareEmitter._tint = _currentColour; if (_flareEmitter != null) _flareEmitter._tint = _currentColour;
@ -234,7 +239,7 @@ namespace NewHorizons.Components.SizeControllers
_currentColour = Color.Lerp(_endColour, Color.white, t); _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 // After the collapse is done we go supernova
if (_collapseTimer > collapseTime) StartSupernova(); if (_collapseTimer > collapseTime) StartSupernova();
@ -324,7 +329,7 @@ namespace NewHorizons.Components.SizeControllers
_isCollapsing = true; _isCollapsing = true;
_collapseStartSize = CurrentScale; _collapseStartSize = CurrentScale;
_collapseTimer = 0f; _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 (oneShotSource != null && !PlayerState.IsSleepingAtCampfire() && !PlayerState.InDreamWorld()) oneShotSource.PlayOneShot(AudioType.Sun_Collapse);
if (_proxy != null) _proxy.StartCollapse(); if (_proxy != null) _proxy.StartCollapse();
@ -338,7 +343,7 @@ namespace NewHorizons.Components.SizeControllers
CollapseStop.Invoke(); CollapseStop.Invoke();
_isCollapsing = false; _isCollapsing = false;
supernova._surface._materials[0].CopyPropertiesFromMaterial(_endSurfaceMaterial); _surface._materials[0].CopyPropertiesFromMaterial(_endSurfaceMaterial);
if (_proxy != null) _proxy.StopCollapse(); if (_proxy != null) _proxy.StopCollapse();
} }
@ -384,8 +389,8 @@ namespace NewHorizons.Components.SizeControllers
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;
supernova._surface._materials[0] = _surfaceMaterial; _surface._materials[0] = _surfaceMaterial;
supernova._surface.transform.localScale = Vector3.one; _surface.transform.localScale = Vector3.one;
if (_proxy != null) _proxy.StopSupernova(); if (_proxy != null) _proxy.StopSupernova();
} }

View File

@ -7,19 +7,20 @@ namespace NewHorizons.Components
{ {
public class StellarDeathController : MonoBehaviour public class StellarDeathController : MonoBehaviour
{ {
public ParticleSystem[] _explosionParticles; public ParticleSystem[] explosionParticles;
public MeshRenderer _shockwave; public MeshRenderer shockwave;
public float _shockwaveLength = 5f; public float shockwaveLength = 5f;
public AnimationCurve _shockwaveScale = AnimationCurve.Linear(0.0f, 0.0f, 1f, 100000f); public AnimationCurve shockwaveScale = AnimationCurve.Linear(0.0f, 0.0f, 1f, 100000f);
public AnimationCurve _shockwaveAlpha = AnimationCurve.Linear(0.0f, 1f, 1f, 0.0f); public AnimationCurve shockwaveAlpha = AnimationCurve.Linear(0.0f, 1f, 1f, 0.0f);
public TessellatedSphereRenderer _surface; public TessellatedSphereRenderer surface;
public Material _supernovaMaterial; 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 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 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 _time;
private float _currentSupernovaScale; private float _currentSupernovaScale;
private Material _localSupernovaMat; private Material _localSupernovaMat;
@ -28,58 +29,59 @@ namespace NewHorizons.Components
public void Awake() public void Awake()
{ {
_cachedParticleRenderers = new ParticleSystemRenderer[_explosionParticles.Length]; _cachedParticleRenderers = new ParticleSystemRenderer[explosionParticles.Length];
for (int index = 0; index < _explosionParticles.Length; ++index) for (int index = 0; index < explosionParticles.Length; ++index)
_cachedParticleRenderers[index] = _explosionParticles[index].GetComponent<ParticleSystemRenderer>(); _cachedParticleRenderers[index] = explosionParticles[index].GetComponent<ParticleSystemRenderer>();
} }
public void Activate() public void Activate()
{ {
enabled = true; enabled = true;
_shockwave.enabled = true; shockwave.enabled = true;
foreach (var particle in _explosionParticles) particle.Play(); foreach (var particle in explosionParticles) particle.Play();
_time = 0.0f; _time = 0.0f;
_currentSupernovaScale = _supernovaScale.Evaluate(0.0f); _currentSupernovaScale = supernovaScale.Evaluate(0.0f);
_localSupernovaMat = new Material(_supernovaMaterial); _localSupernovaMat = new Material(supernovaMaterial);
_surface.sharedMaterial = _localSupernovaMat; surface.sharedMaterial = _localSupernovaMat;
if (_audioSource == null) return; if (audioSource == null) return;
_audioSource.AssignAudioLibraryClip(AudioType.Sun_SupernovaWall_LP); audioSource.AssignAudioLibraryClip(AudioType.Sun_SupernovaWall_LP);
_audioSource.SetLocalVolume(0); audioSource.SetLocalVolume(0);
_audioSource.Play(); audioSource.Play();
} }
public void Deactivate() public void Deactivate()
{ {
enabled = false; enabled = false;
_shockwave.enabled = false; shockwave.enabled = false;
if (_audioSource == null) return; if (audioSource == null) return;
_audioSource.SetLocalVolume(0); audioSource.SetLocalVolume(0);
_audioSource.Stop(); audioSource.Stop();
} }
public void FixedUpdate() public void FixedUpdate()
{ {
if (_main != null) _time = _main._time; if (mainStellerDeathController != null) _time = mainStellerDeathController._time;
else _time += Time.deltaTime; else _time += Time.deltaTime;
float shockwaveTime = Mathf.Clamp01(_time / _shockwaveLength);
_shockwave.transform.localScale = Vector3.one * _shockwaveScale.Evaluate(shockwaveTime); float shockwaveTime = Mathf.Clamp01(_time / shockwaveLength);
_shockwave.material.color = Color.Lerp(Color.black, _shockwave.sharedMaterial.color, _shockwaveAlpha.Evaluate(shockwaveTime)); shockwave.transform.localScale = Vector3.one * shockwaveScale.Evaluate(shockwaveTime);
_currentSupernovaScale = _supernovaScale.Evaluate(_time); shockwave.material.color = Color.Lerp(Color.black, shockwave.sharedMaterial.color, shockwaveAlpha.Evaluate(shockwaveTime));
_surface.transform.localScale = Vector3.one * _currentSupernovaScale; _currentSupernovaScale = supernovaScale.Evaluate(_time);
_localSupernovaMat.color = Color.Lerp(Color.black, _supernovaMaterial.color, _supernovaAlpha.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()); float distanceToPlayer = PlayerState.InDreamWorld() ? 20000f : (Vector3.Distance(transform.position, Locator.GetPlayerCamera().transform.position) - GetSupernovaRadius());
if (_isProxy) return; if (_isProxy) return;
if (_audioSource != null) if (audioSource != null)
{ {
float dt = Mathf.InverseLerp(12000f, 0.0f, distanceToPlayer); 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); RumbleManager.UpdateSupernova(distanceToPlayer);
@ -99,7 +101,7 @@ namespace NewHorizons.Components
public void SetRenderingEnabled(bool renderingEnabled) public void SetRenderingEnabled(bool renderingEnabled)
{ {
if (!enabled) return; if (!enabled) return;
_shockwave.enabled = renderingEnabled; shockwave.enabled = renderingEnabled;
SetParticlesVisibility(renderingEnabled); SetParticlesVisibility(renderingEnabled);
} }
} }

View File

@ -508,12 +508,12 @@ namespace NewHorizons.Handlers
if (body.Config.Star != null) 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 (starController != null) StarLightController.AddStar(starController);
// If it has an evolution controller that means it will die -> we make a remnant // If it has an evolution controller that means it will die -> we make a remnant (unless its a remnant)
if (starEvolutionController != null) if (starEvolutionController != null && !body.Config.isStellarRemnant)
{ {
GameObject remnantGO; GameObject remnantGO;

View File

@ -108,11 +108,12 @@ namespace NewHorizons.Handlers
public static SunController GetSunController() => _sunController; public static SunController GetSunController() => _sunController;
public static bool InPointInsideAnySupernova(Vector3 position) public static bool IsPointInsideAnySupernova(Vector3 position)
{ {
foreach (var starEvolutionController in _starEvolutionControllers) foreach (var starEvolutionController in _starEvolutionControllers)
{ {
if (!IsStarActive(starEvolutionController)) continue; if (!IsStarActive(starEvolutionController)) continue;
if (starEvolutionController.supernova == null) continue;
var distanceSqr = (position - starEvolutionController.transform.position).sqrMagnitude; var distanceSqr = (position - starEvolutionController.transform.position).sqrMagnitude;
var size = starEvolutionController.GetSupernovaRadius(); var size = starEvolutionController.GetSupernovaRadius();

View File

@ -47,7 +47,7 @@ namespace NewHorizons.Patches
} }
else else
{ {
__result = SupernovaEffectHandler.InPointInsideAnySupernova(__instance._realObjectTransform.position); __result = SupernovaEffectHandler.IsPointInsideAnySupernova(__instance._realObjectTransform.position);
return false; return false;
} }
} }