From e6051428cde870f024217348a834e49c28085567 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 1 May 2022 22:00:25 +0100 Subject: [PATCH] fix ghosts grabbing --- .../Ghosts/Actions/QSBGrabAction.cs | 6 +- QSB/EchoesOfTheEye/Ghosts/GhostManager.cs | 2 + .../Messages/GrabRemotePlayerMessage.cs | 23 +++++++ .../Ghosts/WorldObjects/QSBGhostController.cs | 3 + .../WorldObjects/QSBGhostGrabController.cs | 67 +++++++++++++++++++ 5 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 QSB/EchoesOfTheEye/Ghosts/Messages/GrabRemotePlayerMessage.cs create mode 100644 QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostGrabController.cs diff --git a/QSB/EchoesOfTheEye/Ghosts/Actions/QSBGrabAction.cs b/QSB/EchoesOfTheEye/Ghosts/Actions/QSBGrabAction.cs index 33a6fae8..4a4e81df 100644 --- a/QSB/EchoesOfTheEye/Ghosts/Actions/QSBGrabAction.cs +++ b/QSB/EchoesOfTheEye/Ghosts/Actions/QSBGrabAction.cs @@ -75,19 +75,19 @@ internal class QSBGrabAction : QSBGhostAction _controller.FaceLocalPosition(_data.interestedPlayer.playerLocation.localPosition, TurnSpeed.FASTEST); if (_sensors.CanGrabPlayer(_data.interestedPlayer)) { - GrabPlayer(); + GrabPlayer(_data.interestedPlayer); } return !_grabAnimComplete; } - private void GrabPlayer() + private void GrabPlayer(GhostPlayer player) { _playerIsGrabbed = true; _controller.StopMovingInstantly(); _controller.StopFacing(); _controller.SetLanternConcealed(true, false); - _controller.AttachedObject.GetGrabController().GrabPlayer(1f); + _controller.GetGrabController().GrabPlayer(1f, player); } private void OnGrabComplete() diff --git a/QSB/EchoesOfTheEye/Ghosts/GhostManager.cs b/QSB/EchoesOfTheEye/Ghosts/GhostManager.cs index 1d2ded9a..19afa1cd 100644 --- a/QSB/EchoesOfTheEye/Ghosts/GhostManager.cs +++ b/QSB/EchoesOfTheEye/Ghosts/GhostManager.cs @@ -27,7 +27,9 @@ internal class GhostManager : WorldObjectManager QSBWorldSync.Init(QSBWorldSync.GetUnityObjects()); QSBWorldSync.Init(); QSBWorldSync.Init(); + // to avoid disabled ghosts (TheCollector) QSBWorldSync.Init(QSBWorldSync.GetUnityObjects().Where(x => x.gameObject.activeSelf).SortDeterministic()); + QSBWorldSync.Init(); _hotelDirector = QSBWorldSync.GetUnityObjects().First(); _partyPathDirector = QSBWorldSync.GetUnityObjects().First(); diff --git a/QSB/EchoesOfTheEye/Ghosts/Messages/GrabRemotePlayerMessage.cs b/QSB/EchoesOfTheEye/Ghosts/Messages/GrabRemotePlayerMessage.cs new file mode 100644 index 00000000..ce698d4c --- /dev/null +++ b/QSB/EchoesOfTheEye/Ghosts/Messages/GrabRemotePlayerMessage.cs @@ -0,0 +1,23 @@ +using QSB.EchoesOfTheEye.Ghosts.WorldObjects; +using QSB.Messaging; +using QSB.Player; +using QSB.WorldSync; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace QSB.EchoesOfTheEye.Ghosts.Messages; + +internal class GrabRemotePlayerMessage : QSBWorldObjectMessage +{ + public GrabRemotePlayerMessage(float speed, uint playerId) : base((speed, playerId)) { } + + public override void OnReceiveRemote() + { + var allGhosts = QSBWorldSync.GetWorldObjects(); + var owningGhost = allGhosts.First(x => x.AttachedObject._controller == WorldObject.AttachedObject._effects._controller); + WorldObject.GrabPlayer(Data.speed, owningGhost._data.players[QSBPlayerManager.GetPlayer(Data.playerId)], true); + } +} diff --git a/QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostController.cs b/QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostController.cs index 7b149490..e1819c10 100644 --- a/QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostController.cs +++ b/QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostController.cs @@ -39,6 +39,9 @@ public class QSBGhostController : WorldObject, IGhostObject AttachedObject._playerCollider = Locator.GetPlayerBody().GetComponent(); } + public QSBGhostGrabController GetGrabController() + => AttachedObject.GetGrabController().GetWorldObject(); + public void SetLanternConcealed(bool concealed, bool playAudio = true) { if (playAudio && AttachedObject._lantern.IsConcealed() != concealed) diff --git a/QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostGrabController.cs b/QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostGrabController.cs new file mode 100644 index 00000000..04771060 --- /dev/null +++ b/QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostGrabController.cs @@ -0,0 +1,67 @@ +using QSB.EchoesOfTheEye.Ghosts.Messages; +using QSB.Messaging; +using QSB.Player; +using QSB.Utility; +using QSB.WorldSync; +using UnityEngine; + +namespace QSB.EchoesOfTheEye.Ghosts.WorldObjects; + +public class QSBGhostGrabController : WorldObject +{ + public override void SendInitialState(uint to) + { + + } + + public void GrabPlayer(float speed, GhostPlayer player, bool remote = false) + { + if (!remote) + { + this.SendMessage(new GrabRemotePlayerMessage(speed, player.player.PlayerId)); + } + + var isLocalPlayer = player.player.PlayerId == QSBPlayerManager.LocalPlayerId; + + if (isLocalPlayer) + { + AttachedObject.enabled = true; + AttachedObject._snappingNeck = !player.player.AssignedSimulationLantern.AttachedObject.GetLanternController().IsHeldByPlayer(); + AttachedObject._holdingInPlace = true; + AttachedObject._grabMoveComplete = false; + AttachedObject._extinguishStarted = false; + AttachedObject._attachPoint.transform.parent = AttachedObject._origParent; + AttachedObject._attachPoint.transform.position = Locator.GetPlayerTransform().position; + AttachedObject._attachPoint.transform.rotation = Locator.GetPlayerTransform().rotation; + AttachedObject._startLocalPos = AttachedObject._attachPoint.transform.localPosition; + AttachedObject._startLocalRot = AttachedObject._attachPoint.transform.localRotation; + AttachedObject._playerAttached = true; + AttachedObject._attachPoint.AttachPlayer(); + GlobalMessenger.FireEvent("PlayerGrabbedByGhost"); + OWInput.ChangeInputMode(InputMode.None); + ReticleController.Hide(); + Locator.GetDreamWorldController().SetActiveGhostGrabController(AttachedObject); + AttachedObject._grabStartTime = Time.time; + AttachedObject._grabMoveDuration = Mathf.Min(Vector3.Distance(AttachedObject._startLocalPos, AttachedObject._holdPoint.localPosition) / speed, 2f); + RumbleManager.PlayGhostGrab(); + Achievement_Ghost.GotCaughtByGhost(); + } + + var effects = AttachedObject._effects.GetWorldObject(); + + if (QSBCore.IsHost) + { + if (AttachedObject._snappingNeck) + { + effects.PlaySnapNeckAnimation(); + } + else + { + // todo : make this track grab counts, so we can use the fast animation + effects.PlayBlowOutLanternAnimation(); + } + } + + effects.AttachedObject.PlayGrabAudio(AudioType.Ghost_Grab_Contact); + } +}