Planets now get destroyed in stars

This commit is contained in:
Nick 2022-03-21 19:24:32 -04:00
parent a7b443c27e
commit bd4a118ee8
8 changed files with 58 additions and 10 deletions

View File

@ -211,6 +211,8 @@ namespace NewHorizons.Builder.Body
var destructionVolume = child.gameObject.AddComponent<DestructionVolume>(); var destructionVolume = child.gameObject.AddComponent<DestructionVolume>();
destructionVolume._deathType = deathType; destructionVolume._deathType = deathType;
// Only stars should destroy planets
destructionVolume._onlyAffectsPlayerAndShip = deathType != DeathType.Energy;
} }
} }
} }

View File

@ -108,6 +108,8 @@ namespace NewHorizons.Builder.Body
deathVolume.transform.localPosition = Vector3.zero; deathVolume.transform.localPosition = Vector3.zero;
deathVolume.transform.localScale = Vector3.one; deathVolume.transform.localScale = Vector3.one;
deathVolume.GetComponent<SphereCollider>().radius = 1f; deathVolume.GetComponent<SphereCollider>().radius = 1f;
deathVolume.GetComponent<DestructionVolume>()._onlyAffectsPlayerAndShip = false;
deathVolume.GetComponent<DestructionVolume>()._shrinkBodies = false;
deathVolume.name = "DestructionVolume"; deathVolume.name = "DestructionVolume";
TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>(); TessellatedSphereRenderer surface = sunSurface.GetComponent<TessellatedSphereRenderer>();

View File

@ -8,28 +8,38 @@ using System.Reflection;
using UnityEngine; using UnityEngine;
using NewHorizons.Utility; using NewHorizons.Utility;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
using NewHorizons.External.Configs;
namespace NewHorizons.Builder.General namespace NewHorizons.Builder.General
{ {
static class DetectorBuilder static class DetectorBuilder
{ {
public static GameObject Make(GameObject body, OWRigidbody OWRB, AstroObject primaryBody, AstroObject astroObject, bool inherit, bool destroyedBySun) public static GameObject Make(GameObject body, OWRigidbody OWRB, AstroObject primaryBody, AstroObject astroObject, IPlanetConfig config)
{ {
GameObject detectorGO = new GameObject("FieldDetector"); GameObject detectorGO = new GameObject("FieldDetector");
detectorGO.SetActive(false); detectorGO.SetActive(false);
detectorGO.transform.parent = body.transform; detectorGO.transform.parent = body.transform;
detectorGO.transform.localPosition = Vector3.zero; detectorGO.transform.localPosition = Vector3.zero;
detectorGO.layer = 20; detectorGO.layer = LayerMask.NameToLayer("BasicDetector");
ConstantForceDetector forceDetector = detectorGO.AddComponent<ConstantForceDetector>(); ConstantForceDetector forceDetector = detectorGO.AddComponent<ConstantForceDetector>();
forceDetector.SetValue("_inheritElement0", inherit); forceDetector.SetValue("_inheritElement0", true);
OWRB.RegisterAttachedForceDetector(forceDetector); OWRB.RegisterAttachedForceDetector(forceDetector);
// For falling into sun // For falling into sun
if(destroyedBySun) if(!config.Base.InvulnerableToSun && config.Star == null && config.FocalPoint == null)
{ {
detectorGO.layer = LayerMask.NameToLayer("AdvancedDetector");
var fluidDetector = detectorGO.AddComponent<DynamicFluidDetector>(); var fluidDetector = detectorGO.AddComponent<DynamicFluidDetector>();
// Could copy the splash from the interloper var sphereCollider = detectorGO.AddComponent<SphereCollider>();
sphereCollider.radius = config.Base.SurfaceSize;
var owCollider = detectorGO.AddComponent<OWCollider>();
fluidDetector._collider = sphereCollider;
// Could copy the splash from the interloper as well some day
} }
GravityVolume parentGravityVolume = primaryBody?.GetAttachedOWRigidbody()?.GetAttachedGravityVolume(); GravityVolume parentGravityVolume = primaryBody?.GetAttachedOWRigidbody()?.GetAttachedGravityVolume();

View File

@ -80,9 +80,9 @@ namespace NewHorizons.Builder.Props
StreamingManager.LoadStreamingAssets(child.assetBundle); StreamingManager.LoadStreamingAssets(child.assetBundle);
} }
var detectorGO = DetectorBuilder.Make(raftObject, owRigidBody, ao, null, false, false); //var detectorGO = DetectorBuilder.Make(raftObject, owRigidBody, ao, null, false, false);
var fluidDetector = detectorGO.AddComponent<DynamicFluidDetector>(); //var fluidDetector = detectorGO.AddComponent<DynamicFluidDetector>();
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => fluidDetector._activeVolumes = new EffectVolume[] { body.GetComponentInChildren<RadialFluidVolume>() }.ToList()); //Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => fluidDetector._activeVolumes = new EffectVolume[] { body.GetComponentInChildren<RadialFluidVolume>() }.ToList());
var targetBodyAlignment = raftObject.AddComponent<AlignWithTargetBody>(); var targetBodyAlignment = raftObject.AddComponent<AlignWithTargetBody>();

View File

@ -23,5 +23,14 @@ namespace NewHorizons.Components
var dist = (transform.position - target.position).magnitude; var dist = (transform.position - target.position).magnitude;
transform.localScale = new Vector3(num, dist/500f, num); transform.localScale = new Vector3(num, dist/500f, num);
} }
private void Update()
{
// The target or anchor could have been destroyed by a star
if(!target.gameObject.activeInHierarchy || !anchor.gameObject.activeInHierarchy)
{
gameObject.SetActive(false);
}
}
} }
} }

