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

117 lines
4.8 KiB
C#
Raw Normal View History

2022-03-18 20:49:44 +00:00
using Cysharp.Threading.Tasks;
using QSB.EchoesOfTheEye.Ghosts.WorldObjects;
2022-03-20 00:21:40 +00:00
using QSB.Utility;
2022-03-18 20:49:44 +00:00
using QSB.WorldSync;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
2022-03-18 20:49:44 +00:00
namespace QSB.EchoesOfTheEye.Ghosts;
2023-07-28 18:30:57 +00:00
public class GhostManager : WorldObjectManager
2022-03-18 20:49:44 +00:00
{
public override WorldObjectScene WorldObjectScene => WorldObjectScene.SolarSystem;
public override bool DlcOnly => true;
private static GhostHotelDirector _hotelDirector;
private static GhostPartyPathDirector _partyPathDirector;
private static GhostZone2Director _zone2Director;
2022-03-18 20:49:44 +00:00
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct)
{
2022-03-21 17:00:21 +00:00
QSBWorldSync.Init<QSBGhostController, GhostController>();
2022-04-22 17:29:50 +00:00
QSBWorldSync.Init<QSBGhostEffects, GhostEffects>(typeof(PrisonerEffects));
QSBWorldSync.Init<QSBPrisonerEffects, GhostEffects>(QSBWorldSync.GetUnityObjects<PrisonerEffects>());
QSBWorldSync.Init<QSBGhostSensors, GhostSensors>();
2022-04-09 21:07:24 +00:00
QSBWorldSync.Init<QSBGhostNodeMap, GhostNodeMap>();
2022-05-01 21:00:25 +00:00
// to avoid disabled ghosts (TheCollector)
2022-03-20 00:21:40 +00:00
QSBWorldSync.Init<QSBGhostBrain, GhostBrain>(QSBWorldSync.GetUnityObjects<GhostBrain>().Where(x => x.gameObject.activeSelf).SortDeterministic());
2022-05-01 21:00:25 +00:00
QSBWorldSync.Init<QSBGhostGrabController, GhostGrabController>();
2022-05-03 07:48:24 +00:00
_hotelDirector = QSBWorldSync.GetUnityObject<GhostHotelDirector>();
_partyPathDirector = QSBWorldSync.GetUnityObject<GhostPartyPathDirector>();
_zone2Director = QSBWorldSync.GetUnityObject<GhostZone2Director>();
for (int i = 0; i < _hotelDirector._hotelDepthsGhosts.Length; i++)
{
_hotelDirector._hotelDepthsGhosts[i].OnIdentifyIntruder -= _hotelDirector.OnHotelDepthsGhostsIdentifiedIntruder;
_hotelDirector._hotelDepthsGhosts[i].GetWorldObject<QSBGhostBrain>().OnIdentifyIntruder += CustomOnHotelDepthsGhostsIdentifiedIntruder;
}
for (var j = 0; j < _partyPathDirector._directedGhosts.Length; j++)
{
_partyPathDirector._directedGhosts[j].OnIdentifyIntruder -= _partyPathDirector.OnGhostIdentifyIntruder;
_partyPathDirector._directedGhosts[j].GetWorldObject<QSBGhostBrain>().OnIdentifyIntruder += CustomOnGhostIdentifyIntruder;
}
for (int i = 0; i < _zone2Director._cityGhosts.Length; i++)
{
_zone2Director._cityGhosts[i].OnIdentifyIntruder -= _zone2Director.OnCityGhostsIdentifiedIntruder;
_zone2Director._cityGhosts[i].GetWorldObject<QSBGhostBrain>().OnIdentifyIntruder += CustomOnCityGhostsIdentifiedIntruder;
}
2023-03-16 10:57:17 +00:00
2023-05-07 18:41:14 +00:00
// the collision group sector is smaller than the one for ghost light sensors,
// so ghosts can see thru walls.
// fix this by just changing the collision group sector :P
2023-03-16 10:57:17 +00:00
var allCollisionGroups = Resources.FindObjectsOfTypeAll<SectorCollisionGroup>();
var city = allCollisionGroups.First(x => x.name == "City");
city.SetSector(_zone2Director._sector);
}
public static void CustomOnHotelDepthsGhostsIdentifiedIntruder(GhostBrain ghostBrain, QSBGhostData ghostData)
{
if (_hotelDirector._playerIdentifiedInDepths)
{
return;
}
var num = Random.Range(2f, 3f);
for (var i = 0; i < _hotelDirector._hotelDepthsGhosts.Length; i++)
{
2022-04-02 09:54:12 +00:00
if (!(_hotelDirector._hotelDepthsGhosts[i] == ghostBrain) && _hotelDirector._hotelDepthsGhosts[i].HearGhostCall(ghostData.interestedPlayer.playerLocation.localPosition, num, false))
{
num += Random.Range(2f, 3f);
}
}
}
public static void CustomOnGhostIdentifyIntruder(GhostBrain ghostBrain, QSBGhostData ghostData)
{
float num = Random.Range(2f, 3f);
for (int i = 0; i < _partyPathDirector._directedGhosts.Length; i++)
{
if (!(_partyPathDirector._directedGhosts[i] == ghostBrain))
{
bool flag = _partyPathDirector._directedGhosts[i].GetCurrentActionName() != GhostAction.Name.PartyPath || ((QSBPartyPathAction)_partyPathDirector._directedGhosts[i].GetWorldObject<QSBGhostBrain>().GetCurrentAction()).allowHearGhostCall;
float num2 = Vector3.Distance(ghostBrain.transform.position, _partyPathDirector._directedGhosts[i].transform.position);
2022-04-02 09:54:12 +00:00
if (flag && num2 < 50f && _partyPathDirector._directedGhosts[i].HearGhostCall(ghostData.interestedPlayer.playerLocation.localPosition, num, true))
{
2022-04-02 14:07:47 +00:00
_partyPathDirector._directedGhosts[i].GetWorldObject<QSBGhostBrain>().HintPlayerLocation(ghostData.interestedPlayer.player);
num += Random.Range(2f, 3f);
}
}
}
}
public static void CustomOnCityGhostsIdentifiedIntruder(GhostBrain ghostBrain, QSBGhostData ghostData)
{
if (_zone2Director._playerIdentifiedInCity)
{
return;
}
_zone2Director._playerIdentifiedInCity = true;
float num = Random.Range(2f, 3f);
for (int i = 0; i < _zone2Director._cityGhosts.Length; i++)
{
2022-04-02 09:54:12 +00:00
if (!(_zone2Director._cityGhosts[i] == ghostBrain) && _zone2Director._cityGhosts[i].HearGhostCall(ghostData.interestedPlayer.playerLocation.localPosition, num, false))
{
num += Random.Range(2f, 3f);
}
}
2022-03-18 20:49:44 +00:00
}
}