mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-03-11 10:14:17 +00:00
use custom GhostController
This commit is contained in:
parent
509ab36567
commit
d19171a690
@ -120,7 +120,7 @@ public class QSBGuardAction : QSBGhostAction
|
||||
_targetSearchNode = GetHighestPriorityNodeToSearch();
|
||||
if (_targetSearchNode == null)
|
||||
{
|
||||
Debug.LogError("Failed to find any nodes to search! Did we exhaust our existing options?", _controller);
|
||||
Debug.LogError("Failed to find any nodes to search! Did we exhaust our existing options?", _controller.AttachedObject);
|
||||
Debug.Break();
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class QSBHuntAction : QSBGhostAction
|
||||
_huntStartTime = 0f;
|
||||
_huntFailed = false;
|
||||
_huntFailTime = 0f;
|
||||
_controller.OnNodeMapChanged += new OWEvent.OWCallback(OnNodeMapChanged);
|
||||
_controller.AttachedObject.OnNodeMapChanged += new OWEvent.OWCallback(OnNodeMapChanged);
|
||||
}
|
||||
|
||||
private void OnNodeMapChanged()
|
||||
|
52
QSB/EchoesOfTheEye/Ghosts/Patches/GhostControllerPatches.cs
Normal file
52
QSB/EchoesOfTheEye/Ghosts/Patches/GhostControllerPatches.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using GhostEnums;
|
||||
using HarmonyLib;
|
||||
using QSB.EchoesOfTheEye.Ghosts.WorldObjects;
|
||||
using QSB.Patches;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.Ghosts.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(GhostController))]
|
||||
internal class GhostControllerPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(GhostController.Initialize))]
|
||||
public static bool Initialize(GhostController __instance)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - {MethodBase.GetCurrentMethod().Name} not supported!", OWML.Common.MessageType.Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(GhostController.SetLanternConcealed))]
|
||||
public static bool SetLanternConcealed(GhostController __instance, bool concealed, bool playAudio)
|
||||
{
|
||||
__instance.GetWorldObject<QSBGhostController>().SetLanternConcealed(concealed, playAudio);
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(GhostController.ChangeLanternFocus))]
|
||||
public static bool ChangeLanternFocus(GhostController __instance, float focus, float focusRate)
|
||||
{
|
||||
__instance.GetWorldObject<QSBGhostController>().ChangeLanternFocus(focus, focusRate);
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(GhostController.FacePlayer))]
|
||||
public static bool FacePlayer(GhostController __instance, TurnSpeed turnSpeed)
|
||||
{
|
||||
DebugLog.ToConsole($"Error - {MethodBase.GetCurrentMethod().Name} not supported!", OWML.Common.MessageType.Error);
|
||||
return false;
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ public abstract class QSBGhostAction
|
||||
{
|
||||
protected QSBGhostBrain _brain;
|
||||
protected QSBGhostData _data => _brain._data;
|
||||
protected GhostController _controller => _brain.AttachedObject._controller;
|
||||
protected QSBGhostController _controller => _brain._controller;
|
||||
protected QSBGhostSensors _sensors => _brain.AttachedObject._sensors.GetWorldObject<QSBGhostSensors>();
|
||||
protected QSBGhostEffects _effects => _brain.AttachedObject._effects.GetWorldObject<QSBGhostEffects>();
|
||||
protected Transform _transform;
|
||||
@ -83,7 +83,7 @@ public abstract class QSBGhostAction
|
||||
public virtual void Initialize(QSBGhostBrain brain)
|
||||
{
|
||||
_brain = brain;
|
||||
this._transform = this._controller.transform;
|
||||
this._transform = this._controller.AttachedObject.transform;
|
||||
}
|
||||
|
||||
public void EnterAction()
|
||||
|
@ -1,4 +1,5 @@
|
||||
using UnityEngine;
|
||||
using QSB.EchoesOfTheEye.Ghosts.WorldObjects;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.Ghosts;
|
||||
|
||||
@ -55,7 +56,7 @@ public class QSBGhostData
|
||||
}
|
||||
}
|
||||
|
||||
public void FixedUpdate_Data(GhostController controller, GhostSensors sensors)
|
||||
public void FixedUpdate_Data(QSBGhostController controller, GhostSensors sensors)
|
||||
{
|
||||
wasPlayerLocationKnown = isPlayerLocationKnown;
|
||||
isPlayerLocationKnown = sensor.isPlayerVisible || sensor.isPlayerHeldLanternVisible || sensor.isIlluminatedByPlayer || sensor.inContactWithPlayer;
|
||||
@ -66,7 +67,7 @@ public class QSBGhostData
|
||||
|
||||
var worldPosition = Locator.GetPlayerTransform().position - Locator.GetPlayerTransform().up;
|
||||
var worldVelocity = Locator.GetPlayerBody().GetVelocity() - controller.GetNodeMap().GetOWRigidbody().GetVelocity();
|
||||
playerLocation.Update(worldPosition, worldVelocity, controller);
|
||||
playerLocation.Update(worldPosition, worldVelocity, controller.AttachedObject);
|
||||
playerMinLanternRange = Locator.GetDreamWorldController().GetPlayerLantern().GetLanternController().GetMinRange();
|
||||
if (isPlayerLocationKnown)
|
||||
{
|
||||
@ -82,7 +83,7 @@ public class QSBGhostData
|
||||
firstUnknownSensor.CopyFromOther(sensor);
|
||||
}
|
||||
|
||||
lastKnownPlayerLocation.Update(controller);
|
||||
lastKnownPlayerLocation.Update(controller.AttachedObject);
|
||||
timeSincePlayerLocationKnown += Time.deltaTime;
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,8 @@ public class QSBGhostBrain : WorldObject<GhostBrain>, IGhostObject
|
||||
|
||||
public override void DisplayLines()
|
||||
{
|
||||
ControllerLines(AttachedObject._controller);
|
||||
DataLines(_data, AttachedObject._controller);
|
||||
ControllerLines(_controller);
|
||||
DataLines(_data, _controller);
|
||||
|
||||
if (_currentAction != null)
|
||||
{
|
||||
@ -51,9 +51,9 @@ public class QSBGhostBrain : WorldObject<GhostBrain>, IGhostObject
|
||||
}
|
||||
}
|
||||
|
||||
private void ControllerLines(GhostController controller)
|
||||
private void ControllerLines(QSBGhostController controller)
|
||||
{
|
||||
Popcron.Gizmos.Sphere(controller.transform.position, 2f, Color.white);
|
||||
Popcron.Gizmos.Sphere(controller.AttachedObject.transform.position, 2f, Color.white);
|
||||
|
||||
if (controller._followNodePath)
|
||||
{
|
||||
@ -77,17 +77,18 @@ public class QSBGhostBrain : WorldObject<GhostBrain>, IGhostObject
|
||||
}
|
||||
}
|
||||
|
||||
private void DataLines(QSBGhostData data, GhostController controller)
|
||||
private void DataLines(QSBGhostData data, QSBGhostController controller)
|
||||
{
|
||||
if (data.timeSincePlayerLocationKnown != float.PositiveInfinity)
|
||||
{
|
||||
Popcron.Gizmos.Line(controller.transform.position, controller.LocalToWorldPosition(data.lastKnownPlayerLocation.localPosition), Color.magenta);
|
||||
Popcron.Gizmos.Line(controller.AttachedObject.transform.position, controller.LocalToWorldPosition(data.lastKnownPlayerLocation.localPosition), Color.magenta);
|
||||
Popcron.Gizmos.Sphere(controller.LocalToWorldPosition(data.lastKnownPlayerLocation.localPosition), 1f, Color.magenta);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
internal QSBGhostController _controller;
|
||||
internal QSBGhostData _data;
|
||||
private List<QSBGhostAction> _actionLibrary = new();
|
||||
private QSBGhostAction _currentAction;
|
||||
@ -156,7 +157,7 @@ public class QSBGhostBrain : WorldObject<GhostBrain>, IGhostObject
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
AttachedObject._controller = AttachedObject.GetComponent<GhostController>();
|
||||
_controller = AttachedObject.GetComponent<GhostController>().GetWorldObject<QSBGhostController>();
|
||||
AttachedObject._sensors = AttachedObject.GetComponent<GhostSensors>();
|
||||
_data = new();
|
||||
if (AttachedObject._data != null)
|
||||
@ -168,13 +169,13 @@ public class QSBGhostBrain : WorldObject<GhostBrain>, IGhostObject
|
||||
public void Start()
|
||||
{
|
||||
AttachedObject.enabled = false;
|
||||
AttachedObject._controller.GetDreamLanternController().enabled = false;
|
||||
AttachedObject._controller.Initialize(AttachedObject._nodeLayer, AttachedObject._effects);
|
||||
_controller.GetDreamLanternController().enabled = false;
|
||||
_controller.Initialize(AttachedObject._nodeLayer, AttachedObject._effects.GetWorldObject<QSBGhostEffects>());
|
||||
AttachedObject._sensors.GetWorldObject<QSBGhostSensors>().Initialize(_data, AttachedObject._guardVolume);
|
||||
AttachedObject._effects.GetWorldObject<QSBGhostEffects>().Initialize(AttachedObject._controller.GetNodeRoot(), AttachedObject._controller, _data);
|
||||
AttachedObject._effects.GetWorldObject<QSBGhostEffects>().Initialize(_controller.GetNodeRoot(), _controller, _data);
|
||||
AttachedObject._effects.OnCallForHelp += AttachedObject.OnCallForHelp;
|
||||
_data.reducedFrights_allowChase = AttachedObject._reducedFrights_allowChase;
|
||||
AttachedObject._controller.SetLanternConcealed(AttachedObject._startWithLanternConcealed, false);
|
||||
_controller.SetLanternConcealed(AttachedObject._startWithLanternConcealed, false);
|
||||
AttachedObject._intruderConfirmedBySelf = false;
|
||||
AttachedObject._intruderConfirmPending = false;
|
||||
AttachedObject._intruderConfirmTime = 0f;
|
||||
@ -195,10 +196,10 @@ public class QSBGhostBrain : WorldObject<GhostBrain>, IGhostObject
|
||||
public void OnDestroy()
|
||||
{
|
||||
AttachedObject._sensors.RemoveEventListeners();
|
||||
AttachedObject._controller.OnArriveAtPosition -= AttachedObject.OnArriveAtPosition;
|
||||
AttachedObject._controller.OnTraversePathNode -= AttachedObject.OnTraversePathNode;
|
||||
AttachedObject._controller.OnFaceNode -= AttachedObject.OnFaceNode;
|
||||
AttachedObject._controller.OnFinishFaceNodeList -= AttachedObject.OnFinishFaceNodeList;
|
||||
_controller.AttachedObject.OnArriveAtPosition -= AttachedObject.OnArriveAtPosition;
|
||||
_controller.AttachedObject.OnTraversePathNode -= AttachedObject.OnTraversePathNode;
|
||||
_controller.AttachedObject.OnFaceNode -= AttachedObject.OnFaceNode;
|
||||
_controller.AttachedObject.OnFinishFaceNodeList -= AttachedObject.OnFinishFaceNodeList;
|
||||
AttachedObject._effects.OnCallForHelp -= AttachedObject.OnCallForHelp;
|
||||
GlobalMessenger.RemoveListener("EnterDreamWorld", new Callback(AttachedObject.OnEnterDreamWorld));
|
||||
GlobalMessenger.RemoveListener("ExitDreamWorld", new Callback(AttachedObject.OnExitDreamWorld));
|
||||
@ -221,11 +222,11 @@ public class QSBGhostBrain : WorldObject<GhostBrain>, IGhostObject
|
||||
}
|
||||
|
||||
_data.isAlive = false;
|
||||
AttachedObject._controller.StopMoving();
|
||||
AttachedObject._controller.StopFacing();
|
||||
AttachedObject._controller.ExtinguishLantern();
|
||||
AttachedObject._controller.GetCollider().GetComponent<OWCollider>().SetActivation(false);
|
||||
AttachedObject._controller.GetGrabController().ReleasePlayer();
|
||||
_controller.StopMoving();
|
||||
_controller.StopFacing();
|
||||
_controller.ExtinguishLantern();
|
||||
_controller.GetCollider().GetComponent<OWCollider>().SetActivation(false);
|
||||
_controller.GetGrabController().ReleasePlayer();
|
||||
_pendingAction = null;
|
||||
_currentAction = null;
|
||||
_data.currentAction = GhostAction.Name.None;
|
||||
@ -299,7 +300,7 @@ public class QSBGhostBrain : WorldObject<GhostBrain>, IGhostObject
|
||||
|
||||
AttachedObject._effects.PlayRespondToHelpCallAudio(reactDelay);
|
||||
_data.reduceGuardUtility = true;
|
||||
_data.lastKnownPlayerLocation.UpdateLocalPosition(playerLocalPosition, AttachedObject._controller);
|
||||
_data.lastKnownPlayerLocation.UpdateLocalPosition(playerLocalPosition, _controller.AttachedObject);
|
||||
_data.wasPlayerLocationKnown = true;
|
||||
_data.timeSincePlayerLocationKnown = 0f;
|
||||
return true;
|
||||
@ -319,7 +320,7 @@ public class QSBGhostBrain : WorldObject<GhostBrain>, IGhostObject
|
||||
|
||||
if (informationTime > _data.timeLastSawPlayer)
|
||||
{
|
||||
_data.lastKnownPlayerLocation.UpdateLocalPosition(localPosition, AttachedObject._controller);
|
||||
_data.lastKnownPlayerLocation.UpdateLocalPosition(localPosition, _controller.AttachedObject);
|
||||
_data.wasPlayerLocationKnown = true;
|
||||
_data.timeSincePlayerLocationKnown = 0f;
|
||||
}
|
||||
@ -331,9 +332,9 @@ public class QSBGhostBrain : WorldObject<GhostBrain>, IGhostObject
|
||||
{
|
||||
return;
|
||||
}
|
||||
AttachedObject._controller.FixedUpdate_Controller();
|
||||
_controller.FixedUpdate_Controller();
|
||||
AttachedObject._sensors.FixedUpdate_Sensors();
|
||||
_data.FixedUpdate_Data(AttachedObject._controller, AttachedObject._sensors);
|
||||
_data.FixedUpdate_Data(_controller, AttachedObject._sensors);
|
||||
AttachedObject.FixedUpdate_ThreatAwareness();
|
||||
if (_currentAction != null)
|
||||
{
|
||||
@ -347,7 +348,7 @@ public class QSBGhostBrain : WorldObject<GhostBrain>, IGhostObject
|
||||
{
|
||||
return;
|
||||
}
|
||||
AttachedObject._controller.Update_Controller();
|
||||
_controller.Update_Controller();
|
||||
AttachedObject._sensors.Update_Sensors();
|
||||
AttachedObject._effects.Update_Effects();
|
||||
var flag = false;
|
||||
@ -524,13 +525,13 @@ public class QSBGhostBrain : WorldObject<GhostBrain>, IGhostObject
|
||||
public void OnEnterDreamWorld()
|
||||
{
|
||||
AttachedObject.enabled = true;
|
||||
AttachedObject._controller.GetDreamLanternController().enabled = true;
|
||||
_controller.GetDreamLanternController().enabled = true;
|
||||
}
|
||||
|
||||
public void OnExitDreamWorld()
|
||||
{
|
||||
AttachedObject.enabled = false;
|
||||
AttachedObject._controller.GetDreamLanternController().enabled = false;
|
||||
_controller.GetDreamLanternController().enabled = false;
|
||||
ChangeAction(null);
|
||||
_data.OnPlayerExitDreamWorld();
|
||||
}
|
||||
|
76
QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostController.cs
Normal file
76
QSB/EchoesOfTheEye/Ghosts/WorldObjects/QSBGhostController.cs
Normal file
@ -0,0 +1,76 @@
|
||||
using GhostEnums;
|
||||
using QSB.Player;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.Ghosts.WorldObjects;
|
||||
|
||||
public class QSBGhostController : WorldObject<GhostController>, IGhostObject
|
||||
{
|
||||
public override void SendInitialState(uint to)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public QSBGhostEffects _effects;
|
||||
|
||||
public void Initialize(GhostNode.NodeLayer layer, QSBGhostEffects effects)
|
||||
{
|
||||
_effects = effects;
|
||||
AttachedObject._nodeRoot = AttachedObject.transform.parent = AttachedObject._nodeMap.transform;
|
||||
AttachedObject._nodeLayer = layer;
|
||||
AttachedObject._grabController.Initialize(effects.AttachedObject);
|
||||
AttachedObject._lantern.SetLit(true);
|
||||
AttachedObject.MoveLanternToCarrySocket(false, 0.1f);
|
||||
AttachedObject._playerCollider = Locator.GetPlayerBody().GetComponent<CapsuleCollider>();
|
||||
}
|
||||
|
||||
public void SetLanternConcealed(bool concealed, bool playAudio = true)
|
||||
{
|
||||
if (playAudio && AttachedObject._lantern.IsConcealed() != concealed)
|
||||
{
|
||||
_effects.PlayLanternAudio(concealed ? global::AudioType.Artifact_Conceal : global::AudioType.Artifact_Unconceal);
|
||||
}
|
||||
|
||||
AttachedObject._lantern.SetConcealed(concealed);
|
||||
if (concealed)
|
||||
{
|
||||
AttachedObject._lantern.SetFocus(0f);
|
||||
AttachedObject._updateLantern = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeLanternFocus(float focus, float focusRate = 2f)
|
||||
{
|
||||
if (focus > 0f)
|
||||
{
|
||||
AttachedObject._lantern.SetConcealed(false);
|
||||
}
|
||||
|
||||
if (focus > AttachedObject._targetLanternFocus)
|
||||
{
|
||||
_effects.PlayLanternAudio(global::AudioType.Artifact_Focus);
|
||||
}
|
||||
else if (focus < AttachedObject._targetLanternFocus)
|
||||
{
|
||||
_effects.PlayLanternAudio(global::AudioType.Artifact_Unfocus);
|
||||
}
|
||||
|
||||
AttachedObject._updateLantern = true;
|
||||
AttachedObject._targetLanternFocus = focus;
|
||||
AttachedObject._lanternFocusRate = focusRate;
|
||||
}
|
||||
|
||||
public void FacePlayer(PlayerInfo player, TurnSpeed turnSpeed)
|
||||
{
|
||||
AttachedObject._facingState = GhostController.FacingState.FaceTransform;
|
||||
AttachedObject._faceTransform = player.Camera.transform;
|
||||
AttachedObject._targetDegreesPerSecond = GhostConstants.GetTurnSpeed(turnSpeed);
|
||||
AttachedObject._angularAcceleration = GhostConstants.GetTurnAcceleration(turnSpeed);
|
||||
}
|
||||
}
|
@ -20,10 +20,10 @@ public class QSBGhostEffects : WorldObject<GhostEffects>, IGhostObject
|
||||
|
||||
private QSBGhostData _data;
|
||||
|
||||
public void Initialize(Transform nodeRoot, GhostController controller, QSBGhostData data)
|
||||
public void Initialize(Transform nodeRoot, QSBGhostController controller, QSBGhostData data)
|
||||
{
|
||||
AttachedObject._animator = AttachedObject.GetComponent<Animator>();
|
||||
AttachedObject._controller = controller;
|
||||
AttachedObject._controller = controller.AttachedObject;
|
||||
_data = data;
|
||||
if (AttachedObject._feetAudioSourceFar != null)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user