quantum-space-buddies/QSB/EchoesOfTheEye/Ghosts/QSBGhostData.cs

124 lines
3.7 KiB
C#
Raw Permalink Normal View History

2022-03-21 16:42:09 +00:00
using QSB.EchoesOfTheEye.Ghosts.WorldObjects;
2022-04-02 09:54:12 +00:00
using QSB.Player;
using QSB.Utility;
using System.Collections.Generic;
using System.Linq;
2022-03-21 16:42:09 +00:00
using UnityEngine;
namespace QSB.EchoesOfTheEye.Ghosts;
public class QSBGhostData
{
public GhostData.ThreatAwareness threatAwareness;
public GhostAction.Name currentAction = GhostAction.Name.None;
public GhostAction.Name previousAction = GhostAction.Name.None;
public bool isAlive = true;
public bool hasWokenUp;
public bool reduceGuardUtility;
public bool fastStalkUnlocked;
public float illuminatedByPlayerMeter;
public bool reducedFrights_allowChase;
2022-04-02 09:54:12 +00:00
public bool isIlluminated;
public bool IsIlluminatedByAnyPlayer => players.Values.Any(x => x.sensor.isIlluminatedByPlayer);
public Dictionary<PlayerInfo, GhostPlayer> players = new();
public GhostPlayer localPlayer => players[QSBPlayerManager.LocalPlayer];
public GhostPlayer interestedPlayer;
public void TabulaRasa()
{
threatAwareness = GhostData.ThreatAwareness.EverythingIsNormal;
reduceGuardUtility = false;
fastStalkUnlocked = false;
illuminatedByPlayerMeter = 0f;
2022-04-02 09:54:12 +00:00
foreach (var player in players.Values)
{
player.isPlayerLocationKnown = false;
player.wasPlayerLocationKnown = false;
player.timeLastSawPlayer = 0f;
player.timeSincePlayerLocationKnown = float.PositiveInfinity;
player.playerMinLanternRange = 0f;
}
}
public void OnPlayerExitDreamWorld(PlayerInfo player)
{
players[player].isPlayerLocationKnown = false;
players[player].wasPlayerLocationKnown = false;
players[player].timeSincePlayerLocationKnown = float.PositiveInfinity;
}
public void OnEnterAction(GhostAction.Name actionName)
{
if (actionName == GhostAction.Name.IdentifyIntruder || actionName - GhostAction.Name.Chase <= 2)
{
reduceGuardUtility = true;
}
}
2022-03-21 16:47:24 +00:00
public void FixedUpdate_Data(GhostController controller, GhostSensors sensors)
{
2022-04-02 09:54:12 +00:00
foreach (var player in QSBPlayerManager.PlayerList)
{
2022-04-02 09:54:12 +00:00
if (!players.ContainsKey(player))
{
2022-04-02 14:07:47 +00:00
var newPlayer = new GhostPlayer
{
player = player
};
players.Add(player, newPlayer);
2022-04-02 09:54:12 +00:00
}
}
2022-04-02 09:54:12 +00:00
foreach (var pair in players)
{
2022-04-02 09:54:12 +00:00
var player = pair.Value;
2022-04-10 13:33:09 +00:00
if (!player.player.InDreamWorld)
{
continue;
}
2022-04-02 09:54:12 +00:00
player.wasPlayerLocationKnown = player.isPlayerLocationKnown;
player.isPlayerLocationKnown = player.sensor.isPlayerVisible
|| player.sensor.isPlayerHeldLanternVisible
|| player.sensor.isIlluminatedByPlayer
|| player.sensor.inContactWithPlayer;
if (!reduceGuardUtility && player.sensor.isIlluminatedByPlayer)
{
reduceGuardUtility = true;
}
var worldPosition = pair.Key.Body.transform.position - pair.Key.Body.transform.up;
var worldVelocity = pair.Key.Velocity - controller.GetNodeMap().GetOWRigidbody().GetVelocity();
2022-04-02 09:54:12 +00:00
player.playerLocation.Update(worldPosition, worldVelocity, controller);
player.playerMinLanternRange = pair.Key.AssignedSimulationLantern.AttachedObject.GetLanternController().GetMinRange();
if (player.isPlayerLocationKnown)
{
2022-04-02 09:54:12 +00:00
player.lastKnownPlayerLocation.CopyFromOther(player.playerLocation);
player.lastKnownSensor.CopyFromOther(player.sensor);
player.timeLastSawPlayer = Time.time;
player.timeSincePlayerLocationKnown = 0f;
}
2022-04-02 09:54:12 +00:00
else
{
if (player.wasPlayerLocationKnown)
{
player.firstUnknownSensor.CopyFromOther(player.sensor);
}
2022-04-02 09:54:12 +00:00
player.lastKnownPlayerLocation.Update(controller);
player.timeSincePlayerLocationKnown += Time.deltaTime;
}
}
2022-04-02 09:54:12 +00:00
if (threatAwareness >= GhostData.ThreatAwareness.IntruderConfirmed && IsIlluminatedByAnyPlayer && !PlayerData.GetReducedFrights())
{
illuminatedByPlayerMeter += Time.deltaTime;
return;
}
illuminatedByPlayerMeter = Mathf.Max(0f, illuminatedByPlayerMeter - (Time.deltaTime * 0.5f));
}
}