using Cysharp.Threading.Tasks; using QSB.EchoesOfTheEye.Ghosts.WorldObjects; using QSB.Utility; using QSB.WorldSync; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using UnityEngine; namespace QSB.EchoesOfTheEye.Ghosts; public class GhostManager : WorldObjectManager { public override WorldObjectScene WorldObjectScene => WorldObjectScene.SolarSystem; public override bool DlcOnly => true; private static GhostHotelDirector _hotelDirector; private static GhostPartyPathDirector _partyPathDirector; private static GhostZone2Director _zone2Director; public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct) { QSBWorldSync.Init(); QSBWorldSync.Init(typeof(PrisonerEffects)); QSBWorldSync.Init(QSBWorldSync.GetUnityObjects()); QSBWorldSync.Init(); QSBWorldSync.Init(); // to avoid disabled ghosts (TheCollector) QSBWorldSync.Init(QSBWorldSync.GetUnityObjects().Where(x => x.gameObject.activeSelf).SortDeterministic()); QSBWorldSync.Init(); _hotelDirector = QSBWorldSync.GetUnityObject(); _partyPathDirector = QSBWorldSync.GetUnityObject(); _zone2Director = QSBWorldSync.GetUnityObject(); for (int i = 0; i < _hotelDirector._hotelDepthsGhosts.Length; i++) { _hotelDirector._hotelDepthsGhosts[i].OnIdentifyIntruder -= _hotelDirector.OnHotelDepthsGhostsIdentifiedIntruder; _hotelDirector._hotelDepthsGhosts[i].GetWorldObject().OnIdentifyIntruder += CustomOnHotelDepthsGhostsIdentifiedIntruder; } for (var j = 0; j < _partyPathDirector._directedGhosts.Length; j++) { _partyPathDirector._directedGhosts[j].OnIdentifyIntruder -= _partyPathDirector.OnGhostIdentifyIntruder; _partyPathDirector._directedGhosts[j].GetWorldObject().OnIdentifyIntruder += CustomOnGhostIdentifyIntruder; } for (int i = 0; i < _zone2Director._cityGhosts.Length; i++) { _zone2Director._cityGhosts[i].OnIdentifyIntruder -= _zone2Director.OnCityGhostsIdentifiedIntruder; _zone2Director._cityGhosts[i].GetWorldObject().OnIdentifyIntruder += CustomOnCityGhostsIdentifiedIntruder; } // 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 var allCollisionGroups = Resources.FindObjectsOfTypeAll(); 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++) { 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().GetCurrentAction()).allowHearGhostCall; float num2 = Vector3.Distance(ghostBrain.transform.position, _partyPathDirector._directedGhosts[i].transform.position); if (flag && num2 < 50f && _partyPathDirector._directedGhosts[i].HearGhostCall(ghostData.interestedPlayer.playerLocation.localPosition, num, true)) { _partyPathDirector._directedGhosts[i].GetWorldObject().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++) { if (!(_zone2Director._cityGhosts[i] == ghostBrain) && _zone2Director._cityGhosts[i].HearGhostCall(ghostData.interestedPlayer.playerLocation.localPosition, num, false)) { num += Random.Range(2f, 3f); } } } }