fix some bugs and add some logs

This commit is contained in:
Mister_Nebula 2022-03-21 09:56:05 +00:00 committed by JohnCorby
parent 3007d874bb
commit 9b6537d120
10 changed files with 249 additions and 151 deletions

View File

@ -1,4 +1,5 @@
using GhostEnums;
using QSB.Utility;
using UnityEngine;
namespace QSB.EchoesOfTheEye.Ghosts.Actions;
@ -30,6 +31,7 @@ internal class QSBCallForHelpAction : QSBGhostAction
protected override void OnEnterAction()
{
DebugLog.DebugWrite($"{_brain.AttachedObject._name} : Calling for help!");
_hasCalledForHelp = true;
_hasStartedMoving = false;
_controller.ChangeLanternFocus(1f, 2f);

View File

@ -3,59 +3,47 @@ using System.Collections.Generic;
using GhostEnums;
using QSB.EchoesOfTheEye.Ghosts;
using QSB.EchoesOfTheEye.Ghosts.WorldObjects;
using QSB.Utility;
using UnityEngine;
public class QSBHuntAction : QSBGhostAction
{
private int _numNodesToSearch;
private GhostNodeMap.NodeSearchData[] _nodesToSearch;
private int _currentNodeIndex;
private GhostNode _closestNode;
private bool _startAtClosestNode;
private bool _huntStarted;
private float _huntStartTime;
private bool _huntFailed;
private float _huntFailTime;
private List<int> _spotlightIndexList = new List<int>(16);
private int _spotlightIndex = -1;
private Vector3 _DEBUG_localPos;
private Vector3 _DEBUG_localVel;
public override void Initialize(QSBGhostBrain brain)
{
base.Initialize(brain);
this._numNodesToSearch = 0;
this._nodesToSearch = new GhostNodeMap.NodeSearchData[this._controller.GetNodeMap().GetNodeCount()];
this._currentNodeIndex = 0;
this._huntStarted = false;
this._huntStartTime = 0f;
this._huntFailed = false;
this._huntFailTime = 0f;
_controller.OnNodeMapChanged += new OWEvent.OWCallback(this.OnNodeMapChanged);
_numNodesToSearch = 0;
_nodesToSearch = new GhostNodeMap.NodeSearchData[_controller.GetNodeMap().GetNodeCount()];
_currentNodeIndex = 0;
_huntStarted = false;
_huntStartTime = 0f;
_huntFailed = false;
_huntFailTime = 0f;
_controller.OnNodeMapChanged += new OWEvent.OWCallback(OnNodeMapChanged);
}
private void OnNodeMapChanged()
{
if (this._running)
if (_running)
{
Debug.LogError("Changing node maps while the Hunt action is running is almost definitely not supported!");
this._huntFailed = true;
_huntFailed = true;
}
this._numNodesToSearch = 0;
this._nodesToSearch = new GhostNodeMap.NodeSearchData[this._controller.GetNodeMap().GetNodeCount()];
this._currentNodeIndex = 0;
_numNodesToSearch = 0;
_nodesToSearch = new GhostNodeMap.NodeSearchData[_controller.GetNodeMap().GetNodeCount()];
_currentNodeIndex = 0;
}
public override GhostAction.Name GetName()
@ -65,98 +53,103 @@ public class QSBHuntAction : QSBGhostAction
public override float CalculateUtility()
{
if (this._data.threatAwareness < GhostData.ThreatAwareness.IntruderConfirmed)
if (_data.threatAwareness < GhostData.ThreatAwareness.IntruderConfirmed)
{
return -100f;
}
if (this._huntFailed && this._huntFailTime > this._data.timeLastSawPlayer)
if (_huntFailed && _huntFailTime > _data.timeLastSawPlayer)
{
return -100f;
}
if (this._running || this._data.timeSincePlayerLocationKnown < 60f)
if (_running || _data.timeSincePlayerLocationKnown < 60f)
{
return 80f;
}
return -100f;
}
protected override void OnEnterAction()
{
this._controller.SetLanternConcealed(true, true);
this._controller.FaceVelocity();
this._effects.AttachedObject.SetMovementStyle(GhostEffects.MovementStyle.Normal);
if (!this._huntStarted || this._data.timeLastSawPlayer > this._huntStartTime)
_controller.SetLanternConcealed(true, true);
_controller.FaceVelocity();
_effects.AttachedObject.SetMovementStyle(GhostEffects.MovementStyle.Normal);
if (!_huntStarted || _data.timeLastSawPlayer > _huntStartTime)
{
Vector3 vector = this._data.lastKnownSensor.knowsPlayerVelocity ? this._data.lastKnownPlayerLocation.localVelocity : Vector3.zero;
this._numNodesToSearch = this._controller.GetNodeMap().FindPossiblePlayerNodes(this._data.lastKnownPlayerLocation.localPosition, vector, 30f, this._nodesToSearch, true, null, null, null);
this._currentNodeIndex = 0;
this._startAtClosestNode = false;
this._closestNode = null;
this._huntStarted = true;
this._huntStartTime = Time.time;
this._huntFailed = false;
if (this._numNodesToSearch == 0)
var knownPlayerVelocity = _data.lastKnownSensor.knowsPlayerVelocity ? _data.lastKnownPlayerLocation.localVelocity : Vector3.zero;
_numNodesToSearch = _controller.GetNodeMap().FindPossiblePlayerNodes(_data.lastKnownPlayerLocation.localPosition, knownPlayerVelocity, 30f, _nodesToSearch, true, null, null, null);
_currentNodeIndex = 0;
_startAtClosestNode = false;
_closestNode = null;
_huntStarted = true;
_huntStartTime = Time.time;
_huntFailed = false;
if (_numNodesToSearch == 0)
{
Debug.LogError("Failed to find nodes to hunt player!", this._controller);
this._huntFailed = true;
this._huntFailTime = Time.time;
DebugLog.DebugWrite($"{_brain.AttachedObject._name} : Failed to find nodes to hunt player.", OWML.Common.MessageType.Error);
_huntFailed = true;
_huntFailTime = Time.time;
}
this._DEBUG_localPos = this._data.lastKnownPlayerLocation.localPosition;
this._DEBUG_localVel = vector;
}
if (!this._huntFailed)
if (!_huntFailed)
{
this._closestNode = this._controller.GetNodeMap().FindClosestNode(this._controller.GetLocalFeetPosition());
for (int i = 0; i < this._closestNode.visibleNodes.Count; i++)
_closestNode = _controller.GetNodeMap().FindClosestNode(_controller.GetLocalFeetPosition());
for (var i = 0; i < _closestNode.visibleNodes.Count; i++)
{
for (int j = 0; j < this._numNodesToSearch; j++)
for (var j = 0; j < _numNodesToSearch; j++)
{
if (this._closestNode.visibleNodes[i] == this._nodesToSearch[j].node.index)
if (_closestNode.visibleNodes[i] == _nodesToSearch[j].node.index)
{
this._startAtClosestNode = true;
_startAtClosestNode = true;
break;
}
}
}
if (this._startAtClosestNode)
if (_startAtClosestNode)
{
this._controller.PathfindToNode(this._closestNode, MoveType.SEARCH);
_controller.PathfindToNode(_closestNode, MoveType.SEARCH);
}
else
{
this._controller.PathfindToNode(this._nodesToSearch[this._currentNodeIndex].node, MoveType.SEARCH);
_controller.PathfindToNode(_nodesToSearch[_currentNodeIndex].node, MoveType.SEARCH);
}
this._effects.AttachedObject.PlayVoiceAudioNear(global::AudioType.Ghost_Hunt, 1f);
_effects.AttachedObject.PlayVoiceAudioNear(AudioType.Ghost_Hunt, 1f);
}
}
protected override void OnExitAction()
{
if (this._huntFailed && !this._data.isPlayerLocationKnown)
if (_huntFailed && !_data.isPlayerLocationKnown)
{
this._effects.AttachedObject.PlayVoiceAudioNear(global::AudioType.Ghost_HuntFail, 1f);
DebugLog.DebugWrite($"{_brain.AttachedObject._name} : Hunt failed. :(");
_effects.AttachedObject.PlayVoiceAudioNear(AudioType.Ghost_HuntFail, 1f);
}
}
public override bool Update_Action()
{
return !this._huntFailed && !this._data.isPlayerLocationKnown;
return !_huntFailed && !_data.isPlayerLocationKnown;
}
public override void FixedUpdate_Action()
{
if (this._huntStarted && !this._huntFailed && this._spotlightIndexList.Count > 0 && !this._controller.GetDreamLanternController().IsConcealed())
if (_huntStarted && !_huntFailed && _spotlightIndexList.Count > 0 && !_controller.GetDreamLanternController().IsConcealed())
{
for (int i = 0; i < this._spotlightIndexList.Count; i++)
for (var i = 0; i < _spotlightIndexList.Count; i++)
{
if (!this._nodesToSearch[this._spotlightIndexList[i]].searched)
if (!_nodesToSearch[_spotlightIndexList[i]].searched)
{
Vector3 from = this._nodesToSearch[this._spotlightIndexList[i]].node.localPosition - this._controller.GetLocalFeetPosition();
OWLight2 light = this._controller.GetDreamLanternController().GetLight();
Vector3 to = this._controller.WorldToLocalDirection(light.transform.forward);
if (Vector3.Angle(from, to) < light.GetLight().spotAngle * 0.5f - 5f && from.sqrMagnitude < light.range * light.range)
var from = _nodesToSearch[_spotlightIndexList[i]].node.localPosition - _controller.GetLocalFeetPosition();
var light = _controller.GetDreamLanternController().GetLight();
var to = _controller.WorldToLocalDirection(light.transform.forward);
if (Vector3.Angle(from, to) < (light.GetLight().spotAngle * 0.5f) - 5f && from.sqrMagnitude < light.range * light.range)
{
this._nodesToSearch[this._spotlightIndexList[i]].searched = true;
_nodesToSearch[_spotlightIndexList[i]].searched = true;
}
}
}
@ -165,11 +158,11 @@ public class QSBHuntAction : QSBGhostAction
public override void OnTraversePathNode(GhostNode node)
{
for (int i = 0; i < this._numNodesToSearch; i++)
for (var i = 0; i < _numNodesToSearch; i++)
{
if (node == this._nodesToSearch[i].node)
if (node == _nodesToSearch[i].node)
{
this._nodesToSearch[i].searched = true;
_nodesToSearch[i].searched = true;
}
}
}
@ -177,99 +170,108 @@ public class QSBHuntAction : QSBGhostAction
public override void OnArriveAtPosition()
{
GhostNode node;
if (this._startAtClosestNode)
if (_startAtClosestNode)
{
this._startAtClosestNode = false;
node = this._closestNode;
for (int i = 0; i < this._numNodesToSearch; i++)
_startAtClosestNode = false;
node = _closestNode;
for (var i = 0; i < _numNodesToSearch; i++)
{
if (this._closestNode == this._nodesToSearch[i].node)
if (_closestNode == _nodesToSearch[i].node)
{
this._nodesToSearch[i].searched = true;
_nodesToSearch[i].searched = true;
break;
}
}
}
else
{
node = this._nodesToSearch[this._currentNodeIndex].node;
this._nodesToSearch[this._currentNodeIndex].searched = true;
node = _nodesToSearch[_currentNodeIndex].node;
_nodesToSearch[_currentNodeIndex].searched = true;
}
this.GenerateSpotlightList(node);
if (this._spotlightIndexList.Count > 0)
GenerateSpotlightList(node);
if (_spotlightIndexList.Count > 0)
{
this._controller.SetLanternConcealed(false, true);
this.SpotlightNextNode();
_controller.SetLanternConcealed(false, true);
SpotlightNextNode();
return;
}
this.TryContinueSearch();
TryContinueSearch();
}
public override void OnFaceNode(GhostNode node)
{
int num = this._spotlightIndexList[this._spotlightIndex];
if (node != this._nodesToSearch[num].node)
var num = _spotlightIndexList[_spotlightIndex];
if (node != _nodesToSearch[num].node)
{
Debug.LogError("Why are we facing this node??? " + node.name);
Debug.Break();
return;
}
this._nodesToSearch[num].searched = true;
for (int i = this._spotlightIndexList.Count - 1; i >= 0; i--)
_nodesToSearch[num].searched = true;
for (var i = _spotlightIndexList.Count - 1; i >= 0; i--)
{
if (this._nodesToSearch[this._spotlightIndexList[i]].searched)
if (_nodesToSearch[_spotlightIndexList[i]].searched)
{
this._spotlightIndexList.RemoveAt(i);
_spotlightIndexList.RemoveAt(i);
}
}
if (this._spotlightIndexList.Count > 0)
if (_spotlightIndexList.Count > 0)
{
this.SpotlightNextNode();
SpotlightNextNode();
return;
}
this._controller.SetLanternConcealed(true, true);
this._controller.FaceVelocity();
this.TryContinueSearch();
_controller.SetLanternConcealed(true, true);
_controller.FaceVelocity();
TryContinueSearch();
}
private void SpotlightNextNode()
{
this._spotlightIndex = 0;
int num = this._spotlightIndexList[this._spotlightIndex];
this._controller.FaceNode(this._nodesToSearch[num].node, TurnSpeed.MEDIUM, 1f, true);
_spotlightIndex = 0;
var num = _spotlightIndexList[_spotlightIndex];
_controller.FaceNode(_nodesToSearch[num].node, TurnSpeed.MEDIUM, 1f, true);
}
private void TryContinueSearch()
{
if (Time.time > this._enterTime + 60f)
if (Time.time > _enterTime + 60f)
{
this._huntFailed = true;
this._huntFailTime = Time.time;
_huntFailed = true;
_huntFailTime = Time.time;
return;
}
while (this._nodesToSearch[this._currentNodeIndex].searched && this._currentNodeIndex < this._numNodesToSearch)
while (_nodesToSearch[_currentNodeIndex].searched && _currentNodeIndex < _numNodesToSearch)
{
this._currentNodeIndex++;
_currentNodeIndex++;
}
if (this._currentNodeIndex < this._numNodesToSearch)
if (_currentNodeIndex < _numNodesToSearch)
{
this._controller.PathfindToNode(this._nodesToSearch[this._currentNodeIndex].node, MoveType.SEARCH);
DebugLog.DebugWrite($"{_brain.AttachedObject._name} : Moving to hunt at new node.");
_controller.PathfindToNode(_nodesToSearch[_currentNodeIndex].node, MoveType.SEARCH);
return;
}
this._huntFailed = true;
this._huntFailTime = Time.time;
_huntFailed = true;
_huntFailTime = Time.time;
}
private void GenerateSpotlightList(GhostNode node)
{
this._spotlightIndexList.Clear();
for (int i = 0; i < node.visibleNodes.Count; i++)
_spotlightIndexList.Clear();
for (var i = 0; i < node.visibleNodes.Count; i++)
{
for (int j = 0; j < this._numNodesToSearch; j++)
for (var j = 0; j < _numNodesToSearch; j++)
{
if (!this._nodesToSearch[j].searched && node.visibleNodes[i] == this._nodesToSearch[j].node.index)
if (!_nodesToSearch[j].searched && node.visibleNodes[i] == _nodesToSearch[j].node.index)
{
this._spotlightIndexList.Add(j);
_spotlightIndexList.Add(j);
}
}
}
@ -279,16 +281,13 @@ public class QSBHuntAction : QSBGhostAction
{
if (isGhostSelected)
{
Popcron.Gizmos.Cube(_controller.transform.position + _DEBUG_localPos, Quaternion.identity, Vector3.one, Color.white);
Popcron.Gizmos.Line(_controller.transform.position + _DEBUG_localPos, _controller.transform.position + _DEBUG_localPos + _DEBUG_localVel, Color.white);
for (int i = 0; i < this._numNodesToSearch; i++)
for (var i = 0; i < _numNodesToSearch; i++)
{
float t = Mathf.Abs(this._nodesToSearch[i].score) / 180f;
var t = Mathf.Abs(_nodesToSearch[i].score) / 180f;
Popcron.Gizmos.Sphere(
_controller.LocalToWorldPosition(this._nodesToSearch[i].node.localPosition),
(i < this._currentNodeIndex) ? 0.5f : 2f,
this._nodesToSearch[i].searched ? Color.black : Color.HSVToRGB(Mathf.Lerp(0.5f, 0f, t), 1f, 1f));
_controller.LocalToWorldPosition(_nodesToSearch[i].node.localPosition),
(i < _currentNodeIndex) ? 0.5f : 2f,
_nodesToSearch[i].searched ? Color.black : Color.HSVToRGB(Mathf.Lerp(0.5f, 0f, t), 1f, 1f));
}
}
}

View File

@ -74,8 +74,6 @@ public class QSBIdentifyIntruderAction : QSBGhostAction
protected override void OnEnterAction()
{
DebugLog.DebugWrite($"{_brain.AttachedObject._name} : I saw something...");
_sawPlayerOccluded = false;
_movingToSearchLocation = false;
_arrivedAtTargetSearchPosition = false;
@ -177,33 +175,35 @@ public class QSBIdentifyIntruderAction : QSBGhostAction
}
else
{
var localPos = _data.lastKnownPlayerLocation.localPosition + new Vector3(0f, 1.8f, 0f);
var flag2 = _sensors.AttachedObject.CheckPositionOccluded(_controller.LocalToWorldPosition(localPos));
var num = _allowFocusBeam ? (_controller.GetFocusedLanternRange() - 3f) : (_controller.GetUnfocusedLanternRange() - 1f);
var flag3 = _data.lastKnownPlayerLocation.distance < _controller.GetUnfocusedLanternRange();
var playerLocationToCheck = _data.lastKnownPlayerLocation.localPosition + new Vector3(0f, 1.8f, 0f);
var canSeePlayerCheckLocation = _sensors.AttachedObject.CheckPositionOccluded(_controller.LocalToWorldPosition(playerLocationToCheck));
var lanternRange = _allowFocusBeam
? (_controller.GetFocusedLanternRange() - 3f)
: (_controller.GetUnfocusedLanternRange() - 1f);
var isLastKnownLocationInRange = _data.lastKnownPlayerLocation.distance < _controller.GetUnfocusedLanternRange();
if (_data.sensor.isPlayerIlluminatedByUs)
{
_allowFocusBeam = true;
_controller.FaceLocalPosition(_data.lastKnownPlayerLocation.localPosition, TurnSpeed.MEDIUM);
if (flag3 == _controller.IsLanternFocused())
if (isLastKnownLocationInRange == _controller.IsLanternFocused())
{
_controller.ChangeLanternFocus(flag3 ? 0f : 1f, 2f);
_controller.ChangeLanternFocus(isLastKnownLocationInRange ? 0f : 1f, 2f);
return;
}
}
else if (_data.lastKnownPlayerLocation.distance < num && !flag2)
else if (_data.lastKnownPlayerLocation.distance < lanternRange && !canSeePlayerCheckLocation)
{
if (_allowFocusBeam || !_data.isPlayerLocationKnown)
{
_controller.StopMoving();
}
if (_data.lastKnownPlayerLocation.degreesToPositionXZ < 5f && (flag3 || _controller.IsLanternFocused()))
if (_data.lastKnownPlayerLocation.degreesToPositionXZ < 5f && (isLastKnownLocationInRange || _controller.IsLanternFocused()))
{
_checkingTargetLocation = true;
}
if (flag3)
if (isLastKnownLocationInRange)
{
_controller.FaceLocalPosition(_data.lastKnownPlayerLocation.localPosition, TurnSpeed.FASTEST);
_controller.SetLanternConcealed(false, true);

View File

@ -1,5 +1,6 @@
using GhostEnums;
using QSB.EchoesOfTheEye.Ghosts;
using QSB.Utility;
using UnityEngine;
public class QSBStalkAction : QSBGhostAction
@ -38,15 +39,16 @@ public class QSBStalkAction : QSBGhostAction
_controller.SetLanternConcealed(!_isFocusingLight, true);
_controller.FaceVelocity();
_effects.AttachedObject.SetMovementStyle(GhostEffects.MovementStyle.Stalk);
_effects.AttachedObject.PlayVoiceAudioNear(_data.fastStalkUnlocked ? global::AudioType.Ghost_Stalk_Fast : global::AudioType.Ghost_Stalk, 1f);
_effects.AttachedObject.PlayVoiceAudioNear(_data.fastStalkUnlocked ? AudioType.Ghost_Stalk_Fast : AudioType.Ghost_Stalk, 1f);
}
public override bool Update_Action()
{
if (!_data.fastStalkUnlocked && _data.illuminatedByPlayerMeter > 4f)
{
DebugLog.DebugWrite($"{_brain.AttachedObject._name} Fast stalk unlocked.");
_data.fastStalkUnlocked = true;
_effects.AttachedObject.PlayVoiceAudioNear(global::AudioType.Ghost_Stalk_Fast, 1f);
_effects.AttachedObject.PlayVoiceAudioNear(AudioType.Ghost_Stalk_Fast, 1f);
}
return true;
@ -54,22 +56,26 @@ public class QSBStalkAction : QSBGhostAction
public override void FixedUpdate_Action()
{
var num = GhostConstants.GetMoveSpeed(MoveType.SEARCH);
var stalkSpeed = GhostConstants.GetMoveSpeed(MoveType.SEARCH);
if (_data.fastStalkUnlocked)
{
num += 1.5f;
stalkSpeed += 1.5f;
}
if (_controller.GetNodeMap().CheckLocalPointInBounds(_data.lastKnownPlayerLocation.localPosition))
{
_controller.PathfindToLocalPosition(_data.lastKnownPlayerLocation.localPosition, num, GhostConstants.GetMoveAcceleration(MoveType.SEARCH));
_controller.PathfindToLocalPosition(_data.lastKnownPlayerLocation.localPosition, stalkSpeed, GhostConstants.GetMoveAcceleration(MoveType.SEARCH));
}
_controller.FaceLocalPosition(_data.lastKnownPlayerLocation.localPosition, TurnSpeed.MEDIUM);
var flag = Locator.GetDreamWorldController().GetPlayerLantern().GetLanternController().IsConcealed();
var flag2 = !_wasPlayerLanternConcealed && flag && _data.wasPlayerLocationKnown;
_wasPlayerLanternConcealed = flag;
if (flag2 && !_shouldFocusLightOnPlayer)
var isPlayerLanternConcealed = Locator.GetDreamWorldController().GetPlayerLantern().GetLanternController().IsConcealed();
var sawPlayerLanternConceal = !_wasPlayerLanternConcealed
&& isPlayerLanternConcealed
&& _data.wasPlayerLocationKnown;
_wasPlayerLanternConcealed = isPlayerLanternConcealed;
if (sawPlayerLanternConceal && !_shouldFocusLightOnPlayer)
{
_shouldFocusLightOnPlayer = true;
_changeFocusTime = Time.time + 1f;
@ -84,11 +90,13 @@ public class QSBStalkAction : QSBGhostAction
{
if (_shouldFocusLightOnPlayer)
{
DebugLog.DebugWrite($"{_brain.AttachedObject._name} : Un-concealing lantern and focusing on player.");
_controller.SetLanternConcealed(false, true);
_controller.ChangeLanternFocus(1f, 2f);
}
else
{
DebugLog.DebugWrite($"{_brain.AttachedObject._name} : Concealing lantern.");
_controller.SetLanternConcealed(true, true);
}

View File

@ -58,6 +58,22 @@ internal class GhostBrainPatches : QSBPatch
return false;
}
[HarmonyPrefix]
[HarmonyPatch(nameof(GhostBrain.CheckDreadAudioConditions))]
public static bool CheckDreadAudioConditions(GhostBrain __instance, ref bool __result)
{
__result = __instance.GetWorldObject<QSBGhostBrain>().CheckDreadAudioConditions();
return false;
}
[HarmonyPrefix]
[HarmonyPatch(nameof(GhostBrain.CheckFearAudioConditions))]
public static bool CheckFearAudioConditions(GhostBrain __instance, bool fearAudioAlreadyPlaying, ref bool __result)
{
__result = __instance.GetWorldObject<QSBGhostBrain>().CheckFearAudioConditions(fearAudioAlreadyPlaying);
return false;
}
[HarmonyPrefix]
[HarmonyPatch(nameof(GhostBrain.Awake))]
public static bool Awake(GhostBrain __instance)

View File

@ -32,4 +32,16 @@ internal class GhostHotelDirectorPatches : QSBPatch
return false;
}
/*
* I have no idea why, but for some reason unknown to the damned souls that walk this mortal plane,
* this method only runs when this patch is here. What the absolute fuck.
*/
[HarmonyPrefix]
[HarmonyPatch(typeof(GhostDirector), nameof(GhostDirector.WakeGhosts))]
public static bool WakeGhosts()
{
return true;
}
}

View File

@ -0,0 +1,5 @@
using QSB.WorldSync;
namespace QSB.EchoesOfTheEye.Ghosts.WorldObjects;
public interface IGhostObject : IWorldObject { }

View File

@ -11,7 +11,7 @@ using UnityEngine;
namespace QSB.EchoesOfTheEye.Ghosts.WorldObjects;
public class QSBGhostBrain : WorldObject<GhostBrain>
public class QSBGhostBrain : WorldObject<GhostBrain>, IGhostObject
{
#region World Object Stuff
@ -32,7 +32,10 @@ public class QSBGhostBrain : WorldObject<GhostBrain>
public override string ReturnLabel()
{
var label = $"Name:{AttachedObject.ghostName}\r\nAwareness:{AttachedObject.GetThreatAwareness()}\r\nCurrent Action:{AttachedObject.GetCurrentActionName()}";
var label = $"Name:{AttachedObject.ghostName}" +
$"\r\nAwareness:{AttachedObject.GetThreatAwareness()}" +
$"\r\nCurrent Action:{AttachedObject.GetCurrentActionName()}" +
$"\r\nHas Choke Point:{_data.hasChokePoint}";
return label;
}
@ -46,6 +49,11 @@ public class QSBGhostBrain : WorldObject<GhostBrain>
{
_currentAction.DrawGizmos(true);
}
if (_data.hasChokePoint)
{
Popcron.Gizmos.Sphere(AttachedObject._chokePoint.position, 0.5f, Color.red);
}
}
private void ControllerLines(GhostController controller)
@ -103,16 +111,16 @@ public class QSBGhostBrain : WorldObject<GhostBrain>
public QSBGhostAction GetCurrentAction()
{
return this._currentAction;
return _currentAction;
}
public QSBGhostAction GetAction(GhostAction.Name actionName)
{
for (int i = 0; i < this._actionLibrary.Count; i++)
for (int i = 0; i < _actionLibrary.Count; i++)
{
if (this._actionLibrary[i].GetName() == actionName)
if (_actionLibrary[i].GetName() == actionName)
{
return this._actionLibrary[i];
return _actionLibrary[i];
}
}
return null;
@ -128,6 +136,29 @@ public class QSBGhostBrain : WorldObject<GhostBrain>
return AttachedObject._effects;
}
public bool CheckDreadAudioConditions()
{
return _currentAction != null
&& _data.playerLocation.distance < 10f
&& _currentAction.GetName() != GhostAction.Name.Sentry
&& _currentAction.GetName() != GhostAction.Name.Grab;
}
public bool CheckFearAudioConditions(bool fearAudioAlreadyPlaying)
{
if (_currentAction == null)
{
return false;
}
if (fearAudioAlreadyPlaying)
{
return _currentAction.GetName() is GhostAction.Name.Chase or GhostAction.Name.Grab;
}
return _currentAction.GetName() == GhostAction.Name.Chase;
}
public void Awake()
{
AttachedObject._controller = AttachedObject.GetComponent<GhostController>();
@ -236,6 +267,7 @@ public class QSBGhostBrain : WorldObject<GhostBrain>
public void WakeUp()
{
DebugLog.DebugWrite($"Wake up!");
_data.hasWokenUp = true;
}
@ -265,7 +297,8 @@ public class QSBGhostBrain : WorldObject<GhostBrain>
return false;
}
MonoBehaviour.print(AttachedObject._name + " responding to help call");
DebugLog.DebugWrite($"{AttachedObject._name} Hear call for help!");
if (_data.threatAwareness < GhostData.ThreatAwareness.IntruderConfirmed)
{
_data.threatAwareness = GhostData.ThreatAwareness.IntruderConfirmed;
@ -435,7 +468,7 @@ public class QSBGhostBrain : WorldObject<GhostBrain>
_data.previousAction = GhostAction.Name.None;
}
_currentAction = action;
_data.currentAction = ((action != null) ? action.GetName() : GhostAction.Name.None);
_data.currentAction = (action != null) ? action.GetName() : GhostAction.Name.None;
if (_currentAction != null)
{
_currentAction.EnterAction();
@ -485,6 +518,8 @@ public class QSBGhostBrain : WorldObject<GhostBrain>
public void OnCallForHelp()
{
DebugLog.DebugWrite($"{AttachedObject._name} - iterating through helper list for callforhelp");
if (AttachedObject._helperGhosts != null)
{
for (var i = 0; i < AttachedObject._helperGhosts.Length; i++)

View File

@ -9,7 +9,7 @@ using UnityEngine;
namespace QSB.EchoesOfTheEye.Ghosts.WorldObjects;
public class QSBGhostEffects : WorldObject<GhostEffects>
public class QSBGhostEffects : WorldObject<GhostEffects>, IGhostObject
{
public override void SendInitialState(uint to)
{

View File

@ -9,13 +9,34 @@ using UnityEngine;
namespace QSB.EchoesOfTheEye.Ghosts.WorldObjects;
public class QSBGhostSensors : WorldObject<GhostSensors>
public class QSBGhostSensors : WorldObject<GhostSensors>, IGhostObject
{
public override void SendInitialState(uint to)
{
}
public override void DisplayLines()
{
if (AttachedObject._guardVolume == null)
{
return;
}
var shape = AttachedObject._guardVolume._shape;
if (shape is BoxShape box)
{
Popcron.Gizmos.Cube(
ShapeUtil.Box.CalcWorldSpaceCenter(box),
box.transform.rotation,
ShapeUtil.Box.CalcWorldSpaceSize(box));
}
else
{
DebugLog.DebugWrite($"Unknown shape {shape.GetType()}");
}
}
private QSBGhostData _data;
public void Initialize(QSBGhostData data, OWTriggerVolume guardVolume = null)