diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index a3adedce..37b5a2d6 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -12,7 +12,7 @@ namespace NewHorizons.Builder.General public static SpawnPoint Make(GameObject body, SpawnModule module, OWRigidbody rb) { SpawnPoint playerSpawn = null; - if(!Main.IsWarping && module.PlayerSpawnPoint != null) + if(!Main.Instance.IsWarping && module.PlayerSpawnPoint != null) { GameObject spawnGO = new GameObject("PlayerSpawnPoint"); spawnGO.transform.parent = body.transform; @@ -45,7 +45,7 @@ namespace NewHorizons.Builder.General ship.GetRequiredComponent().SetBodyToMatch(rb); - if(Main.IsWarping) + if(Main.Instance.IsWarping) { Logger.Log("Overriding player spawn to be inside ship"); GameObject playerSpawnGO = new GameObject("PlayerSpawnPoint"); @@ -60,7 +60,7 @@ namespace NewHorizons.Builder.General GameObject.FindObjectOfType().SetInitialSpawnPoint(playerSpawn); } } - if(!Main.IsWarping && module.StartWithSuit && !suitUpQueued) + if(!Main.Instance.IsWarping && module.StartWithSuit && !suitUpQueued) { suitUpQueued = true; Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => SuitUp(), 4); diff --git a/NewHorizons/Components/ChangeStarSystemVolume.cs b/NewHorizons/Components/ChangeStarSystemVolume.cs index a8cddf31..326809fc 100644 --- a/NewHorizons/Components/ChangeStarSystemVolume.cs +++ b/NewHorizons/Components/ChangeStarSystemVolume.cs @@ -16,10 +16,15 @@ namespace NewHorizons.Components _deathType = DeathType.Meditation; } + public override void VanishShip(OWRigidbody shipBody, RelativeLocationData entryLocation) + { + if(PlayerState.IsInsideShip()) Main.Instance.ChangeCurrentStarSystem(TargetSolarSystem, true); + } + public override void VanishPlayer(OWRigidbody playerBody, RelativeLocationData entryLocation) { - //Main.Instance.ChangeCurrentStarSystem(TargetSolarSystem, PlayerState.AtFlightConsole()); - Main.Instance.ChangeCurrentStarSystem(TargetSolarSystem, false); + Main.Instance.ChangeCurrentStarSystem(TargetSolarSystem, PlayerState.AtFlightConsole()); + //Main.Instance.ChangeCurrentStarSystem(TargetSolarSystem, false); } } } diff --git a/NewHorizons/Components/ShipLogStarChartMode.cs b/NewHorizons/Components/ShipLogStarChartMode.cs index c68257e5..538c8c76 100644 --- a/NewHorizons/Components/ShipLogStarChartMode.cs +++ b/NewHorizons/Components/ShipLogStarChartMode.cs @@ -94,7 +94,11 @@ namespace NewHorizons.Components } var newCard = GameObject.Instantiate(_cardTemplate, parent); - newCard.transform.Find("EntryCardRoot/NameBackground/Name").GetComponent().text = UniqueNameToString(uniqueName); + var textComponent = newCard.transform.Find("EntryCardRoot/NameBackground/Name").GetComponent(); + var name = UniqueNameToString(uniqueName); + textComponent.text = name; + if (name.Length > 17) textComponent.fontSize = 10; + newCard.SetActive(true); newCard.transform.name = uniqueName; newCard.transform.localPosition = new Vector3(position.x, position.y, 40); diff --git a/NewHorizons/Components/ShipWarpController.cs b/NewHorizons/Components/ShipWarpController.cs index 15fa3ebb..16c140b3 100644 --- a/NewHorizons/Components/ShipWarpController.cs +++ b/NewHorizons/Components/ShipWarpController.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; +using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Components { @@ -28,11 +29,18 @@ namespace NewHorizons.Components MakeBlackHole(); MakeWhiteHole(); + _isWarpingIn = false; + _oneShotSource = base.gameObject.AddComponent(); GlobalMessenger.AddListener("FinishOpenEyes", new Callback(OnFinishOpenEyes)); } + public void OnDestroy() + { + GlobalMessenger.RemoveListener("FinishOpenEyes", new Callback(OnFinishOpenEyes)); + } + 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().material.shader; @@ -81,13 +89,9 @@ namespace NewHorizons.Components whiteHoleRenderer.SetActive(true); } - public void OnDestroy() - { - GlobalMessenger.RemoveListener("FinishOpenEyes", new Callback(OnFinishOpenEyes)); - } - public void WarpIn() { + Logger.Log("Starting warp-in"); // Trying really hard to stop the player from dying while warping in _impactDeathSpeed = Locator.GetDeathManager()._impactDeathSpeed; Locator.GetDeathManager()._impactDeathSpeed = Mathf.Infinity; @@ -99,6 +103,7 @@ namespace NewHorizons.Components public void WarpOut() { + Logger.Log("Starting warp-out"); _oneShotSource.PlayOneShot(global::AudioType.VesselSingularityCreate, 1f); _blackhole.Create(); } @@ -107,37 +112,28 @@ namespace NewHorizons.Components { if(_isWarpingIn && LateInitializerManager.isDoneInitializing) { - _oneShotSource.PlayOneShot(global::AudioType.VesselSingularityCollapse, 1f); - Locator.GetDeathManager()._invincible = true; - if (Main.Instance.CurrentStarSystem.Equals("SolarSystem")) Teleportation.teleportPlayerToShip(); - _whitehole.Create(); + Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => StartWarpInEffect(), 1); _isWarpingIn = false; - _waitingToBeSeated = true; - if (!Locator.GetPlayerController()._isWearingSuit) - { - SpawnPointBuilder.SuitUp(); - } - } - // Idk whats making this work but now it works and idc - if(_waitingToBeSeated - && PlayerState.IsInsideShip() - && PlayerState.IsWearingSuit() - && base.GetComponentInChildren()?._playerAttachPoint?.GetAttachedOWRigidbody() != null - && !Locator.GetPlayerController()._isMovementLocked - && !Locator.GetPlayerController()._isTurningLocked - && _eyesOpen) - { - Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => FinishWarp(), 4); - _waitingToBeSeated = false; } + if (_waitingToBeSeated) { if (Player.getResources()._currentHealth < 100f) { + Logger.Log("Player died in a warp drive accident, reviving them"); // Means the player was killed meaning they weren't teleported in Player.getResources()._currentHealth = 100f; - Teleportation.teleportPlayerToShip(); + if(!PlayerState.AtFlightConsole()) Teleportation.teleportPlayerToShip(); } + + Logger.Log($"{PlayerState.IsInsideShip()}, {PlayerState.IsWearingSuit()}, {base.GetComponentInChildren()?._playerAttachPoint?.GetAttachedOWRigidbody() != null}, {!Locator.GetPlayerController()._isMovementLocked}, {!Locator.GetPlayerController()._isTurningLocked }, {_eyesOpen}"); + } + + // Idk whats making this work but now it works and idc + if (_waitingToBeSeated && PlayerState.IsInsideShip() && _eyesOpen) + { + Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => FinishWarpIn(), 1); + _waitingToBeSeated = false; } } @@ -146,8 +142,23 @@ namespace NewHorizons.Components _eyesOpen = true; } - public void FinishWarp() + private void StartWarpInEffect() { + Logger.Log("Starting warp-in effect"); + _oneShotSource.PlayOneShot(global::AudioType.VesselSingularityCollapse, 1f); + Locator.GetDeathManager()._invincible = true; + if (Main.Instance.CurrentStarSystem.Equals("SolarSystem")) Teleportation.teleportPlayerToShip(); + _whitehole.Create(); + _waitingToBeSeated = true; + if (!Locator.GetPlayerController()._isWearingSuit) + { + SpawnPointBuilder.SuitUp(); + } + } + + public void FinishWarpIn() + { + Logger.Log("Finishing warp"); Locator.GetShipBody().GetComponentInChildren().OnPressInteract(); _waitingToBeSeated = false; Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => _whitehole.Collapse(), 30); diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 88d7318d..4583537d 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -39,8 +39,7 @@ namespace NewHorizons public string CurrentStarSystem { get { return Instance._currentStarSystem; } } private bool _isChangingStarSystem = false; - private bool _isWarping = false; - public static bool IsWarping { get { return Instance._isWarping; } } + public bool IsWarping { get; private set; } = false; private ShipWarpController _shipWarpController; @@ -199,8 +198,9 @@ namespace NewHorizons if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; _shipWarpController = GameObject.Find("Ship_Body").AddComponent(); - if (_isWarping) Instance.ModHelper.Events.Unity.FireInNUpdates(() => _shipWarpController.WarpIn(), 1); - _isWarping = false; + Logger.Log($"Is the player warping in? {IsWarping}"); + //if (IsWarping) Instance.ModHelper.Events.Unity.FireInNUpdates(() => _shipWarpController.WarpIn(), 1); + IsWarping = false; } #region TitleScreen @@ -548,11 +548,13 @@ namespace NewHorizons #region Change star system public void ChangeCurrentStarSystem(string newStarSystem, bool warp = false) { + if (_isChangingStarSystem) return; + Logger.Log($"Warping to {newStarSystem}"); if(warp) _shipWarpController.WarpOut(); _currentStarSystem = newStarSystem; _isChangingStarSystem = true; - _isWarping = warp; + IsWarping = warp; // We kill them so they don't move as much Locator.GetDeathManager().KillPlayer(DeathType.Meditation);