mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
added exit pairing
This commit is contained in:
parent
b8fb35a351
commit
3b25c5cf20
@ -1,3 +1,4 @@
|
|||||||
|
using NewHorizons.Builder.Props;
|
||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -6,6 +7,7 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using static NewHorizons.External.Modules.BrambleModule;
|
using static NewHorizons.External.Modules.BrambleModule;
|
||||||
|
using Logger = NewHorizons.Utility.Logger;
|
||||||
|
|
||||||
namespace NewHorizons.Builder.Body
|
namespace NewHorizons.Builder.Body
|
||||||
{
|
{
|
||||||
@ -26,6 +28,12 @@ namespace NewHorizons.Builder.Body
|
|||||||
|
|
||||||
private static int DIMENSION_COUNTER = 0;
|
private static int DIMENSION_COUNTER = 0;
|
||||||
|
|
||||||
|
|
||||||
|
// keys are all node names that have been referenced as an exit by at least one dimension but do not (yet) exist
|
||||||
|
// values are all dimensions' warp controllers that link to a given dimension
|
||||||
|
// unpairedNodes[name of node that doesn't exist yet] => List{warp controller for dimension that exits to that node, ...}
|
||||||
|
private static Dictionary<string, List<OuterFogWarpVolume>> unpairedDimensions = new();
|
||||||
|
|
||||||
public static GameObject Make(NewHorizonsBody body)
|
public static GameObject Make(NewHorizonsBody body)
|
||||||
{
|
{
|
||||||
var config = body.Config.Bramble.dimension;
|
var config = body.Config.Bramble.dimension;
|
||||||
@ -69,10 +77,41 @@ namespace NewHorizons.Builder.Body
|
|||||||
var outerFogWarpVolume = exitWarps.GetComponent<OuterFogWarpVolume>();
|
var outerFogWarpVolume = exitWarps.GetComponent<OuterFogWarpVolume>();
|
||||||
outerFogWarpVolume._senderWarps.Clear();
|
outerFogWarpVolume._senderWarps.Clear();
|
||||||
outerFogWarpVolume._linkedInnerWarpVolume = null;
|
outerFogWarpVolume._linkedInnerWarpVolume = null;
|
||||||
|
outerFogWarpVolume._name = OuterFogWarpVolume.Name.None;
|
||||||
|
//outerFogWarpVolume._sector = dimensionSector.GetComponent<Sector>();
|
||||||
|
//outerFogWarpVolume.Awake(); // I can't spawn this game object disabled, but Awake needs to run after _sector is set. That means I need to call Awake myself
|
||||||
|
|
||||||
// TODO MAYBE: set "exitWarps/ExitPoint", "exitWarp/ExitPoint (1)", ... "exitWarp/ExitPoint (5)"
|
// TODO if I need to: set "exitWarps/ExitPoint", "exitWarp/ExitPoint (1)", ... "exitWarp/ExitPoint (5)"
|
||||||
|
|
||||||
|
PairExit(config.linksTo, outerFogWarpVolume);
|
||||||
|
|
||||||
return dimension;
|
return dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void PairExit(string exitName, OuterFogWarpVolume warpController)
|
||||||
|
{
|
||||||
|
if (!BrambleNodeBuilder.namedNodes.ContainsKey(exitName))
|
||||||
|
{
|
||||||
|
if (!unpairedDimensions.ContainsKey(exitName)) unpairedDimensions[exitName] = new();
|
||||||
|
unpairedDimensions[exitName].Add(warpController);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
warpController._linkedInnerWarpVolume = BrambleNodeBuilder.namedNodes[exitName];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void FinishPairingDimensionsForExitNode(string nodeName)
|
||||||
|
{
|
||||||
|
if (!unpairedDimensions.ContainsKey(nodeName)) return;
|
||||||
|
|
||||||
|
var warpControllers = unpairedDimensions[nodeName].ToList();
|
||||||
|
foreach (var dimensionWarpController in warpControllers)
|
||||||
|
{
|
||||||
|
PairExit(nodeName, dimensionWarpController);
|
||||||
|
}
|
||||||
|
|
||||||
|
unpairedDimensions.Remove(nodeName);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using NewHorizons.Builder.Body;
|
||||||
using NewHorizons.Utility;
|
using NewHorizons.Utility;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -17,6 +18,45 @@ namespace NewHorizons.Builder.Props
|
|||||||
public static class FogDebuggingPatches
|
public static class FogDebuggingPatches
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
[HarmonyPrefix]
|
||||||
|
[HarmonyPatch(typeof(FogWarpVolume), nameof(FogWarpVolume.WarpDetector))]
|
||||||
|
public static bool FogWarpVolume_WarpDetector(FogWarpVolume __instance, FogWarpDetector detector, FogWarpVolume linkedWarpVolume)
|
||||||
|
{
|
||||||
|
bool flag = detector.CompareName(FogWarpDetector.Name.Player);
|
||||||
|
bool flag2 = detector.CompareName(FogWarpDetector.Name.Ship);
|
||||||
|
if (!flag || !PlayerState.IsInsideShip())
|
||||||
|
{
|
||||||
|
OWRigidbody oWRigidbody = detector.GetOWRigidbody();
|
||||||
|
if (flag && PlayerState.IsAttached())
|
||||||
|
{
|
||||||
|
oWRigidbody = detector.GetOWRigidbody().transform.parent.GetComponentInParent<OWRigidbody>();
|
||||||
|
MonoBehaviour.print("body to warp: " + oWRigidbody.name);
|
||||||
|
}
|
||||||
|
Vector3 localRelVelocity = __instance.transform.InverseTransformDirection(oWRigidbody.GetVelocity() - __instance._attachedBody.GetVelocity());
|
||||||
|
Vector3 localPos = __instance.transform.InverseTransformPoint(oWRigidbody.transform.position);
|
||||||
|
Quaternion localRot = Quaternion.Inverse(__instance.transform.rotation) * oWRigidbody.transform.rotation;
|
||||||
|
if (flag2 && PlayerState.IsInsideShip())
|
||||||
|
{
|
||||||
|
__instance._sector.GetTriggerVolume().RemoveObjectFromVolume(Locator.GetPlayerDetector());
|
||||||
|
__instance._sector.GetTriggerVolume().RemoveObjectFromVolume(Locator.GetPlayerCameraDetector());
|
||||||
|
}
|
||||||
|
if (flag || (flag2 && PlayerState.IsInsideShip()))
|
||||||
|
{
|
||||||
|
GlobalMessenger.FireEvent("PlayerFogWarp");
|
||||||
|
}
|
||||||
|
__instance._sector.GetTriggerVolume().RemoveObjectFromVolume(detector.gameObject);
|
||||||
|
linkedWarpVolume.ReceiveWarpedDetector(detector, localRelVelocity, localPos, localRot);
|
||||||
|
//if (__instance.OnWarpDetector != null)
|
||||||
|
//{
|
||||||
|
// __instance.OnWarpDetector(detector);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
[HarmonyPatch(typeof(FogWarpVolume), nameof(FogWarpVolume.OnOccupantEnterSector))]
|
[HarmonyPatch(typeof(FogWarpVolume), nameof(FogWarpVolume.OnOccupantEnterSector))]
|
||||||
private static bool FogWarpVolume_OnOccupantEnterSector(FogWarpVolume __instance, SectorDetector detector)
|
private static bool FogWarpVolume_OnOccupantEnterSector(FogWarpVolume __instance, SectorDetector detector)
|
||||||
@ -79,14 +119,10 @@ namespace NewHorizons.Builder.Props
|
|||||||
|
|
||||||
public static Dictionary<string, InnerFogWarpVolume> namedNodes = new();
|
public static Dictionary<string, InnerFogWarpVolume> namedNodes = new();
|
||||||
|
|
||||||
public static void FinishPairingNodesForDimension(string dimensionName, AstroObject dimensionAO = null, BrambleDimensionInfo dimensionInfo = null)
|
public static void FinishPairingNodesForDimension(string dimensionName, AstroObject dimensionAO = null)
|
||||||
{
|
{
|
||||||
Logger.Log("Pairing for " + dimensionName);
|
if (!unpairedNodes.ContainsKey(dimensionName)) return;
|
||||||
// TODO: I might need to call this on Make: InnerFogWarpVolume.OnOccupantEnterSector
|
|
||||||
|
|
||||||
// pair node->dimension (entrances)
|
|
||||||
if (unpairedNodes.ContainsKey(dimensionName))
|
|
||||||
{
|
|
||||||
foreach (var nodeWarpController in unpairedNodes[dimensionName])
|
foreach (var nodeWarpController in unpairedNodes[dimensionName])
|
||||||
{
|
{
|
||||||
Pair(nodeWarpController, dimensionName, dimensionAO);
|
Pair(nodeWarpController, dimensionName, dimensionAO);
|
||||||
@ -95,14 +131,6 @@ namespace NewHorizons.Builder.Props
|
|||||||
unpairedNodes.Remove(dimensionName);
|
unpairedNodes.Remove(dimensionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// pair dimension->node (exit)
|
|
||||||
if (dimensionInfo != null && dimensionAO != null && namedNodes.ContainsKey(dimensionInfo.linksTo))
|
|
||||||
{
|
|
||||||
var dimensionWarpController = dimensionAO.GetComponentInChildren<OuterFogWarpVolume>();
|
|
||||||
dimensionWarpController._linkedInnerWarpVolume = namedNodes[dimensionInfo.linksTo];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RecordUnpairedNode(InnerFogWarpVolume warpVolume, string linksTo)
|
private static void RecordUnpairedNode(InnerFogWarpVolume warpVolume, string linksTo)
|
||||||
{
|
{
|
||||||
if (!unpairedNodes.ContainsKey(linksTo)) unpairedNodes[linksTo] = new();
|
if (!unpairedNodes.ContainsKey(linksTo)) unpairedNodes[linksTo] = new();
|
||||||
@ -131,7 +159,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
if (destination == null) return false;
|
if (destination == null) return false;
|
||||||
|
|
||||||
nodeWarp._linkedOuterWarpVolume = destination;
|
nodeWarp._linkedOuterWarpVolume = destination;
|
||||||
destination._senderWarps.Add(nodeWarp);
|
destination.RegisterSenderWarp(nodeWarp);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,6 +235,11 @@ namespace NewHorizons.Builder.Props
|
|||||||
// TODO: support adding signals to these nodes
|
// TODO: support adding signals to these nodes
|
||||||
//
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Cleanup for dimension exits
|
||||||
|
//
|
||||||
|
if (config.name != null) BrambleDimensionBuilder.FinishPairingDimensionsForExitNode(config.name);
|
||||||
|
|
||||||
// Done!
|
// Done!
|
||||||
return brambleNode;
|
return brambleNode;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user