diff --git a/QSB/DeathSync/RespawnManager.cs b/QSB/DeathSync/RespawnManager.cs index 7b104e2e..6685c945 100644 --- a/QSB/DeathSync/RespawnManager.cs +++ b/QSB/DeathSync/RespawnManager.cs @@ -6,6 +6,7 @@ using QSB.Utility; using System.Collections.Generic; using System.Linq; using UnityEngine; +using UnityEngine.Networking; namespace QSB.DeathSync { @@ -17,11 +18,29 @@ namespace QSB.DeathSync private List _playersPendingRespawn = new List(); private NotificationData _previousNotification; + private GameObject _owRecoveryPoint; + private GameObject _qsbRecoveryPoint; private void Start() { Instance = this; QSBSceneManager.OnSceneLoaded += OnSceneLoaded; + QSBNetworkManager.Instance.OnClientConnected += OnConnected; + QSBNetworkManager.Instance.OnClientDisconnected += OnDisconnected; + } + + private void OnConnected() + { + if (QSBSceneManager.IsInUniverse) + { + OnSceneLoaded(OWScene.None, QSBSceneManager.CurrentScene, true); + } + } + + private void OnDisconnected(NetworkError error) + { + _owRecoveryPoint?.SetActive(true); + _qsbRecoveryPoint?.SetActive(false); } private void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool inUniverse) @@ -29,6 +48,48 @@ namespace QSB.DeathSync QSBPlayerManager.ShowAllPlayers(); QSBPlayerManager.PlayerList.ForEach(x => x.IsDead = false); _playersPendingRespawn.Clear(); + + if (newScene != OWScene.SolarSystem) + { + return; + } + + if (_owRecoveryPoint == null) + { + _owRecoveryPoint = GameObject.Find("Systems_Supplies/PlayerRecoveryPoint"); + } + + if (_owRecoveryPoint == null) + { + DebugLog.ToConsole($"Error - Couldn't find the ship's PlayerRecoveryPoint!", OWML.Common.MessageType.Error); + return; + } + + _owRecoveryPoint.SetActive(false); + + var Systems_Supplies = _owRecoveryPoint.gameObject.transform.parent; + + if (_qsbRecoveryPoint == null) + { + _qsbRecoveryPoint = new GameObject("QSBPlayerRecoveryPoint"); + _qsbRecoveryPoint.SetActive(false); + _qsbRecoveryPoint.transform.parent = Systems_Supplies; + _qsbRecoveryPoint.transform.localPosition = new Vector3(2.46f, 1.957f, 1.156f); + _qsbRecoveryPoint.transform.localRotation = Quaternion.Euler(0, 6.460001f, 0f); + _qsbRecoveryPoint.layer = 21; + + var boxCollider = _qsbRecoveryPoint.AddComponent(); + boxCollider.isTrigger = true; + boxCollider.size = new Vector3(1.3f, 1.01f, 0.47f); + + var multiInteract = _qsbRecoveryPoint.AddComponent(); + multiInteract._usableInShip = true; + multiInteract._interactRange = 1.5f; + + _qsbRecoveryPoint.AddComponent(); + } + + _qsbRecoveryPoint.SetActive(true); } public void TriggerRespawnMap() diff --git a/QSB/DeathSync/ShipRecoveryPoint.cs b/QSB/DeathSync/ShipRecoveryPoint.cs new file mode 100644 index 00000000..0b662637 --- /dev/null +++ b/QSB/DeathSync/ShipRecoveryPoint.cs @@ -0,0 +1,69 @@ +using QSB.Utility; +using UnityEngine; + +namespace QSB.DeathSync +{ + internal class ShipRecoveryPoint : MonoBehaviour + { + private MultipleInteractionVolume _interactVolume; + private PlayerResources _playerResources; + private VisorEffectController _playerVisor; + private PlayerAudioController _playerAudioController; + private bool _recovering; + private int _refillIndex; + private int _respawnIndex; + + private void Awake() + { + DebugLog.DebugWrite($"AWAKE"); + _interactVolume = this.GetRequiredComponent(); + //_interactVolume.OnPressInteract += OnPressInteract; + _interactVolume.OnGainFocus += OnGainFocus; + + _refillIndex = _interactVolume.AddInteraction(InputLibrary.interact, InputMode.Character, UITextType.None, true, true); + _respawnIndex = _interactVolume.AddInteraction(InputLibrary.interactSecondary, InputMode.Character, UITextType.YouEscapeOnRingWorld, false, true); + } + + private void OnGainFocus() + { + DebugLog.DebugWrite($"OnGainFocus"); + + if (_playerResources == null) + { + _playerResources = Locator.GetPlayerTransform().GetComponent(); + } + + _interactVolume.EnableSingleInteraction(RespawnManager.Instance.RespawnNeeded, _respawnIndex); + + var needsHealing = _playerResources.GetHealthFraction() != 1f; + var needsRefueling = _playerResources.GetFuelFraction() != 1f; + + UITextType uitextType; + if (needsHealing && needsRefueling) + { + uitextType = UITextType.RefillPrompt_0; + _interactVolume.SetKeyCommandVisible(true, _refillIndex); + } + else if (needsHealing) + { + uitextType = UITextType.RefillPrompt_2; + _interactVolume.SetKeyCommandVisible(true, _refillIndex); + } + else if (needsRefueling) + { + uitextType = UITextType.RefillPrompt_4; + _interactVolume.SetKeyCommandVisible(true, _refillIndex); + } + else + { + uitextType = UITextType.RefillPrompt_7; + _interactVolume.SetKeyCommandVisible(false, _refillIndex); + } + + if (uitextType != UITextType.None) + { + _interactVolume.ChangePrompt(uitextType, _refillIndex); + } + } + } +} diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 614cfac7..570fcd8a 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -95,6 +95,7 @@ +