View File

@ -1,4 +1,5 @@
using NewHorizons.Builder.General; using NewHorizons.Builder.General;
using NewHorizons.External.Configs;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -12,9 +13,13 @@ namespace NewHorizons.Components
{ {
public void Awake() public void Awake()
{ {
// TODO: eventually all bodies should have configs
var config = new PlanetConfig(null);
config.Base.SurfaceSize = 10f;
var detector = base.transform.GetComponentInChildren<DynamicForceDetector>(); var detector = base.transform.GetComponentInChildren<DynamicForceDetector>();
var ao = base.GetComponent<AstroObject>(); var ao = base.GetComponent<AstroObject>();
var newDetector = DetectorBuilder.Make(base.gameObject, ao.GetAttachedOWRigidbody(), ao.GetPrimaryBody(), ao, true, false); var newDetector = DetectorBuilder.Make(base.gameObject, ao.GetAttachedOWRigidbody(), ao.GetPrimaryBody(), ao, config);
newDetector.transform.parent = detector.transform.parent; newDetector.transform.parent = detector.transform.parent;
GameObject.Destroy(detector); GameObject.Destroy(detector);
} }

View File

@ -23,5 +23,25 @@ namespace NewHorizons.Components.Orbital
{ {
FakeMassBody.SetActive(true); FakeMassBody.SetActive(true);
} }
void Update()
{
// Secondary and primary must have been engulfed by a star
if(!Primary.isActiveAndEnabled && !Secondary.isActiveAndEnabled)
{
ReferenceFrameTracker component = Locator.GetPlayerBody().GetComponent<ReferenceFrameTracker>();
if (component.GetReferenceFrame(true) != null && component.GetReferenceFrame(true).GetOWRigidBody() == gameObject)
{
component.UntargetReferenceFrame();
}
MapMarker component2 = gameObject.GetComponent<MapMarker>();
if (component2 != null)
{
component2.DisableMarker();
}
gameObject.SetActive(false);
FakeMassBody.SetActive(false);
}
}
} }
} }

View File

@ -274,7 +274,7 @@ namespace NewHorizons.Handlers
if (body.Config.Orbit.ShowOrbitLine && !body.Config.Orbit.IsStatic) OrbitlineBuilder.Make(body.Object, ao, body.Config.Orbit.IsMoon, body.Config); if (body.Config.Orbit.ShowOrbitLine && !body.Config.Orbit.IsStatic) OrbitlineBuilder.Make(body.Object, ao, body.Config.Orbit.IsMoon, body.Config);
if (!body.Config.Orbit.IsStatic) DetectorBuilder.Make(go, owRigidBody, primaryBody, ao, true, (body.Config.Star == null && !body.Config.Base.InvulnerableToSun)); if (!body.Config.Orbit.IsStatic) DetectorBuilder.Make(go, owRigidBody, primaryBody, ao, body.Config);
if (ao.GetAstroObjectName() == AstroObject.Name.CustomString) AstroObjectLocator.RegisterCustomAstroObject(ao); if (ao.GetAstroObjectName() == AstroObject.Name.CustomString) AstroObjectLocator.RegisterCustomAstroObject(ao);