mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-19 12:40:56 +00:00
add back in qsbsearchaction smh
This commit is contained in:
parent
2dc62cee8f
commit
6265b97bfd
109
QSB/EchoesOfTheEye/Ghosts/Actions/QSBSearchAction.cs
Normal file
109
QSB/EchoesOfTheEye/Ghosts/Actions/QSBSearchAction.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using GhostEnums;
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.Ghosts.Actions;
|
||||
|
||||
public class QSBSearchAction : QSBGhostAction
|
||||
{
|
||||
private GhostNode _targetSearchNode;
|
||||
|
||||
private bool _searchingAtNode;
|
||||
|
||||
private float _searchStartTime;
|
||||
|
||||
public override GhostAction.Name GetName()
|
||||
{
|
||||
return GhostAction.Name.SearchForIntruder;
|
||||
}
|
||||
|
||||
public override float CalculateUtility()
|
||||
{
|
||||
if (!_controller.GetNodeMap().HasSearchNodes(_controller.GetNodeLayer()))
|
||||
{
|
||||
return -100f;
|
||||
}
|
||||
|
||||
if (_data.threatAwareness >= GhostData.ThreatAwareness.SomeoneIsInHere)
|
||||
{
|
||||
return 50f;
|
||||
}
|
||||
|
||||
return -100f;
|
||||
}
|
||||
|
||||
protected override void OnEnterAction()
|
||||
{
|
||||
_controller.SetLanternConcealed(true, true);
|
||||
_effects.AttachedObject.SetMovementStyle(GhostEffects.MovementStyle.Normal);
|
||||
ContinueSearch();
|
||||
}
|
||||
|
||||
protected override void OnExitAction()
|
||||
{
|
||||
if (_searchingAtNode)
|
||||
{
|
||||
_controller.FaceVelocity();
|
||||
}
|
||||
|
||||
_targetSearchNode = null;
|
||||
_searchingAtNode = false;
|
||||
}
|
||||
|
||||
public override bool Update_Action()
|
||||
{
|
||||
if (_searchingAtNode && Time.time > _searchStartTime + 4f)
|
||||
{
|
||||
_controller.FaceVelocity();
|
||||
_targetSearchNode.searchData.lastSearchTime = Time.time;
|
||||
ContinueSearch();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void OnArriveAtPosition()
|
||||
{
|
||||
_controller.Spin(TurnSpeed.MEDIUM);
|
||||
_searchingAtNode = true;
|
||||
_searchStartTime = Time.time;
|
||||
}
|
||||
|
||||
private void ContinueSearch()
|
||||
{
|
||||
_searchingAtNode = false;
|
||||
_targetSearchNode = GetHighestPriorityNodeToSearch();
|
||||
if (_targetSearchNode == null)
|
||||
{
|
||||
Debug.LogError("Failed to find any nodes to search! Did we exhaust our existing options?", _controller);
|
||||
Debug.Break();
|
||||
}
|
||||
|
||||
_controller.PathfindToNode(_targetSearchNode, MoveType.SEARCH);
|
||||
_controller.FaceVelocity();
|
||||
}
|
||||
|
||||
private GhostNode GetHighestPriorityNodeToSearch()
|
||||
{
|
||||
var searchNodesOnLayer = _controller.GetNodeMap().GetSearchNodesOnLayer(_controller.GetNodeLayer());
|
||||
var num = 0f;
|
||||
var time = Time.time;
|
||||
for (var i = 0; i < searchNodesOnLayer.Length; i++)
|
||||
{
|
||||
var num2 = time - searchNodesOnLayer[i].searchData.lastSearchTime;
|
||||
num += num2;
|
||||
}
|
||||
|
||||
num /= (float)searchNodesOnLayer.Length;
|
||||
GhostNode ghostNode = null;
|
||||
for (var j = 0; j < 5; j++)
|
||||
{
|
||||
ghostNode = searchNodesOnLayer[Random.Range(0, searchNodesOnLayer.Length)];
|
||||
if (time - ghostNode.searchData.lastSearchTime > num)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ghostNode;
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ internal class GhostManager : WorldObjectManager
|
||||
|
||||
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct)
|
||||
{
|
||||
QSBWorldSync.Init<QSBGhostController, GhostController>();
|
||||
QSBWorldSync.Init<QSBGhostEffects, GhostEffects>();
|
||||
QSBWorldSync.Init<QSBGhostSensors, GhostSensors>();
|
||||
QSBWorldSync.Init<QSBGhostBrain, GhostBrain>(QSBWorldSync.GetUnityObjects<GhostBrain>().Where(x => x.gameObject.activeSelf).SortDeterministic());
|
||||
|
Loading…
x
Reference in New Issue
Block a user