From 29f6fb8908e1aab571bc968ac4bacdf45142c9bd Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 15 Jun 2022 11:05:13 -0400 Subject: [PATCH] Separate Vessel And Ship Warp --- .../NH/WarpDriveAchievement.cs | 2 +- .../Builder/General/SpawnPointBuilder.cs | 7 ++-- NewHorizons/Main.cs | 40 ++++++++++--------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/NewHorizons/AchievementsPlus/NH/WarpDriveAchievement.cs b/NewHorizons/AchievementsPlus/NH/WarpDriveAchievement.cs index e697891b..ee0747b7 100644 --- a/NewHorizons/AchievementsPlus/NH/WarpDriveAchievement.cs +++ b/NewHorizons/AchievementsPlus/NH/WarpDriveAchievement.cs @@ -18,7 +18,7 @@ namespace NewHorizons.AchievementsPlus.NH private static void OnChangeStarSystem(string system) { - if (Main.Instance.IsWarping) AchievementHandler.Earn(UNIQUE_ID); + if (Main.Instance.IsWarpingFromShip) AchievementHandler.Earn(UNIQUE_ID); } } } diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index 8c26fd9c..907f131d 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -10,7 +10,7 @@ namespace NewHorizons.Builder.General public static SpawnPoint Make(GameObject planetGO, SpawnModule module, OWRigidbody owRigidBody) { SpawnPoint playerSpawn = null; - if (!Main.Instance.IsWarping && module.playerSpawnPoint != null) + if (!Main.Instance.IsWarpingFromVessel && !Main.Instance.IsWarpingFromShip && module.playerSpawnPoint != null) { GameObject spawnGO = new GameObject("PlayerSpawnPoint"); spawnGO.transform.parent = planetGO.transform; @@ -60,7 +60,7 @@ namespace NewHorizons.Builder.General ship.GetRequiredComponent().SetBodyToMatch(owRigidBody); - if (Main.Instance.IsWarping) + if (Main.Instance.IsWarpingFromShip) { Logger.Log("Overriding player spawn to be inside ship"); GameObject playerSpawnGO = new GameObject("PlayerSpawnPoint"); @@ -74,7 +74,8 @@ namespace NewHorizons.Builder.General playerSpawnGO.transform.localRotation = Quaternion.Euler(0, 0, 0); } } - if (!Main.Instance.IsWarping && module.startWithSuit && !suitUpQueued) + + if (!Main.Instance.IsWarpingFromShip && module.startWithSuit && !suitUpQueued) { suitUpQueued = true; Main.Instance.ModHelper.Events.Unity.RunWhen(() => Main.IsSystemReady, () => SuitUp()); diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 2112fa57..35bf01b9 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -1,10 +1,11 @@ using HarmonyLib; using NewHorizons.Builder.Props; using NewHorizons.Components; -using NewHorizons.External.Configs; using NewHorizons.External; +using NewHorizons.External.Configs; using NewHorizons.Handlers; using NewHorizons.Utility; +using NewHorizons.Utility.DebugUtilities; using OWML.Common; using OWML.ModHelper; using System; @@ -16,8 +17,6 @@ using UnityEngine; using UnityEngine.Events; using UnityEngine.SceneManagement; using Logger = NewHorizons.Utility.Logger; -using NewHorizons.Utility.DebugUtilities; -using Newtonsoft.Json; namespace NewHorizons { @@ -43,7 +42,8 @@ namespace NewHorizons public static float FurthestOrbit { get; set; } = 50000f; public string CurrentStarSystem { get { return Instance._currentStarSystem; } } - public bool IsWarping { get; private set; } = false; + public bool IsWarpingFromShip { get; private set; } = false; + public bool IsWarpingFromVessel { get; private set; } = false; public bool WearingSuit { get; private set; } = false; public bool IsChangingStarSystem { get; private set; } = false; @@ -218,7 +218,7 @@ namespace NewHorizons TitleSceneHandler.InitSubtitles(); } - if (scene.name == "EyeOfTheUniverse" && IsWarping) + if (scene.name == "EyeOfTheUniverse" && IsWarpingFromShip) { if (_ship != null) SceneManager.MoveGameObjectToScene(_ship, SceneManager.GetActiveScene()); _ship.transform.position = new Vector3(50, 0, 0); @@ -255,10 +255,12 @@ namespace NewHorizons _shipWarpController.Init(); if (HasWarpDrive == true) EnableWarpDrive(); - var shouldWarpIn = IsWarping && _shipWarpController != null; - Instance.ModHelper.Events.Unity.RunWhen(() => IsSystemReady, () => OnSystemReady(shouldWarpIn)); + var shouldWarpInFromShip = IsWarpingFromShip && _shipWarpController != null; + var shouldWarpInFromVessel = IsWarpingFromVessel; + Instance.ModHelper.Events.Unity.RunWhen(() => IsSystemReady, () => OnSystemReady(shouldWarpInFromShip, shouldWarpInFromVessel)); - IsWarping = false; + IsWarpingFromShip = false; + IsWarpingFromVessel = false; var map = GameObject.FindObjectOfType(); if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; @@ -273,7 +275,7 @@ namespace NewHorizons if (SystemDict.Keys.Contains(_defaultSystemOverride)) { _currentStarSystem = _defaultSystemOverride; - IsWarping = true; // always do this else sometimes the spawn gets messed up + IsWarpingFromShip = true; // always do this else sometimes the spawn gets messed up } else { @@ -283,13 +285,14 @@ namespace NewHorizons } // Had a bunch of separate unity things firing stuff when the system is ready so I moved it all to here - private void OnSystemReady(bool shouldWarpIn) + private void OnSystemReady(bool shouldWarpInFromShip, bool shouldWarpInFromVessel) { Locator.GetPlayerBody().gameObject.AddComponent(); Locator.GetPlayerBody().gameObject.AddComponent(); Locator.GetPlayerBody().gameObject.AddComponent(); - if (shouldWarpIn) _shipWarpController.WarpIn(WearingSuit); + if (shouldWarpInFromShip) _shipWarpController.WarpIn(WearingSuit); + else if (shouldWarpInFromVessel) { } else FindObjectOfType().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint); } @@ -393,10 +396,10 @@ namespace NewHorizons { var config = mod.ModHelper.Storage.Load(relativeDirectory); // var config = JsonConvert.DeserializeObject(File.ReadAllText($"{mod.ModHelper.Manifest.ModFolderPath}/{relativeDirectory}")); - + config.MigrateAndValidate(); - Logger.Log($"Loaded {config.name}"); + Logger.Log($"Loaded {config.name}"); if (!SystemDict.ContainsKey(config.starSystem)) { @@ -431,11 +434,12 @@ namespace NewHorizons #endregion Load #region Change star system - public void ChangeCurrentStarSystem(string newStarSystem, bool warp = false) + public void ChangeCurrentStarSystem(string newStarSystem, bool warp = false, bool vessel = false) { if (IsChangingStarSystem) return; - IsWarping = warp; + IsWarpingFromShip = warp; + IsWarpingFromVessel = vessel; OnChangeStarSystem?.Invoke(newStarSystem); Logger.Log($"Warping to {newStarSystem}"); @@ -463,7 +467,7 @@ namespace NewHorizons _currentStarSystem = newStarSystem; - LoadManager.LoadSceneAsync(sceneToLoad, true, LoadManager.FadeType.ToBlack, 0.1f, true); + LoadManager.LoadSceneAsync(sceneToLoad, !vessel, LoadManager.FadeType.ToBlack, 0.1f, true); } void OnDeath(DeathType _) @@ -475,14 +479,14 @@ namespace NewHorizons if (SystemDict.Keys.Contains(_defaultSystemOverride)) { _currentStarSystem = _defaultSystemOverride; - IsWarping = true; // always do this else sometimes the spawn gets messed up + IsWarpingFromShip = true; // always do this else sometimes the spawn gets messed up } else { _currentStarSystem = _defaultStarSystem; } - IsWarping = false; + IsWarpingFromShip = false; } } #endregion Change star system