Allow starting in other star system

This commit is contained in:
Nick J. Connors 2022-02-24 17:52:39 -05:00
parent 9b0d90ca9a
commit cdac659dd0
7 changed files with 78 additions and 41 deletions

View File

@ -70,6 +70,7 @@ namespace NewHorizons.Builder.General
if (config.Base.CenterOfSolarSystem)
{
Logger.Log($"Setting center of universe to {config.Name}");
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => Locator.GetCenterOfTheUniverse()._staticReferenceFrame = owRigidBody, 2);
}

View File

@ -35,11 +35,18 @@ namespace NewHorizons.Builder.General
public static void RemoveSolarSystem()
{
// Stop the sun from killing the player
var sunVolumes = GameObject.Find("Sun_Body/Sector_SUN/Volumes_SUN");
sunVolumes.SetActive(false);
foreach(var name in _solarSystemBodies)
{
var ao = AstroObjectLocator.GetAstroObject(name);
if (ao != null) RemoveBody(ao);
if (ao != null) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => RemoveBody(ao));
}
// Bring the sun back because why not
Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => { if (Locator.GetAstroObject(AstroObject.Name.Sun).gameObject.activeInHierarchy) { sunVolumes.SetActive(true); } }, 2);
}
public static void RemoveBody(AstroObject ao, List<AstroObject> toDestroy = null)
@ -109,6 +116,11 @@ namespace NewHorizons.Builder.General
GameObject.Find("QuantumIsland_Body").SetActive(false);
GameObject.Find("StatueIsland_Body").SetActive(false);
GameObject.Find("ConstructionYardIsland_Body").SetActive(false);
GameObject.Find("GabbroShip_Body").SetActive(false);
foreach(var jelly in GameObject.FindObjectsOfType<JellyfishController>())
{
jelly.gameObject.SetActive(false);
}
}
else if(ao.GetAstroObjectName() == AstroObject.Name.WhiteHole)
{
@ -118,6 +130,15 @@ namespace NewHorizons.Builder.General
else if(ao.GetAstroObjectName() == AstroObject.Name.TimberHearth)
{
GameObject.Find("MiningRig_Body").SetActive(false);
foreach(var obj in GameObject.FindObjectsOfType<DayNightTracker>())
{
GameObject.Destroy(obj);
}
foreach (var obj in GameObject.FindObjectsOfType<VillageMusicVolume>())
{
GameObject.Destroy(obj);
}
}
else if(ao.GetAstroObjectName() == AstroObject.Name.Sun)
{
@ -140,7 +161,11 @@ namespace NewHorizons.Builder.General
GameObject.Destroy(audioSource);
}
GameObject.Find("SunProxy(Clone)/Sun_Proxy_Body").SetActive(false);
foreach(var sunProxy in GameObject.FindObjectsOfType<SunProxy>())
{
Logger.Log($"Destroying SunProxy {sunProxy.gameObject.name}");
GameObject.Destroy(sunProxy.gameObject);
}
}
else if(ao.GetAstroObjectName() == AstroObject.Name.DreamWorld)
{
@ -157,22 +182,25 @@ namespace NewHorizons.Builder.General
break;
}
}
Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => RemoveProxy(ao.name.Replace("_Body", "")));
RemoveProxy(ao.name.Replace("_Body", ""));
ao.transform.root.gameObject.SetActive(false);
foreach (ProxyBody proxy in GameObject.FindObjectsOfType<ProxyBody>())
{
if (proxy?._realObjectTransform?.gameObject == ao.gameObject)
{
GameObject.Destroy(proxy.gameObject);
}
}
HeavenlyBodyBuilder.Remove(ao);
}
public static void RemoveDistantProxyClones()
{
foreach(ProxyBody proxy in GameObject.FindObjectsOfType<ProxyBody>())
{
if(proxy.transform.name.Contains("_DistantProxy(Clone"))
{
GameObject.Destroy(proxy.gameObject);
}
}
GameObject.Destroy(GameObject.FindObjectOfType<DistantProxyManager>().gameObject);
}
private static void RemoveProxy(string name)

View File

