using Epic.OnlineServices.Presence; using NewHorizons.Builder.Props.TranslatorText; using NewHorizons.External.Modules.WarpPad; using NewHorizons.Handlers; using NewHorizons.Utility; using NewHorizons.Utility.OWMLUtilities; using OWML.Utils; using UnityEngine; namespace NewHorizons.Builder.Props { public static class WarpPadBuilder { private static GameObject _detailedReceiverPrefab; private static GameObject _receiverPrefab; private static GameObject _transmitterPrefab; private static GameObject _platformContainerPrefab; public static void InitPrefabs() { if (_platformContainerPrefab == null) { // Put this around the platforms without details // Trifid is a Nomai ruins genius _platformContainerPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_SouthHemisphere/Sector_SouthPole/Sector_Observatory/Interactables_Observatory/Prefab_NOM_RemoteViewer/Structure_NOM_RemoteViewer") .InstantiateInactive() .DontDestroyOnLoad(); _platformContainerPrefab.transform.localScale = new Vector3(0.85f, 3f, 0.85f); } if (_detailedReceiverPrefab == null) { var thReceiverLamp = SearchUtilities.Find("TimberHearth_Body/Sector_TH/Sector_NomaiCrater/Geometry_NomaiCrater/OtherComponentsGroup/Structure_NOM_WarpReceiver_TimberHearth_Lamp"); var thReceiver = SearchUtilities.Find("TimberHearth_Body/Sector_TH/Sector_NomaiCrater/Interactables_NomaiCrater/Prefab_NOM_WarpReceiver"); _detailedReceiverPrefab = new GameObject("NomaiWarpReceiver"); var detailedReceiver = thReceiver.InstantiateInactive(); detailedReceiver.transform.parent = _detailedReceiverPrefab.transform; detailedReceiver.transform.localPosition = Vector3.zero; detailedReceiver.transform.localRotation = Quaternion.identity; var lamp = thReceiverLamp.InstantiateInactive(); lamp.transform.parent = _detailedReceiverPrefab.transform; lamp.transform.localPosition = thReceiver.transform.InverseTransformPoint(thReceiverLamp.transform.position); lamp.transform.localRotation = thReceiver.transform.InverseTransformRotation(thReceiverLamp.transform.rotation); _detailedReceiverPrefab.SetActive(false); lamp.SetActive(true); detailedReceiver.SetActive(true); _detailedReceiverPrefab.DontDestroyOnLoad(); GameObject.Destroy(_detailedReceiverPrefab.GetComponentInChildren().gameObject); } if (_receiverPrefab == null) { _receiverPrefab = SearchUtilities.Find("SunStation_Body/Sector_SunStation/Sector_WarpModule/Interactables_WarpModule/Prefab_NOM_WarpReceiver") .InstantiateInactive() .DontDestroyOnLoad(); GameObject.Destroy(_receiverPrefab.GetComponentInChildren().gameObject); var structure = _platformContainerPrefab.Instantiate(); structure.transform.parent = _receiverPrefab.transform; structure.transform.localPosition = new Vector3(0, 0.8945f, 0); structure.transform.localRotation = Quaternion.identity; structure.SetActive(true); } if (_transmitterPrefab == null) { _transmitterPrefab = SearchUtilities.Find("TowerTwin_Body/Sector_TowerTwin/Sector_Tower_SS/Interactables_Tower_SS/Tower_SS_VisibleFrom_TowerTwin/Prefab_NOM_WarpTransmitter") .InstantiateInactive() .DontDestroyOnLoad(); GameObject.Destroy(_transmitterPrefab.GetComponentInChildren().gameObject); var structure = _platformContainerPrefab.Instantiate(); structure.transform.parent = _transmitterPrefab.transform; structure.transform.localPosition = new Vector3(0, 0.8945f, 0); structure.transform.localRotation = Quaternion.identity; structure.SetActive(true); } } public static void Make(GameObject planetGO, Sector sector, NomaiWarpReceiverInfo info) { var receiverObject = GeneralPropBuilder.MakeFromPrefab(info.detailed ? _detailedReceiverPrefab : _receiverPrefab, "NomaiWarpReceiver", planetGO, sector, info); StreamingHandler.SetUpStreaming(receiverObject, sector); var receiver = receiverObject.GetComponentInChildren(); receiver._frequency = GetFrequency(info.frequency); receiver._alignmentTarget = planetGO?.transform; Locator.RegisterWarpReceiver(receiver); receiverObject.SetActive(true); if (info.computer != null) { CreateComputer(planetGO, sector, info.computer, receiver); } } public static void Make(GameObject planetGO, Sector sector, NomaiWarpTransmitterInfo info) { var transmitterObject = GeneralPropBuilder.MakeFromPrefab(_transmitterPrefab, "NomaiWarpTransmitter", planetGO, sector, info); StreamingHandler.SetUpStreaming(transmitterObject, sector); var transmitter = transmitterObject.GetComponentInChildren(); transmitter._frequency = GetFrequency(info.frequency); transmitter._alignmentWindow = info.alignmentWindow; transmitter.GetComponent().enabled = true; transmitterObject.SetActive(true); } private static void CreateComputer(GameObject planetGO, Sector sector, NomaiWarpComputerLoggerInfo computerInfo, NomaiWarpReceiver receiver) { var computerObject = GeneralPropBuilder.MakeFromPrefab(TranslatorTextBuilder.ComputerPrefab, TranslatorTextBuilder.ComputerPrefab.name, planetGO, sector, computerInfo); var computer = computerObject.GetComponentInChildren(); computer.SetSector(sector); Delay.FireOnNextUpdate(computer.ClearAllEntries); var computerLogger = computerObject.AddComponent(); computerLogger._warpReceiver = receiver; StreamingHandler.SetUpStreaming(computerObject, sector); computerObject.SetActive(true); } private static NomaiWarpPlatform.Frequency GetFrequency(string frequency) { if (!EnumUtils.TryParse(frequency, out var frequencyEnum)) { frequencyEnum = EnumUtilities.Create(frequency); } return frequencyEnum; } } }