113 lines
3.5 KiB
C#
Raw Normal View History

2022-03-18 20:49:44 +00:00
using GhostEnums;
using QSB.EchoesOfTheEye.Ghosts;
2022-03-21 09:56:05 +00:00
using QSB.Utility;
2022-03-18 20:49:44 +00:00
using UnityEngine;
public class QSBStalkAction : QSBGhostAction
{
private bool _wasPlayerLanternConcealed;
private bool _isFocusingLight;
private bool _shouldFocusLightOnPlayer;
private float _changeFocusTime;
public override GhostAction.Name GetName()
2022-03-20 12:12:36 +00:00
=> GhostAction.Name.Stalk;
2022-03-18 20:49:44 +00:00
public override float CalculateUtility()
{
2022-04-02 10:54:12 +01:00
if (_data.interestedPlayer == null)
{
return -100f;
}
if (_data.threatAwareness < GhostData.ThreatAwareness.IntruderConfirmed)
2022-03-18 20:49:44 +00:00
{
return -100f;
}
2022-04-02 10:54:12 +01:00
if ((_running && _data.interestedPlayer.timeSincePlayerLocationKnown < 4f) || _data.interestedPlayer.isPlayerLocationKnown)
2022-03-18 20:49:44 +00:00
{
return 85f;
}
2022-03-18 20:49:44 +00:00
return -100f;
}
protected override void OnEnterAction()
{
// BUG: this checks only for the host's lantern concealed?
2022-03-20 12:12:36 +00:00
var flag = Locator.GetDreamWorldController().GetPlayerLantern().GetLanternController().IsConcealed();
_wasPlayerLanternConcealed = flag;
_isFocusingLight = flag;
_shouldFocusLightOnPlayer = flag;
_changeFocusTime = 0f;
_controller.ChangeLanternFocus(_isFocusingLight ? 1f : 0f, 2f);
_controller.SetLanternConcealed(!_isFocusingLight, true);
_controller.FaceVelocity();
2022-04-14 12:38:34 +01:00
_effects.SetMovementStyle(GhostEffects.MovementStyle.Stalk);
2022-04-14 12:45:56 +01:00
_effects.PlayVoiceAudioNear(_data.fastStalkUnlocked ? AudioType.Ghost_Stalk_Fast : AudioType.Ghost_Stalk, 1f);
2022-03-18 20:49:44 +00:00
}
public override bool Update_Action()
{
if (!_data.fastStalkUnlocked && _data.illuminatedByPlayerMeter > 4f)
2022-03-18 20:49:44 +00:00
{
2022-03-21 09:56:05 +00:00
DebugLog.DebugWrite($"{_brain.AttachedObject._name} Fast stalk unlocked.");
_data.fastStalkUnlocked = true;
2022-04-14 12:45:56 +01:00
_effects.PlayVoiceAudioNear(AudioType.Ghost_Stalk_Fast, 1f);
2022-03-18 20:49:44 +00:00
}
2022-03-20 12:12:36 +00:00
2022-03-18 20:49:44 +00:00
return true;
}
public override void FixedUpdate_Action()
{
2022-03-21 09:56:05 +00:00
var stalkSpeed = GhostConstants.GetMoveSpeed(MoveType.SEARCH);
if (_data.fastStalkUnlocked)
2022-03-18 20:49:44 +00:00
{
2022-03-21 09:56:05 +00:00
stalkSpeed += 1.5f;
2022-03-18 20:49:44 +00:00
}
2022-03-20 12:12:36 +00:00
2022-04-07 08:57:51 +01:00
if (_controller.AttachedObject.GetNodeMap().CheckLocalPointInBounds(_data.interestedPlayer.lastKnownPlayerLocation.localPosition))
2022-03-18 20:49:44 +00:00
{
2022-04-02 10:54:12 +01:00
_controller.PathfindToLocalPosition(_data.interestedPlayer.lastKnownPlayerLocation.localPosition, stalkSpeed, GhostConstants.GetMoveAcceleration(MoveType.SEARCH));
2022-03-18 20:49:44 +00:00
}
2022-03-20 12:12:36 +00:00
2022-04-02 10:54:12 +01:00
_controller.FaceLocalPosition(_data.interestedPlayer.lastKnownPlayerLocation.localPosition, TurnSpeed.MEDIUM);
2022-03-21 09:56:05 +00:00
2022-05-06 19:40:22 +01:00
var isPlayerLanternConcealed = _data.interestedPlayer.player.AssignedSimulationLantern.AttachedObject.GetLanternController().IsConcealed();
2022-03-21 09:56:05 +00:00
var sawPlayerLanternConceal = !_wasPlayerLanternConcealed
&& isPlayerLanternConcealed
2022-04-02 10:54:12 +01:00
&& _data.interestedPlayer.wasPlayerLocationKnown;
2022-03-21 09:56:05 +00:00
_wasPlayerLanternConcealed = isPlayerLanternConcealed;
if (sawPlayerLanternConceal && !_shouldFocusLightOnPlayer)
2022-03-18 20:49:44 +00:00
{
_shouldFocusLightOnPlayer = true;
_changeFocusTime = Time.time + 1f;
2022-03-18 20:49:44 +00:00
}
2022-04-02 10:54:12 +01:00
else if (_data.interestedPlayer.sensor.isPlayerHeldLanternVisible && _shouldFocusLightOnPlayer)
2022-03-18 20:49:44 +00:00
{
_shouldFocusLightOnPlayer = false;
_changeFocusTime = Time.time + 1f;
2022-03-18 20:49:44 +00:00
}
2022-03-20 12:12:36 +00:00
if (_isFocusingLight != _shouldFocusLightOnPlayer && Time.time > _changeFocusTime)
2022-03-18 20:49:44 +00:00
{
if (_shouldFocusLightOnPlayer)
2022-03-18 20:49:44 +00:00
{
2022-03-21 09:56:05 +00:00
DebugLog.DebugWrite($"{_brain.AttachedObject._name} : Un-concealing lantern and focusing on player.");
_controller.SetLanternConcealed(false, true);
_controller.ChangeLanternFocus(1f, 2f);
2022-03-18 20:49:44 +00:00
}
else
{
2022-03-21 09:56:05 +00:00
DebugLog.DebugWrite($"{_brain.AttachedObject._name} : Concealing lantern.");
_controller.SetLanternConcealed(true, true);
2022-03-18 20:49:44 +00:00
}
2022-03-20 12:12:36 +00:00
_isFocusingLight = _shouldFocusLightOnPlayer;
2022-03-18 20:49:44 +00:00
}
}
}