diff --git a/NewHorizons/Builder/Props/ProjectionBuilder.cs b/NewHorizons/Builder/Props/ProjectionBuilder.cs index 4e0983f1..86dc61b8 100644 --- a/NewHorizons/Builder/Props/ProjectionBuilder.cs +++ b/NewHorizons/Builder/Props/ProjectionBuilder.cs @@ -1,10 +1,11 @@ -using NewHorizons.External.Modules; +using NewHorizons.External.Modules; using NewHorizons.Handlers; using NewHorizons.Utility; using OWML.Common; using System; using System.Collections.Generic; using UnityEngine; +using static NewHorizons.External.Modules.PropModule; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.Props { @@ -153,6 +154,47 @@ namespace NewHorizons.Builder.Props projectorObj.SetActive(true); } + + // Makes a target for a vision torch to scan + public static GameObject MakeMindSlidesTarget(GameObject planetGO, Sector sector, PropModule.ProjectionInfo info, IModBehaviour mod) + { + // spawn a trigger for the vision torch + var path = "DreamWorld_Body/Sector_DreamWorld/Sector_Underground/Sector_PrisonCell/Ghosts_PrisonCell/GhostNodeMap_PrisonCell_Lower/Prefab_IP_GhostBird_Prisoner/Ghostbird_IP_ANIM/Ghostbird_Skin_01:Ghostbird_Rig_V01:Base/Ghostbird_Skin_01:Ghostbird_Rig_V01:Root/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine01/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine02/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine03/Ghostbird_Skin_01:Ghostbird_Rig_V01:Spine04/Ghostbird_Skin_01:Ghostbird_Rig_V01:Neck01/Ghostbird_Skin_01:Ghostbird_Rig_V01:Neck02/Ghostbird_Skin_01:Ghostbird_Rig_V01:Head/PrisonerHeadDetector"; + var position = info.position; + GameObject g = DetailBuilder.MakeDetail(planetGO, sector, path, position, Vector3.zero, 1, false); + g.name = "VisionStaffDetector"; + + // The number of slides is unlimited, 15 is only for texturing the actual slide reel item. This is not a slide reel item + SlideInfo[] slides = info.slides; + var slidesCount = slides.Length; + var slideCollection = new SlideCollection(slidesCount); + + + for (int i = 0; i < slidesCount; i++) + { + var slide = new Slide(); + var slideInfo = slides[i]; + + var texture = ImageUtilities.GetTexture(mod, slideInfo.imagePath); + slide.textureOverride = ImageUtilities.Invert(texture); + + AddModules(slideInfo, ref slide); + + slideCollection.slides[i] = slide; + } + + // attatch a component to store all the data for the slides that play when a vision torch scans this target + VisionTorchTarget target = g.AddComponent(); + SlideCollectionContainer slideCollectionContainer = g.AddComponent(); + slideCollectionContainer.slideCollection = slideCollection; + target.slideCollection = new MindSlideCollection(); + target.slideCollection._slideCollectionContainer = slideCollectionContainer; + + // Idk why but it wants reveals to be comma delimited not a list + if (info.reveals != null) slideCollectionContainer._shipLogOnComplete = string.Join(",", info.reveals); + + return g; + } private static void AddModules(PropModule.SlideInfo slideInfo, ref Slide slide) { @@ -201,5 +243,11 @@ namespace NewHorizons.Builder.Props Slide.WriteModules(modules, ref slide._modulesList, ref slide._modulesData, ref slide.lengths); } + } + + public class VisionTorchTarget : MonoBehaviour + { + public MindSlideCollection slideCollection; + public SlideCollectionContainer slideCollectionContainer; } } diff --git a/NewHorizons/Handlers/TitleSceneHandler.cs b/NewHorizons/Handlers/TitleSceneHandler.cs index 9a28229b..f3566315 100644 --- a/NewHorizons/Handlers/TitleSceneHandler.cs +++ b/NewHorizons/Handlers/TitleSceneHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Builder.Body; +using NewHorizons.Builder.Body; using NewHorizons.External.Modules; using NewHorizons.Utility; using System.Collections.Generic; @@ -15,10 +15,10 @@ namespace NewHorizons.Handlers { GameObject subtitleContainer = GameObject.Find("TitleMenu/TitleCanvas/TitleLayoutGroup/Logo_EchoesOfTheEye"); - if (subtitleContainer == null) - { - Logger.LogError("No subtitle container found! Failed to load subtitles."); - return; + if (subtitleContainer == null) + { + Logger.LogError("No subtitle container found! Failed to load subtitles."); + return; } subtitleContainer.SetActive(true); diff --git a/NewHorizons/Patches/VisionTorchPatches.cs b/NewHorizons/Patches/VisionTorchPatches.cs new file mode 100644 index 00000000..b2f97763 --- /dev/null +++ b/NewHorizons/Patches/VisionTorchPatches.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HarmonyLib; +using NewHorizons.Builder.Props; +using UnityEngine; + +namespace NewHorizons.Patches +{ + + [HarmonyPatch] + public static class MindProjectorTriggerPatches + { + [HarmonyPrefix] + [HarmonyPatch(typeof(MindProjectorTrigger), nameof(MindProjectorTrigger.OnTriggerVolumeEntry))] + public static bool MindProjectorTrigger_OnTriggerVolumeEntry(MindProjectorTrigger __instance, GameObject hitObj) + { + Logger.Log("MIND PROJECTOR TRIGGER"); + + VisionTorchTarget t = hitObj.GetComponent(); + if (t != null) //(hitObj.CompareTag("PrisonerDetector")) + { + // _slideCollectionItem is actually a reference to a SlideCollectionContainer. Not a slide reel item + __instance._mindProjector._slideCollectionItem = t.slideCollectionContainer; + __instance._mindProjector._mindSlideCollection = t.slideCollection; + + Logger.Log("MIND PROJECTOR CUSTOM TRIGGER"); + __instance.OnBeamStartHitPrisoner.Invoke(); + __instance._mindProjector.Play(reset: true); + __instance._mindProjector.OnProjectionStart += new OWEvent.OWCallback(__instance.OnProjectionStart); + __instance._mindProjector.OnProjectionComplete += new OWEvent.OWCallback(__instance.OnProjectionComplete); + Locator.GetPlayerTransform().GetComponent().LockOn(hitObj.transform, Vector3.zero); + __instance._playerLockedOn = true; + return false; + } + + return true; + } + + // TOOD: OnTriggerVolumeExit + } + + [HarmonyPatch] + public static class VisionTorchItemPatches + { + // This is some dark magic + // this creates a method called base_DropItem that basically just calls OWItem.PickUpItem whenever it (VisionTorchItemPatches.base_PickUpItem) is called + [HarmonyReversePatch] + [HarmonyPatch(typeof(OWItem), nameof(OWItem.DropItem))] + private static void base_DropItem(OWItem instance, Vector3 position, Vector3 normal, Transform parent, Sector sector, IItemDropTarget customDropTarget) { } + + + // Make the vision torch droppable. In the base game you can only drop it if you're in the dream world. + [HarmonyPrefix] + [HarmonyPatch(typeof(VisionTorchItem), nameof(VisionTorchItem.DropItem))] + public static bool VisionTorchItem_DropItem(VisionTorchItem __instance, Vector3 position, Vector3 normal, Transform parent, Sector sector, IItemDropTarget customDropTarget) + { + if (!Locator.GetDreamWorldController().IsInDream()) + { + base_DropItem(__instance, position, normal, parent, sector, customDropTarget); + } + + return true; + } + } +}