Skip to content

Commit

Permalink
1.16.1 (#719)
Browse files Browse the repository at this point in the history
## Bug fixes
- Fixed systems being added to the shiplog multiple times
- Fixed stars without remnants not exploding
- Fixed proxy exploding independently of the main star
- Fixed proxy explosion showing if it started while in the map screen.
Resolves #718
  • Loading branch information
xen-42 committed Aug 27, 2023
2 parents db9d47f + 2a87997 commit fdc9672
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 39 deletions.
56 changes: 35 additions & 21 deletions NewHorizons/Components/SizeControllers/StarEvolutionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private void Start()

var secondsElapsed = TimeLoop.GetSecondsElapsed();
var lifespanInSeconds = lifespan * 60;
if (willExplode && secondsElapsed >= lifespanInSeconds)
if (!isProxy && willExplode && secondsElapsed >= lifespanInSeconds)
{
var timeAfter = secondsElapsed - lifespanInSeconds;
if (timeAfter <= collapseTime)
Expand Down Expand Up @@ -271,7 +271,8 @@ private void UpdateCollapse()
_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()
Expand Down Expand Up @@ -364,10 +365,7 @@ public void StartCollapse()
_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()
Expand All @@ -380,7 +378,7 @@ public void StopCollapse()
_isCollapsing = false;
_surface._materials[0].CopyPropertiesFromMaterial(_endSurfaceMaterial);

if (_proxy != null) _proxy.StopCollapse();
_proxy?.StopCollapse();
}

public void StartSupernova()
Expand All @@ -394,19 +392,24 @@ public void StartSupernova()
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();
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()
Expand All @@ -416,26 +419,33 @@ public void StopSupernova()
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;
Expand Down Expand Up @@ -472,7 +482,11 @@ protected new void FixedUpdate()
{
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
{
Expand Down
15 changes: 11 additions & 4 deletions NewHorizons/Components/Stars/StellarDeathController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@ public void Awake()
public void Activate()
{
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();
_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);
Expand Down
5 changes: 1 addition & 4 deletions NewHorizons/Handlers/PlanetCreationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using UnityEngine;
using NewHorizons.Streaming;
using Newtonsoft.Json;
using NewHorizons.External.Modules.VariableSize;

namespace NewHorizons.Handlers
{
Expand Down Expand Up @@ -604,10 +605,6 @@ private static GameObject SharedGenerateBody(NewHorizonsBody body, GameObject go
remnantGO.SetActive(false);
starEvolutionController.SetStellarRemnant(remnantGO);
}
else
{
starEvolutionController.willExplode = false;
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions NewHorizons/Patches/ShipLogPatches/ShipLogFactPatches.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HarmonyLib;
using NewHorizons.Handlers;
using NewHorizons.OtherMods.AchievementsPlus;

namespace NewHorizons.Patches.ShipLogPatches
{
Expand All @@ -20,5 +21,13 @@ public static bool ShipLogFact_GetText(ShipLogFact __instance, ref string __resu
return true;
}
}

[HarmonyPostfix]
[HarmonyPatch(nameof(ShipLogFact.Reveal))]
public static void ShipLogFact_Reveal(ShipLogFact __instance)
{
StarChartHandler.OnRevealFact(__instance.GetID());
AchievementHandler.OnRevealFact();
}
}
}
10 changes: 1 addition & 9 deletions NewHorizons/Patches/ShipLogPatches/ShipLogManagerPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using NewHorizons.Builder.ShipLog;
using NewHorizons.External;
using NewHorizons.Handlers;
using NewHorizons.OtherMods.AchievementsPlus;
using NewHorizons.Utility.OWML;
using System.Collections.Generic;
using UnityEngine;
Expand Down Expand Up @@ -75,6 +74,7 @@ public static void ShipLogManager_Awake_Postfix(ShipLogManager __instance)
[HarmonyPatch(nameof(ShipLogManager.IsFactRevealed))]
public static bool ShipLogManager_IsFactRevealed(ShipLogManager __instance, ref bool __result, string id)
{
// normally throws an error on not found
if (__instance._factDict != null && __instance._factDict.ContainsKey(id))
{
__result = __instance._factDict[id].IsRevealed();
Expand Down Expand Up @@ -126,13 +126,5 @@ public static bool ShipLogManager_Start(ShipLogManager __instance)
return false;
}
}

[HarmonyPostfix]
[HarmonyPatch(nameof(ShipLogManager.RevealFact))]
public static void ShipLogManager_RevealFact(string id)
{
StarChartHandler.OnRevealFact(id);
AchievementHandler.OnRevealFact();
}
}
}
2 changes: 1 addition & 1 deletion NewHorizons/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "xen, Bwc9876, clay, MegaPiggy, John, Trifid, Hawkbar, Book",
"name": "New Horizons",
"uniqueName": "xen.NewHorizons",
"version": "1.16.0",
"version": "1.16.1",
"owmlVersion": "2.9.3",
"dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ],
"conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ],
Expand Down

0 comments on commit fdc9672

Please sign in to comment.