Separate Vessel And Ship Warp

This commit is contained in:
Noah Pilarski 2022-06-15 11:05:13 -04:00
parent de05bfa2e0
commit 29f6fb8908
3 changed files with 27 additions and 22 deletions

View File

@ -18,7 +18,7 @@ namespace NewHorizons.AchievementsPlus.NH
private static void OnChangeStarSystem(string system) private static void OnChangeStarSystem(string system)
{ {
if (Main.Instance.IsWarping) AchievementHandler.Earn(UNIQUE_ID); if (Main.Instance.IsWarpingFromShip) AchievementHandler.Earn(UNIQUE_ID);
} }
} }
} }

View File

@ -10,7 +10,7 @@ namespace NewHorizons.Builder.General
public static SpawnPoint Make(GameObject planetGO, SpawnModule module, OWRigidbody owRigidBody) public static SpawnPoint Make(GameObject planetGO, SpawnModule module, OWRigidbody owRigidBody)
{ {
SpawnPoint playerSpawn = null; 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"); GameObject spawnGO = new GameObject("PlayerSpawnPoint");
spawnGO.transform.parent = planetGO.transform; spawnGO.transform.parent = planetGO.transform;
@ -60,7 +60,7 @@ namespace NewHorizons.Builder.General
ship.GetRequiredComponent<MatchInitialMotion>().SetBodyToMatch(owRigidBody); ship.GetRequiredComponent<MatchInitialMotion>().SetBodyToMatch(owRigidBody);
if (Main.Instance.IsWarping) if (Main.Instance.IsWarpingFromShip)
{ {
Logger.Log("Overriding player spawn to be inside ship"); Logger.Log("Overriding player spawn to be inside ship");
GameObject playerSpawnGO = new GameObject("PlayerSpawnPoint"); GameObject playerSpawnGO = new GameObject("PlayerSpawnPoint");
@ -74,7 +74,8 @@ namespace NewHorizons.Builder.General
playerSpawnGO.transform.localRotation = Quaternion.Euler(0, 0, 0); playerSpawnGO.transform.localRotation = Quaternion.Euler(0, 0, 0);
} }
} }
if (!Main.Instance.IsWarping && module.startWithSuit && !suitUpQueued)
if (!Main.Instance.IsWarpingFromShip && module.startWithSuit && !suitUpQueued)
{ {
suitUpQueued = true; suitUpQueued = true;
Main.Instance.ModHelper.Events.Unity.RunWhen(() => Main.IsSystemReady, () => SuitUp()); Main.Instance.ModHelper.Events.Unity.RunWhen(() => Main.IsSystemReady, () => SuitUp());

View File

@ -1,10 +1,11 @@
using HarmonyLib; using HarmonyLib;
using NewHorizons.Builder.Props; using NewHorizons.Builder.Props;
using NewHorizons.Components; using NewHorizons.Components;
using NewHorizons.External.Configs;
using NewHorizons.External; using NewHorizons.External;
using NewHorizons.External.Configs;
using NewHorizons.Handlers; using NewHorizons.Handlers;
using NewHorizons.Utility; using NewHorizons.Utility;
using NewHorizons.Utility.DebugUtilities;
using OWML.Common; using OWML.Common;
using OWML.ModHelper; using OWML.ModHelper;
using System; using System;
@ -16,8 +17,6 @@ using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
using NewHorizons.Utility.DebugUtilities;
using Newtonsoft.Json;
namespace NewHorizons namespace NewHorizons
{ {
@ -43,7 +42,8 @@ namespace NewHorizons
public static float FurthestOrbit { get; set; } = 50000f; public static float FurthestOrbit { get; set; } = 50000f;
public string CurrentStarSystem { get { return Instance._currentStarSystem; } } 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 WearingSuit { get; private set; } = false;
public bool IsChangingStarSystem { get; private set; } = false; public bool IsChangingStarSystem { get; private set; } = false;
@ -218,7 +218,7 @@ namespace NewHorizons
TitleSceneHandler.InitSubtitles(); TitleSceneHandler.InitSubtitles();
} }
if (scene.name == "EyeOfTheUniverse" && IsWarping) if (scene.name == "EyeOfTheUniverse" && IsWarpingFromShip)
{ {
if (_ship != null) SceneManager.MoveGameObjectToScene(_ship, SceneManager.GetActiveScene()); if (_ship != null) SceneManager.MoveGameObjectToScene(_ship, SceneManager.GetActiveScene());
_ship.transform.position = new Vector3(50, 0, 0); _ship.transform.position = new Vector3(50, 0, 0);
@ -255,10 +255,12 @@ namespace NewHorizons
_shipWarpController.Init(); _shipWarpController.Init();
if (HasWarpDrive == true) EnableWarpDrive(); if (HasWarpDrive == true) EnableWarpDrive();
var shouldWarpIn = IsWarping && _shipWarpController != null; var shouldWarpInFromShip = IsWarpingFromShip && _shipWarpController != null;
Instance.ModHelper.Events.Unity.RunWhen(() => IsSystemReady, () => OnSystemReady(shouldWarpIn)); var shouldWarpInFromVessel = IsWarpingFromVessel;
Instance.ModHelper.Events.Unity.RunWhen(() => IsSystemReady, () => OnSystemReady(shouldWarpInFromShip, shouldWarpInFromVessel));
IsWarping = false; IsWarpingFromShip = false;
IsWarpingFromVessel = false;
var map = GameObject.FindObjectOfType<MapController>(); var map = GameObject.FindObjectOfType<MapController>();
if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f;
@ -273,7 +275,7 @@ namespace NewHorizons
if (SystemDict.Keys.Contains(_defaultSystemOverride)) if (SystemDict.Keys.Contains(_defaultSystemOverride))
{ {
_currentStarSystem = _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 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 // 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<DebugRaycaster>(); Locator.GetPlayerBody().gameObject.AddComponent<DebugRaycaster>();
Locator.GetPlayerBody().gameObject.AddComponent<DebugPropPlacer>(); Locator.GetPlayerBody().gameObject.AddComponent<DebugPropPlacer>();
Locator.GetPlayerBody().gameObject.AddComponent<DebugMenu>(); Locator.GetPlayerBody().gameObject.AddComponent<DebugMenu>();
if (shouldWarpIn) _shipWarpController.WarpIn(WearingSuit); if (shouldWarpInFromShip) _shipWarpController.WarpIn(WearingSuit);
else if (shouldWarpInFromVessel) { }
else FindObjectOfType<PlayerSpawner>().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint); else FindObjectOfType<PlayerSpawner>().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint);
} }
@ -431,11 +434,12 @@ namespace NewHorizons
#endregion Load #endregion Load
#region Change star system #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; if (IsChangingStarSystem) return;
IsWarping = warp; IsWarpingFromShip = warp;
IsWarpingFromVessel = vessel;
OnChangeStarSystem?.Invoke(newStarSystem); OnChangeStarSystem?.Invoke(newStarSystem);
Logger.Log($"Warping to {newStarSystem}"); Logger.Log($"Warping to {newStarSystem}");
@ -463,7 +467,7 @@ namespace NewHorizons
_currentStarSystem = newStarSystem; _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 _) void OnDeath(DeathType _)
@ -475,14 +479,14 @@ namespace NewHorizons
if (SystemDict.Keys.Contains(_defaultSystemOverride)) if (SystemDict.Keys.Contains(_defaultSystemOverride))
{ {
_currentStarSystem = _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 else
{ {
_currentStarSystem = _defaultStarSystem; _currentStarSystem = _defaultStarSystem;
} }
IsWarping = false; IsWarpingFromShip = false;
} }
} }
#endregion Change star system #endregion Change star system