@ -56,19 +56,9 @@ namespace NewHorizons.Components
// Conditions to allow warping into that system (either no planets (stock system) or has a ship spawn point)
var flag = false;
if (starSystem.Equals("SolarSystem")) flag = true;
else
{
foreach(var body in Main.BodyDict[starSystem])
{
if(body.Config?.Spawn?.ShipSpawnPoint != null)
{
flag = true;
break;
}
}
}
else if (Main.SystemDict[starSystem].Spawn?.ShipSpawnPoint != null) flag = true;
if(flag)
if (flag && Main.SystemDict[starSystem].Config.canEnterViaWarpDrive)
{
var card = CreateCard(starSystem, root.transform, new Vector2(x++ * 200, 0));
_starSystemCards.Add(card);

View File

@ -6,6 +6,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using NewHorizons.Utility;
using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Components
@ -25,6 +26,18 @@ namespace NewHorizons.Components
private const float size = 14f;
private readonly string _blackHolePath = "TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_TT/Prefab_NOM_WarpTransmitter (1)/BlackHole/BlackHoleSingularity";
private readonly string _whiteHolePath = "TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_CT/Prefab_NOM_WarpTransmitter/WhiteHole/WhiteHoleSingularity";
private GameObject _blackHolePrefab;
private GameObject _whiteHolePrefab;
public void Init()
{
_blackHolePrefab = GameObject.Find(_blackHolePath);
_whiteHolePrefab = GameObject.Find(_whiteHolePath);
}
public void Start()
{
MakeBlackHole();
@ -44,7 +57,8 @@ namespace NewHorizons.Components
private void MakeBlackHole()
{
var blackHoleShader = GameObject.Find("TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_TT/Prefab_NOM_WarpTransmitter (1)/BlackHole/BlackHoleSingularity").GetComponent<MeshRenderer>().material.shader;
var blackHoleShader = _blackHolePrefab.GetComponent<MeshRenderer>().material.shader;
if (blackHoleShader == null) blackHoleShader = _blackHolePrefab.GetComponent<MeshRenderer>().sharedMaterial.shader;
var blackHoleRender = new GameObject("BlackHoleRender");
blackHoleRender.transform.parent = base.transform;
@ -52,10 +66,9 @@ namespace NewHorizons.Components
blackHoleRender.transform.localScale = Vector3.one * size;
var meshFilter = blackHoleRender.AddComponent<MeshFilter>();
meshFilter.mesh = GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent<MeshFilter>().mesh;
meshFilter.mesh = _blackHolePrefab.GetComponent<MeshFilter>().mesh;
var meshRenderer = blackHoleRender.AddComponent<MeshRenderer>();
if (blackHoleShader == null) blackHoleShader = GameObject.Find("BrittleHollow_Body/BlackHole_BH/BlackHoleRenderer").GetComponent<MeshRenderer>().sharedMaterial.shader;
meshRenderer.material = new Material(blackHoleShader);
meshRenderer.material.SetFloat("_Radius", size * 0.4f);
meshRenderer.material.SetFloat("_MaxDistortRadius", size * 0.95f);
@ -68,7 +81,8 @@ namespace NewHorizons.Components
private void MakeWhiteHole()
{
var whiteHoleShader = GameObject.Find("TowerTwin_Body/Sector_TowerTwin/Sector_Tower_HGT/Interactables_Tower_HGT/Interactables_Tower_CT/Prefab_NOM_WarpTransmitter/WhiteHole/WhiteHoleSingularity").GetComponent<MeshRenderer>().material.shader;
var whiteHoleShader = _whiteHolePrefab.GetComponent<MeshRenderer>().material.shader;
if (whiteHoleShader == null) whiteHoleShader = _whiteHolePrefab.GetComponent<MeshRenderer>().sharedMaterial.shader;
var whiteHoleRenderer = new GameObject("WhiteHoleRenderer");
whiteHoleRenderer.transform.parent = base.transform;
@ -76,10 +90,9 @@ namespace NewHorizons.Components
whiteHoleRenderer.transform.localScale = Vector3.one * size * 2.8f;
var meshFilter = whiteHoleRenderer.AddComponent<MeshFilter>();
meshFilter.mesh = GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent<MeshFilter>().mesh;
meshFilter.mesh = _whiteHolePrefab.GetComponent<MeshFilter>().mesh;
var meshRenderer = whiteHoleRenderer.AddComponent<MeshRenderer>();
if (whiteHoleShader == null) whiteHoleShader = GameObject.Find("WhiteHole_Body/WhiteHoleVisuals/Singularity").GetComponent<MeshRenderer>().sharedMaterial.shader;
meshRenderer.material = new Material(whiteHoleShader);
meshRenderer.sharedMaterial.SetFloat("_Radius", size * 0.4f);
meshRenderer.sharedMaterial.SetFloat("_DistortFadeDist", size);

View File

@ -37,7 +37,7 @@ namespace NewHorizons.Utility
Logger.Log($"Removing star from list: {star?.gameObject?.name}");
if (_stars.Contains(star))
{
if (_activeStar.Equals(star))
if (_activeStar != null && _activeStar.Equals(star))
{
_stars.Remove(star);
if(_stars.Count > 0) ChangeActiveStar(_stars[0]);

View File

@ -20,8 +20,6 @@ namespace NewHorizons.External.Configs
if (property == null) property = GetType().GetProperty(item.Key.ToCamelCase(), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
if (property == null) property = GetType().GetProperty(item.Key.ToTitleCase(), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
Logger.Log($"Couldn't find [{item.Key}] in [{string.Concat(GetType().GetProperties().Select(x => x.Name))}] for [{GetType()}]");
if (property != null)
{
if (property.PropertyType.BaseType == typeof(Module))

View File

@ -17,6 +17,7 @@ using Newtonsoft.Json.Linq;
using OWML.Common;
using OWML.ModHelper;
using OWML.Utils;
using PacificEngine.OW_CommonResources.Game.Player;
using System;
using System.Collections.Generic;
using System.IO;
@ -139,7 +140,8 @@ namespace NewHorizons
{
Logger.Log("Setting up warp drive");
_shipWarpController = GameObject.Find("Ship_Body").AddComponent<ShipWarpController>();
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => StarChartHandler.Init());
_shipWarpController.Init();
StarChartHandler.Init();
LoadBody(LoadConfig(this, "AssetBundle/WarpDriveConfig.json"));
}
@ -234,16 +236,17 @@ namespace NewHorizons
Logger.Log("Done loading bodies");
// I don't know what these do but they look really weird from a distance
Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => PlanetDestroyer.RemoveDistantProxyClones());
Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveDistantProxyClones(), 1);
if(!_currentStarSystem.Equals("SolarSystem")) Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveSolarSystem(), 2);
if(!_currentStarSystem.Equals("SolarSystem")) PlanetDestroyer.RemoveSolarSystem();
var map = GameObject.FindObjectOfType<MapController>();
if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f;
Logger.Log($"Is the player warping in? {IsWarping}");
if (IsWarping && _shipWarpController) Instance.ModHelper.Events.Unity.FireInNUpdates(() => _shipWarpController.WarpIn(WearingSuit), 1);
else Instance.ModHelper.Events.Unity.FireInNUpdates(() => GameObject.FindObjectOfType<PlayerSpawner>().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint), 1);
if (IsWarping && _shipWarpController) Instance.ModHelper.Events.Unity.FireInNUpdates(() => _shipWarpController.WarpIn(WearingSuit), 5);
else Instance.ModHelper.Events.Unity.FireInNUpdates(() => GameObject.FindObjectOfType<PlayerSpawner>().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint), 5);
IsWarping = false;
}
@ -408,7 +411,7 @@ namespace NewHorizons
if (!BodyDict.ContainsKey(config.StarSystem))
{
// See if theres a star system config
var starSystemConfig = mod.ModHelper.Storage.Load<StarSystemConfig>($"{config.StarSystem}.json");
var starSystemConfig = mod.ModHelper.Storage.Load<StarSystemConfig>($"systems/{config.StarSystem}.json");
if (starSystemConfig == null) starSystemConfig = new StarSystemConfig(null);
else Logger.Log($"Loaded system config for {config.StarSystem}");
@ -454,8 +457,8 @@ namespace NewHorizons
if (body.Config.Destroy)
{
var ao = existingPlanet.GetComponent<AstroObject>();
if (ao != null) Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveBody(ao), 5);
else Instance.ModHelper.Events.Unity.FireInNUpdates(() => existingPlanet.SetActive(false), 5);
if (ao != null) Instance.ModHelper.Events.Unity.FireInNUpdates(() => PlanetDestroyer.RemoveBody(ao), 1);
else Instance.ModHelper.Events.Unity.FireInNUpdates(() => existingPlanet.SetActive(false), 1);
}
else UpdateBody(body, existingPlanet);
}
@ -718,7 +721,11 @@ namespace NewHorizons
void OnDeath(DeathType _)
{
// We reset the solar system on death (unless we just killed the player)
if (!_isChangingStarSystem) _currentStarSystem = _defaultStarSystem;
if (!_isChangingStarSystem)
{
_currentStarSystem = _defaultStarSystem;
IsWarping = false;
}
}
#endregion Change star system
}