From 2cc7c6326e83ea2584f09f1f68634f5f7dfdfab9 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 29 Dec 2021 11:30:54 +0000 Subject: [PATCH 1/4] add vessel EnterLeave --- .../VesselSync/VesselManager.cs | 48 ++++++++++++++++++ .../WorldObjects/QSBVesselWarpController.cs | 35 +++++++++++++ QSB/Player/EnterLeaveType.cs | 4 +- QSB/Player/Messages/EnterLeaveMessage.cs | 7 +++ QSB/Player/PlayerInfo.cs | 50 +++++++------------ 5 files changed, 112 insertions(+), 32 deletions(-) create mode 100644 QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs create mode 100644 QSB/EyeOfTheUniverse/VesselSync/WorldObjects/QSBVesselWarpController.cs diff --git a/QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs b/QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs new file mode 100644 index 00000000..b110f9c8 --- /dev/null +++ b/QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs @@ -0,0 +1,48 @@ +using QSB.EyeOfTheUniverse.VesselSync.WorldObjects; +using QSB.Player; +using QSB.Utility; +using QSB.WorldSync; +using System.Collections.Generic; +using System.Linq; + +namespace QSB.EyeOfTheUniverse.VesselSync +{ + internal class VesselManager : WorldObjectManager + { + public static VesselManager Instance { get; private set; } + + private List _playersInCage; + private QSBVesselWarpController _warpController; + + public override WorldObjectType WorldObjectType => WorldObjectType.Both; + + public override void Awake() + { + base.Awake(); + Instance = this; + } + + protected override void RebuildWorldObjects(OWScene scene) + { + QSBWorldSync.Init(); + _warpController = QSBWorldSync.GetWorldObjects().First(); + } + + public void Enter(PlayerInfo player) + { + DebugLog.DebugWrite($"{player.PlayerId} enter"); + _playersInCage.Add(player); + } + + public void Exit(PlayerInfo player) + { + DebugLog.DebugWrite($"{player.PlayerId} exit"); + _playersInCage.Remove(player); + + if (_playersInCage.Count == 0 && _warpController.AttachedObject._hasPower) + { + DebugLog.DebugWrite($"NO PLAYERS LEFT"); + } + } + } +} diff --git a/QSB/EyeOfTheUniverse/VesselSync/WorldObjects/QSBVesselWarpController.cs b/QSB/EyeOfTheUniverse/VesselSync/WorldObjects/QSBVesselWarpController.cs new file mode 100644 index 00000000..aaf018cc --- /dev/null +++ b/QSB/EyeOfTheUniverse/VesselSync/WorldObjects/QSBVesselWarpController.cs @@ -0,0 +1,35 @@ +using QSB.Messaging; +using QSB.Player.Messages; +using QSB.Utility; +using QSB.WorldSync; +using UnityEngine; + +namespace QSB.EyeOfTheUniverse.VesselSync.WorldObjects +{ + internal class QSBVesselWarpController : WorldObject + { + public override void Init() + { + AttachedObject._cageTrigger.OnEntry += OnEntry; + AttachedObject._cageTrigger.OnExit += OnExit; + } + + private void OnEntry(GameObject hitObj) + { + if (hitObj.CompareTag("PlayerDetector")) + { + DebugLog.DebugWrite($"On entry"); + new EnterLeaveMessage(Player.EnterLeaveType.EnterVesselCage).Send(); + } + } + + private void OnExit(GameObject hitObj) + { + if (hitObj.CompareTag("PlayerDetector")) + { + DebugLog.DebugWrite($"On exit"); + new EnterLeaveMessage(Player.EnterLeaveType.ExitVesselCage).Send(); + } + } + } +} diff --git a/QSB/Player/EnterLeaveType.cs b/QSB/Player/EnterLeaveType.cs index bd325137..eef74267 100644 --- a/QSB/Player/EnterLeaveType.cs +++ b/QSB/Player/EnterLeaveType.cs @@ -13,6 +13,8 @@ EnterShip = 8, ExitShip = 9, EnterNomaiHeadZone = 10, - ExitNomaiHeadZone = 11 + ExitNomaiHeadZone = 11, + EnterVesselCage = 12, + ExitVesselCage = 13 } } diff --git a/QSB/Player/Messages/EnterLeaveMessage.cs b/QSB/Player/Messages/EnterLeaveMessage.cs index 890ffae9..4e7be642 100644 --- a/QSB/Player/Messages/EnterLeaveMessage.cs +++ b/QSB/Player/Messages/EnterLeaveMessage.cs @@ -1,5 +1,6 @@ using OWML.Common; using QSB.Animation.NPC.WorldObjects; +using QSB.EyeOfTheUniverse.VesselSync; using QSB.Messaging; using QSB.Player.TransformSync; using QSB.PoolSync; @@ -96,6 +97,12 @@ namespace QSB.Player.Messages case EnterLeaveType.ExitShip: ShipManager.Instance.RemovePlayerFromShip(player); break; + case EnterLeaveType.EnterVesselCage: + VesselManager.Instance.Enter(player); + break; + case EnterLeaveType.ExitVesselCage: + VesselManager.Instance.Exit(player); + break; default: DebugLog.ToConsole($"Warning - Unknown EnterLeaveType : {Value}", MessageType.Warning); break; diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index a94bbc0d..571cd1c4 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -26,6 +26,15 @@ namespace QSB.Player public string Name { get; set; } public PlayerHUDMarker HudMarker { get; set; } public PlayerTransformSync TransformSync { get; set; } + public ClientState State { get; set; } + public EyeState EyeState { get; set; } + public bool IsDead { get; set; } + public bool Visible { get; set; } = true; + public bool IsReady { get; set; } + public bool IsInMoon { get; set; } + public bool IsInShrine { get; set; } + public IQSBQuantumObject EntangledObject { get; set; } + public QSBPlayerAudioController AudioController { get; set; } // Body Objects public OWCamera Camera @@ -52,6 +61,7 @@ namespace QSB.Player private OWCamera _camera; public GameObject CameraBody { get; set; } + public GameObject Body { get @@ -76,23 +86,11 @@ namespace QSB.Player private GameObject _body; public GameObject RoastingStick { get; set; } - public bool Visible { get; set; } = true; // Tools public GameObject ProbeBody { get; set; } public QSBProbe Probe { get; set; } - public QSBFlashlight FlashLight - { - get - { - if (CameraBody == null) - { - return null; - } - - return CameraBody.GetComponentInChildren(); - } - } + public QSBFlashlight FlashLight => CameraBody?.GetComponentInChildren(); public QSBTool Signalscope => GetToolByType(ToolType.Signalscope); public QSBTool Translator => GetToolByType(ToolType.Translator); public QSBProbeLauncherTool ProbeLauncher => (QSBProbeLauncherTool)GetToolByType(ToolType.ProbeLauncher); @@ -108,6 +106,12 @@ namespace QSB.Player public QSBMarshmallow Marshmallow { get; set; } public QSBCampfire Campfire { get; set; } public IQSBOWItem HeldItem { get; set; } + public bool FlashlightActive { get; set; } + public bool SuitedUp { get; set; } + public bool ProbeLauncherEquipped { get; set; } + public bool SignalscopeEquipped { get; set; } + public bool TranslatorEquipped { get; set; } + public bool ProbeActive { get; set; } // Conversation public int CurrentCharacterDialogueTreeId { get; set; } @@ -115,27 +119,11 @@ namespace QSB.Player // Animation public AnimationSync AnimationSync => QSBPlayerManager.GetSyncObject(PlayerId); - public bool PlayingInstrument => AnimationSync.CurrentType is not AnimationType.PlayerSuited + public bool PlayingInstrument => AnimationSync.CurrentType + is not AnimationType.PlayerSuited and not AnimationType.PlayerUnsuited; public JetpackAccelerationSync JetpackAcceleration { get; set; } - // Misc - // CLEANUP : this file is very messy. especially this bit - public bool IsReady { get; set; } - public bool IsInMoon; - public bool IsInShrine; - public IQSBQuantumObject EntangledObject; - public bool IsDead { get; set; } - public ClientState State { get; set; } - public bool FlashlightActive { get; set; } - public bool SuitedUp { get; set; } - public bool ProbeLauncherEquipped { get; set; } - public bool SignalscopeEquipped { get; set; } - public bool TranslatorEquipped { get; set; } - public bool ProbeActive { get; set; } - public QSBPlayerAudioController AudioController { get; set; } - public EyeState EyeState { get; set; } - // Local only public PlayerProbeLauncher LocalProbeLauncher { From c56cd230ef06acc7385f1f9841f64fa6ad54dbdd Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 29 Dec 2021 11:38:54 +0000 Subject: [PATCH 2/4] fix nre --- QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs b/QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs index b110f9c8..a9b5ccff 100644 --- a/QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs +++ b/QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs @@ -11,7 +11,7 @@ namespace QSB.EyeOfTheUniverse.VesselSync { public static VesselManager Instance { get; private set; } - private List _playersInCage; + private List _playersInCage = new(); private QSBVesselWarpController _warpController; public override WorldObjectType WorldObjectType => WorldObjectType.Both; From 5a49df9061d490c2b53956c418967586c92b9b56 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 29 Dec 2021 12:19:46 +0000 Subject: [PATCH 3/4] improve vessel warp action --- QSB/Utility/DebugActions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/QSB/Utility/DebugActions.cs b/QSB/Utility/DebugActions.cs index ef14eb64..9ed0c9e0 100644 --- a/QSB/Utility/DebugActions.cs +++ b/QSB/Utility/DebugActions.cs @@ -17,6 +17,9 @@ namespace QSB.Utility var playerBody = Locator.GetPlayerBody(); playerBody.WarpToPositionRotation(spawnPoint.transform.position, spawnPoint.transform.rotation); playerBody.SetVelocity(spawnPoint.GetPointVelocity()); + var bridgeVolume = FindObjectOfType()._bridgeVolume; + bridgeVolume.AddObjectToVolume(Locator.GetPlayerDetector()); + bridgeVolume.AddObjectToVolume(Locator.GetPlayerCameraDetector()); } private void InsertWarpCore() @@ -24,9 +27,6 @@ namespace QSB.Utility var warpCore = GameObject.Find("Prefab_NOM_WarpCoreVessel").GetComponent(); var socket = GameObject.Find("Interactibles_VesselBridge").GetComponentInChildren(); socket.PlaceIntoSocket(warpCore); - var bridgeVolume = FindObjectOfType()._bridgeVolume; - bridgeVolume.AddObjectToVolume(Locator.GetPlayerDetector()); - bridgeVolume.AddObjectToVolume(Locator.GetPlayerCameraDetector()); } private void DamageShipElectricalSystem() => ShipManager.Instance.ShipElectricalComponent.SetDamaged(true); From eaeedd14c5b697079b5e52fc9a58b4058c939e0d Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 29 Dec 2021 12:20:35 +0000 Subject: [PATCH 4/4] remove logs, fix it --- QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs | 12 +++++++++--- .../WorldObjects/QSBVesselWarpController.cs | 2 -- QSB/Utility/DebugGUI.cs | 10 ++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs b/QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs index a9b5ccff..5c5a7588 100644 --- a/QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs +++ b/QSB/EyeOfTheUniverse/VesselSync/VesselManager.cs @@ -4,6 +4,7 @@ using QSB.Utility; using QSB.WorldSync; using System.Collections.Generic; using System.Linq; +using UnityEngine; namespace QSB.EyeOfTheUniverse.VesselSync { @@ -26,22 +27,27 @@ namespace QSB.EyeOfTheUniverse.VesselSync { QSBWorldSync.Init(); _warpController = QSBWorldSync.GetWorldObjects().First(); + _warpController.AttachedObject._cageTrigger.OnExit -= _warpController.AttachedObject.OnExitCageTrigger; } public void Enter(PlayerInfo player) { - DebugLog.DebugWrite($"{player.PlayerId} enter"); _playersInCage.Add(player); } public void Exit(PlayerInfo player) { - DebugLog.DebugWrite($"{player.PlayerId} exit"); _playersInCage.Remove(player); if (_playersInCage.Count == 0 && _warpController.AttachedObject._hasPower) { - DebugLog.DebugWrite($"NO PLAYERS LEFT"); + var obj = _warpController.AttachedObject; + obj._cageClosed = true; + obj._cageAnimator.TranslateToLocalPosition(new Vector3(0f, -8.1f, 0f), 5f); + obj._cageAnimator.RotateToLocalEulerAngles(new Vector3(0f, 180f, 0f), 5f); + obj._cageAnimator.OnTranslationComplete -= obj.OnCageAnimationComplete; + obj._cageAnimator.OnTranslationComplete += obj.OnCageAnimationComplete; + obj._cageLoopingAudio.FadeIn(1f, false, false, 1f); } } } diff --git a/QSB/EyeOfTheUniverse/VesselSync/WorldObjects/QSBVesselWarpController.cs b/QSB/EyeOfTheUniverse/VesselSync/WorldObjects/QSBVesselWarpController.cs index aaf018cc..753e5f20 100644 --- a/QSB/EyeOfTheUniverse/VesselSync/WorldObjects/QSBVesselWarpController.cs +++ b/QSB/EyeOfTheUniverse/VesselSync/WorldObjects/QSBVesselWarpController.cs @@ -18,7 +18,6 @@ namespace QSB.EyeOfTheUniverse.VesselSync.WorldObjects { if (hitObj.CompareTag("PlayerDetector")) { - DebugLog.DebugWrite($"On entry"); new EnterLeaveMessage(Player.EnterLeaveType.EnterVesselCage).Send(); } } @@ -27,7 +26,6 @@ namespace QSB.EyeOfTheUniverse.VesselSync.WorldObjects { if (hitObj.CompareTag("PlayerDetector")) { - DebugLog.DebugWrite($"On exit"); new EnterLeaveMessage(Player.EnterLeaveType.ExitVesselCage).Send(); } } diff --git a/QSB/Utility/DebugGUI.cs b/QSB/Utility/DebugGUI.cs index c7292283..92fcdfb3 100644 --- a/QSB/Utility/DebugGUI.cs +++ b/QSB/Utility/DebugGUI.cs @@ -272,6 +272,16 @@ namespace QSB.Utility foreach (var obj in QSBWorldSync.GetWorldObjects()) { + if (obj == null) + { + return; + } + + if (obj.ReturnObject() == null) + { + return; + } + if (obj.ShouldDisplayLabel()) { DrawLabel(obj.ReturnObject().transform, obj.ReturnLabel());