feat: added patch to make vision torches droppable, patch to allow vision torches to scan other targets besides the prisoner, added untested code to handle creating new vision torch targets

This commit is contained in:
FreezeDriedMangoes 2022-05-23 10:06:42 -04:00
parent ed49e8b6af
commit 22a386e50a
3 changed files with 122 additions and 6 deletions

View File

@ -1,10 +1,11 @@
using NewHorizons.External.Modules; using NewHorizons.External.Modules;
using NewHorizons.Handlers; using NewHorizons.Handlers;
using NewHorizons.Utility; using NewHorizons.Utility;
using OWML.Common; using OWML.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using static NewHorizons.External.Modules.PropModule;
using Logger = NewHorizons.Utility.Logger; using Logger = NewHorizons.Utility.Logger;
namespace NewHorizons.Builder.Props namespace NewHorizons.Builder.Props
{ {
@ -153,6 +154,47 @@ namespace NewHorizons.Builder.Props
projectorObj.SetActive(true); 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<VisionTorchTarget>();
SlideCollectionContainer slideCollectionContainer = g.AddComponent<SlideCollectionContainer>();
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) 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); Slide.WriteModules(modules, ref slide._modulesList, ref slide._modulesData, ref slide.lengths);
} }
}
public class VisionTorchTarget : MonoBehaviour
{
public MindSlideCollection slideCollection;
public SlideCollectionContainer slideCollectionContainer;
} }
} }

View File

@ -1,4 +1,4 @@
using NewHorizons.Builder.Body; using NewHorizons.Builder.Body;
using NewHorizons.External.Modules; using NewHorizons.External.Modules;
using NewHorizons.Utility; using NewHorizons.Utility;
using System.Collections.Generic; using System.Collections.Generic;
@ -15,10 +15,10 @@ namespace NewHorizons.Handlers
{ {
GameObject subtitleContainer = GameObject.Find("TitleMenu/TitleCanvas/TitleLayoutGroup/Logo_EchoesOfTheEye"); GameObject subtitleContainer = GameObject.Find("TitleMenu/TitleCanvas/TitleLayoutGroup/Logo_EchoesOfTheEye");
if (subtitleContainer == null) if (subtitleContainer == null)
{ {
Logger.LogError("No subtitle container found! Failed to load subtitles."); Logger.LogError("No subtitle container found! Failed to load subtitles.");
return; return;
} }
subtitleContainer.SetActive(true); subtitleContainer.SetActive(true);

View File

@ -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<VisionTorchTarget>();
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<PlayerLockOnTargeting>().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;
}
}
}