fix ghosts grabbing

This commit is contained in:
Mister_Nebula 2022-05-01 22:00:25 +01:00
parent 73352566e4
commit e6051428cd
5 changed files with 98 additions and 3 deletions

View File

@ -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()

View File

@ -27,7 +27,9 @@ internal class GhostManager : WorldObjectManager
QSBWorldSync.Init<QSBPrisonerEffects, GhostEffects>(QSBWorldSync.GetUnityObjects<PrisonerEffects>());
QSBWorldSync.Init<QSBGhostSensors, GhostSensors>();
QSBWorldSync.Init<QSBGhostNodeMap, GhostNodeMap>();
// to avoid disabled ghosts (TheCollector)
QSBWorldSync.Init<QSBGhostBrain, GhostBrain>(QSBWorldSync.GetUnityObjects<GhostBrain>().Where(x => x.gameObject.activeSelf).SortDeterministic());
QSBWorldSync.Init<QSBGhostGrabController, GhostGrabController>();
_hotelDirector = QSBWorldSync.GetUnityObjects<GhostHotelDirector>().First();
_partyPathDirector = QSBWorldSync.GetUnityObjects<GhostPartyPathDirector>().First();

View File

@ -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<QSBGhostGrabController, (float speed, uint playerId)>
{
public GrabRemotePlayerMessage(float speed, uint playerId) : base((speed, playerId)) { }
public override void OnReceiveRemote()
{
var allGhosts = QSBWorldSync.GetWorldObjects<QSBGhostBrain>();
var owningGhost = allGhosts.First(x => x.AttachedObject._controller == WorldObject.AttachedObject._effects._controller);
WorldObject.GrabPlayer(Data.speed, owningGhost._data.players[QSBPlayerManager.GetPlayer(Data.playerId)], true);
}
}

View File

@ -39,6 +39,9 @@ public class QSBGhostController : WorldObject<GhostController>, IGhostObject
AttachedObject._playerCollider = Locator.GetPlayerBody().GetComponent<CapsuleCollider>();
}
public QSBGhostGrabController GetGrabController()
=> AttachedObject.GetGrabController().GetWorldObject<QSBGhostGrabController>();
public void SetLanternConcealed(bool concealed, bool playAudio = true)
{
if (playAudio && AttachedObject._lantern.IsConcealed() != concealed)

View File

@ -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<GhostGrabController>
{
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<QSBGhostEffects>();
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);
}
}