From 8d04dc23b47826e186d625db40d2addf2e8ed6cc Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 31 Aug 2022 15:19:25 -0400 Subject: [PATCH 01/22] Make a base volume info --- NewHorizons/External/Modules/VolumesModule.cs | 62 ++++++------------- 1 file changed, 18 insertions(+), 44 deletions(-) diff --git a/NewHorizons/External/Modules/VolumesModule.cs b/NewHorizons/External/Modules/VolumesModule.cs index 43059fbf..e9659f2a 100644 --- a/NewHorizons/External/Modules/VolumesModule.cs +++ b/NewHorizons/External/Modules/VolumesModule.cs @@ -35,7 +35,21 @@ namespace NewHorizons.External.Modules public RevealVolumeInfo[] revealVolumes; [JsonObject] - public class RevealVolumeInfo + public class VolumeInfo + { + /// + /// The location of this volume. Optional (will default to 0,0,0). + /// + public MVector3 position; + + /// + /// The radius of this volume. + /// + public float radius = 1f; + } + + [JsonObject] + public class RevealVolumeInfo : VolumeInfo { [JsonConverter(typeof(StringEnumConverter))] public enum RevealVolumeType @@ -57,16 +71,6 @@ namespace NewHorizons.External.Modules /// public float maxDistance = -1f; // Snapshot & Observe Only - /// - /// The position to place this volume at - /// - public MVector3 position; - - /// - /// The radius of this reveal volume - /// - public float radius = 1f; - /// /// What needs to be done to the volume to unlock the facts /// @@ -84,18 +88,8 @@ namespace NewHorizons.External.Modules } [JsonObject] - public class AudioVolumeInfo + public class AudioVolumeInfo : VolumeInfo { - /// - /// The location of this audio volume. Optional (will default to 0,0,0). - /// - public MVector3 position; - - /// - /// The radius of this audio volume - /// - public float radius; - /// /// The audio to use. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list. /// @@ -113,23 +107,13 @@ namespace NewHorizons.External.Modules } [JsonObject] - public class NotificationVolumeInfo + public class NotificationVolumeInfo : VolumeInfo { /// /// What the notification will show for. /// [DefaultValue("all")] public NotificationTarget target = NotificationTarget.All; - /// - /// The location of this notification volume. Optional (will default to 0,0,0). - /// - public MVector3 position; - - /// - /// The radius of this notification volume. - /// - public float radius; - /// /// The notification that will play when you enter this volume. /// @@ -165,18 +149,8 @@ namespace NewHorizons.External.Modules } [JsonObject] - public class HazardVolumeInfo + public class HazardVolumeInfo : VolumeInfo { - /// - /// The location of this hazard volume. Optional (will default to 0,0,0). - /// - public MVector3 position; - - /// - /// The radius of this hazard volume. - /// - public float radius; - /// /// The type of hazard for this volume. /// From 6e843ee09b5eef6f55647cf82394bf67f1c9fd6c Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 31 Aug 2022 15:26:05 -0400 Subject: [PATCH 02/22] Add map restriction volume --- .../Volumes/MapRestrictionVolumeBuilder.cs | 35 +++++++++++++++ .../Builder/Volumes/VolumesBuildManager.cs | 7 +++ .../Components/MapRestrictionVolume.cs | 43 +++++++++++++++++++ NewHorizons/External/Modules/VolumesModule.cs | 5 +++ 4 files changed, 90 insertions(+) create mode 100644 NewHorizons/Builder/Volumes/MapRestrictionVolumeBuilder.cs create mode 100644 NewHorizons/Components/MapRestrictionVolume.cs diff --git a/NewHorizons/Builder/Volumes/MapRestrictionVolumeBuilder.cs b/NewHorizons/Builder/Volumes/MapRestrictionVolumeBuilder.cs new file mode 100644 index 00000000..53e5944f --- /dev/null +++ b/NewHorizons/Builder/Volumes/MapRestrictionVolumeBuilder.cs @@ -0,0 +1,35 @@ +using NewHorizons.Components; +using NewHorizons.External.Modules; +using OWML.Common; +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +namespace NewHorizons.Builder.Volumes +{ + public static class MapRestrictionVolumeBuilder + { + public static MapRestrictionVolume Make(GameObject planetGO, Sector sector, VolumesModule.VolumeInfo info) + { + var go = new GameObject("MapRestrictionVolume"); + go.SetActive(false); + + go.transform.parent = sector?.transform ?? planetGO.transform; + go.transform.position = planetGO.transform.TransformPoint(info.position != null ? (Vector3)info.position : Vector3.zero); + go.layer = LayerMask.NameToLayer("BasicEffectVolume"); + + var shape = go.AddComponent(); + shape.radius = info.radius; + + var owTriggerVolume = go.AddComponent(); + owTriggerVolume._shape = shape; + + var mapRestrictionVolume = go.AddComponent(); + + go.SetActive(true); + + return mapRestrictionVolume; + } + } +} diff --git a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs index f7a664b9..343ccc0c 100644 --- a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs +++ b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs @@ -49,6 +49,13 @@ namespace NewHorizons.Builder.Volumes HazardVolumeBuilder.Make(go, sector, planetBody, hazardVolume, mod); } } + if (config.Volumes.mapRestrictionVolumes != null) + { + foreach (var mapRestrictionVolume in config.Volumes.mapRestrictionVolumes) + { + MapRestrictionVolumeBuilder.Make(go, sector, mapRestrictionVolume); + } + } } } } diff --git a/NewHorizons/Components/MapRestrictionVolume.cs b/NewHorizons/Components/MapRestrictionVolume.cs new file mode 100644 index 00000000..43ebd8d3 --- /dev/null +++ b/NewHorizons/Components/MapRestrictionVolume.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +namespace NewHorizons.Components +{ + [RequireComponent(typeof(OWTriggerVolume))] + public class MapRestrictionVolume : MonoBehaviour + { + private OWTriggerVolume _triggerVolume; + + public void Awake() + { + _triggerVolume = this.GetRequiredComponent(); + _triggerVolume.OnEntry += OnTriggerVolumeEntry; + _triggerVolume.OnExit += OnTriggerVolumeExit; + } + + public void OnDestroy() + { + if (_triggerVolume == null) return; + _triggerVolume.OnEntry -= OnTriggerVolumeEntry; + _triggerVolume.OnExit -= OnTriggerVolumeExit; + } + + public void OnTriggerVolumeEntry(GameObject hitObj) + { + if (hitObj.CompareTag("PlayerDetector")) + { + Locator.GetMapController()?.OnPlayerEnterMapRestriction(); + } + } + + public void OnTriggerVolumeExit(GameObject hitObj) + { + if (hitObj.CompareTag("PlayerDetector")) + { + Locator.GetMapController()?.OnPlayerExitMapRestriction(); + } + } + } +} diff --git a/NewHorizons/External/Modules/VolumesModule.cs b/NewHorizons/External/Modules/VolumesModule.cs index e9659f2a..0dd9e0fb 100644 --- a/NewHorizons/External/Modules/VolumesModule.cs +++ b/NewHorizons/External/Modules/VolumesModule.cs @@ -24,6 +24,11 @@ namespace NewHorizons.External.Modules /// public HazardVolumeInfo[] hazardVolumes; + /// + /// Add map restriction volumes to this planet + /// + public VolumeInfo[] mapRestrictionVolumes; + /// /// Add notification volumes to this planet /// From 55640c157f88d9a3f98b34c4f6ca12449e6b2e82 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 31 Aug 2022 19:28:30 +0000 Subject: [PATCH 03/22] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 64 +++++++++++++++++++--------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 85fabcd8..c095374d 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -2400,6 +2400,13 @@ "$ref": "#/definitions/HazardVolumeInfo" } }, + "mapRestrictionVolumes": { + "type": "array", + "description": "Add map restriction volumes to this planet", + "items": { + "$ref": "#/definitions/VolumeInfo" + } + }, "notificationVolumes": { "type": "array", "description": "Add notification volumes to this planet", @@ -2421,12 +2428,12 @@ "additionalProperties": false, "properties": { "position": { - "description": "The location of this audio volume. Optional (will default to 0,0,0).", + "description": "The location of this volume. Optional (will default to 0,0,0).", "$ref": "#/definitions/MVector3" }, "radius": { "type": "number", - "description": "The radius of this audio volume", + "description": "The radius of this volume.", "format": "float" }, "audio": { @@ -2490,12 +2497,12 @@ "additionalProperties": false, "properties": { "position": { - "description": "The location of this hazard volume. Optional (will default to 0,0,0).", + "description": "The location of this volume. Optional (will default to 0,0,0).", "$ref": "#/definitions/MVector3" }, "radius": { "type": "number", - "description": "The radius of this hazard volume.", + "description": "The radius of this volume.", "format": "float" }, "type": { @@ -2559,23 +2566,38 @@ "electrical" ] }, - "NotificationVolumeInfo": { + "VolumeInfo": { "type": "object", "additionalProperties": false, "properties": { - "target": { - "description": "What the notification will show for.", - "default": "all", - "$ref": "#/definitions/NotificationTarget" - }, "position": { - "description": "The location of this notification volume. Optional (will default to 0,0,0).", + "description": "The location of this volume. Optional (will default to 0,0,0).", "$ref": "#/definitions/MVector3" }, "radius": { "type": "number", - "description": "The radius of this notification volume.", + "description": "The radius of this volume.", "format": "float" + } + } + }, + "NotificationVolumeInfo": { + "type": "object", + "additionalProperties": false, + "properties": { + "position": { + "description": "The location of this volume. Optional (will default to 0,0,0).", + "$ref": "#/definitions/MVector3" + }, + "radius": { + "type": "number", + "description": "The radius of this volume.", + "format": "float" + }, + "target": { + "description": "What the notification will show for.", + "default": "all", + "$ref": "#/definitions/NotificationTarget" }, "entryNotification": { "description": "The notification that will play when you enter this volume.", @@ -2621,6 +2643,15 @@ "type": "object", "additionalProperties": false, "properties": { + "position": { + "description": "The location of this volume. Optional (will default to 0,0,0).", + "$ref": "#/definitions/MVector3" + }, + "radius": { + "type": "number", + "description": "The radius of this volume.", + "format": "float" + }, "maxAngle": { "type": "number", "description": "The max view angle (in degrees) the player can see the volume with to unlock the fact (`observe` only)", @@ -2631,15 +2662,6 @@ "description": "The max distance the user can be away from the volume to reveal the fact (`snapshot` and `observe` only)", "format": "float" }, - "position": { - "description": "The position to place this volume at", - "$ref": "#/definitions/MVector3" - }, - "radius": { - "type": "number", - "description": "The radius of this reveal volume", - "format": "float" - }, "revealOn": { "description": "What needs to be done to the volume to unlock the facts", "default": "enter", From 2352d5f2d89980e6e8ecd33a41bdc6c4de10de64 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 31 Aug 2022 15:51:11 -0400 Subject: [PATCH 04/22] Add base volume abstract class --- NewHorizons/Components/BaseVolume.cs | 28 +++++++++++++++++++ .../Components/MapRestrictionVolume.cs | 23 ++------------- NewHorizons/Components/NotificationVolume.cs | 22 ++------------- 3 files changed, 34 insertions(+), 39 deletions(-) create mode 100644 NewHorizons/Components/BaseVolume.cs diff --git a/NewHorizons/Components/BaseVolume.cs b/NewHorizons/Components/BaseVolume.cs new file mode 100644 index 00000000..6ddccada --- /dev/null +++ b/NewHorizons/Components/BaseVolume.cs @@ -0,0 +1,28 @@ +using UnityEngine; + +namespace NewHorizons.Components +{ + [RequireComponent(typeof(OWTriggerVolume))] + public abstract class BaseVolume : MonoBehaviour + { + private OWTriggerVolume _triggerVolume; + + public virtual void Awake() + { + _triggerVolume = this.GetRequiredComponent(); + _triggerVolume.OnEntry += OnTriggerVolumeEntry; + _triggerVolume.OnExit += OnTriggerVolumeExit; + } + + public virtual void OnDestroy() + { + if (_triggerVolume == null) return; + _triggerVolume.OnEntry -= OnTriggerVolumeEntry; + _triggerVolume.OnExit -= OnTriggerVolumeExit; + } + + public abstract void OnTriggerVolumeEntry(GameObject hitObj); + + public abstract void OnTriggerVolumeExit(GameObject hitObj); + } +} diff --git a/NewHorizons/Components/MapRestrictionVolume.cs b/NewHorizons/Components/MapRestrictionVolume.cs index 43ebd8d3..04442840 100644 --- a/NewHorizons/Components/MapRestrictionVolume.cs +++ b/NewHorizons/Components/MapRestrictionVolume.cs @@ -5,26 +5,9 @@ using UnityEngine; namespace NewHorizons.Components { - [RequireComponent(typeof(OWTriggerVolume))] - public class MapRestrictionVolume : MonoBehaviour + public class MapRestrictionVolume : BaseVolume { - private OWTriggerVolume _triggerVolume; - - public void Awake() - { - _triggerVolume = this.GetRequiredComponent(); - _triggerVolume.OnEntry += OnTriggerVolumeEntry; - _triggerVolume.OnExit += OnTriggerVolumeExit; - } - - public void OnDestroy() - { - if (_triggerVolume == null) return; - _triggerVolume.OnEntry -= OnTriggerVolumeEntry; - _triggerVolume.OnExit -= OnTriggerVolumeExit; - } - - public void OnTriggerVolumeEntry(GameObject hitObj) + public override void OnTriggerVolumeEntry(GameObject hitObj) { if (hitObj.CompareTag("PlayerDetector")) { @@ -32,7 +15,7 @@ namespace NewHorizons.Components } } - public void OnTriggerVolumeExit(GameObject hitObj) + public override void OnTriggerVolumeExit(GameObject hitObj) { if (hitObj.CompareTag("PlayerDetector")) { diff --git a/NewHorizons/Components/NotificationVolume.cs b/NewHorizons/Components/NotificationVolume.cs index 2dc81ed1..6fe7b746 100644 --- a/NewHorizons/Components/NotificationVolume.cs +++ b/NewHorizons/Components/NotificationVolume.cs @@ -7,29 +7,13 @@ using UnityEngine; namespace NewHorizons.Components { - [RequireComponent(typeof(OWTriggerVolume))] - public class NotificationVolume : MonoBehaviour + public class NotificationVolume : BaseVolume { private NotificationTarget _target = NotificationTarget.All; private bool _pin = false; - private OWTriggerVolume _triggerVolume; private NotificationData _entryNotification; private NotificationData _exitNotification; - public void Awake() - { - _triggerVolume = this.GetRequiredComponent(); - _triggerVolume.OnEntry += OnTriggerVolumeEntry; - _triggerVolume.OnExit += OnTriggerVolumeExit; - } - - public void OnDestroy() - { - if (_triggerVolume == null) return; - _triggerVolume.OnEntry -= OnTriggerVolumeEntry; - _triggerVolume.OnExit -= OnTriggerVolumeExit; - } - public void SetPinned(bool pin) => _pin = pin; public void SetTarget(External.Modules.VolumesModule.NotificationVolumeInfo.NotificationTarget target) => SetTarget(EnumUtils.Parse(target.ToString(), NotificationTarget.All)); @@ -46,7 +30,7 @@ namespace NewHorizons.Components _exitNotification = new NotificationData(_target, TranslationHandler.GetTranslation(displayMessage, TranslationHandler.TextType.UI), duration); } - public void OnTriggerVolumeEntry(GameObject hitObj) + public override void OnTriggerVolumeEntry(GameObject hitObj) { if (_target == NotificationTarget.All) { @@ -71,7 +55,7 @@ namespace NewHorizons.Components } } - public void OnTriggerVolumeExit(GameObject hitObj) + public override void OnTriggerVolumeExit(GameObject hitObj) { if (_target == NotificationTarget.All) { From a1e39303e40f1f652afad9790b7f8fbed084f228 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 31 Aug 2022 15:57:24 -0400 Subject: [PATCH 05/22] Add base volume builder --- ...estrictionVolumeBuilder.cs => VolumeBuilder.cs} | 14 +++++--------- NewHorizons/Builder/Volumes/VolumesBuildManager.cs | 3 ++- 2 files changed, 7 insertions(+), 10 deletions(-) rename NewHorizons/Builder/Volumes/{MapRestrictionVolumeBuilder.cs => VolumeBuilder.cs} (62%) diff --git a/NewHorizons/Builder/Volumes/MapRestrictionVolumeBuilder.cs b/NewHorizons/Builder/Volumes/VolumeBuilder.cs similarity index 62% rename from NewHorizons/Builder/Volumes/MapRestrictionVolumeBuilder.cs rename to NewHorizons/Builder/Volumes/VolumeBuilder.cs index 53e5944f..c8fc563f 100644 --- a/NewHorizons/Builder/Volumes/MapRestrictionVolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/VolumeBuilder.cs @@ -1,18 +1,14 @@ using NewHorizons.Components; using NewHorizons.External.Modules; -using OWML.Common; -using System; -using System.Collections.Generic; -using System.Linq; using UnityEngine; namespace NewHorizons.Builder.Volumes { - public static class MapRestrictionVolumeBuilder + public static class VolumeBuilder { - public static MapRestrictionVolume Make(GameObject planetGO, Sector sector, VolumesModule.VolumeInfo info) + public static TVolume Make(GameObject planetGO, Sector sector, VolumesModule.VolumeInfo info) where TVolume : BaseVolume { - var go = new GameObject("MapRestrictionVolume"); + var go = new GameObject(typeof(TVolume).Name); go.SetActive(false); go.transform.parent = sector?.transform ?? planetGO.transform; @@ -25,11 +21,11 @@ namespace NewHorizons.Builder.Volumes var owTriggerVolume = go.AddComponent(); owTriggerVolume._shape = shape; - var mapRestrictionVolume = go.AddComponent(); + var volume = go.AddComponent(); go.SetActive(true); - return mapRestrictionVolume; + return volume; } } } diff --git a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs index 343ccc0c..f4878c80 100644 --- a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs +++ b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs @@ -1,6 +1,7 @@ using NewHorizons.Builder.Body; using NewHorizons.Builder.ShipLog; using NewHorizons.Builder.Volumes; +using NewHorizons.Components; using NewHorizons.External.Configs; using OWML.Common; using System; @@ -53,7 +54,7 @@ namespace NewHorizons.Builder.Volumes { foreach (var mapRestrictionVolume in config.Volumes.mapRestrictionVolumes) { - MapRestrictionVolumeBuilder.Make(go, sector, mapRestrictionVolume); + VolumeBuilder.Make(go, sector, mapRestrictionVolume); } } } From 26c78e59d30361f4b2359765c52aacad93dfb42d Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 31 Aug 2022 15:58:41 -0400 Subject: [PATCH 06/22] Add interference volume --- .../Builder/Volumes/VolumesBuildManager.cs | 7 ++++ NewHorizons/Components/InterferenceVolume.cs | 37 +++++++++++++++++++ NewHorizons/External/Modules/VolumesModule.cs | 5 +++ NewHorizons/Handlers/InterferenceHandler.cs | 23 ++++++++++++ NewHorizons/Patches/HUDPatches.cs | 3 +- 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 NewHorizons/Components/InterferenceVolume.cs create mode 100644 NewHorizons/Handlers/InterferenceHandler.cs diff --git a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs index f4878c80..bc88df33 100644 --- a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs +++ b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs @@ -57,6 +57,13 @@ namespace NewHorizons.Builder.Volumes VolumeBuilder.Make(go, sector, mapRestrictionVolume); } } + if (config.Volumes.interferenceVolumes != null) + { + foreach (var interferenceVolume in config.Volumes.interferenceVolumes) + { + VolumeBuilder.Make(go, sector, interferenceVolume); + } + } } } } diff --git a/NewHorizons/Components/InterferenceVolume.cs b/NewHorizons/Components/InterferenceVolume.cs new file mode 100644 index 00000000..7daa0238 --- /dev/null +++ b/NewHorizons/Components/InterferenceVolume.cs @@ -0,0 +1,37 @@ +using NewHorizons.Handlers; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Components +{ + public class InterferenceVolume : BaseVolume + { + public override void OnTriggerVolumeEntry(GameObject hitObj) + { + if (hitObj.CompareTag("PlayerDetector")) + { + InterferenceHandler.OnPlayerEnterInterferenceVolume(); + } + else if (hitObj.CompareTag("ProbeDetector")) + { + InterferenceHandler.OnProbeEnterInterferenceVolume(); + } + } + + public override void OnTriggerVolumeExit(GameObject hitObj) + { + if (hitObj.CompareTag("PlayerDetector")) + { + InterferenceHandler.OnPlayerExitInterferenceVolume(); + } + else if (hitObj.CompareTag("ProbeDetector")) + { + InterferenceHandler.OnProbeExitInterferenceVolume(); + } + } + } +} diff --git a/NewHorizons/External/Modules/VolumesModule.cs b/NewHorizons/External/Modules/VolumesModule.cs index 0dd9e0fb..7bbf651c 100644 --- a/NewHorizons/External/Modules/VolumesModule.cs +++ b/NewHorizons/External/Modules/VolumesModule.cs @@ -24,6 +24,11 @@ namespace NewHorizons.External.Modules /// public HazardVolumeInfo[] hazardVolumes; + /// + /// Add interference volumes to this planet + /// + public VolumeInfo[] interferenceVolumes; + /// /// Add map restriction volumes to this planet /// diff --git a/NewHorizons/Handlers/InterferenceHandler.cs b/NewHorizons/Handlers/InterferenceHandler.cs new file mode 100644 index 00000000..cc0d5a90 --- /dev/null +++ b/NewHorizons/Handlers/InterferenceHandler.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.Handlers +{ + public static class InterferenceHandler + { + public static bool _playerInterference; + public static bool _probeInterference; + + public static bool PlayerHasInterference() => _playerInterference; + public static bool ProbeHasInterference() => _probeInterference; + + public static void OnPlayerEnterInterferenceVolume() => _playerInterference = true; + public static void OnPlayerExitInterferenceVolume() => _playerInterference = false; + + public static void OnProbeEnterInterferenceVolume() => _probeInterference = true; + public static void OnProbeExitInterferenceVolume() => _probeInterference = false; + } +} diff --git a/NewHorizons/Patches/HUDPatches.cs b/NewHorizons/Patches/HUDPatches.cs index bbb0061a..adcde38e 100644 --- a/NewHorizons/Patches/HUDPatches.cs +++ b/NewHorizons/Patches/HUDPatches.cs @@ -1,4 +1,5 @@ using HarmonyLib; +using NewHorizons.Handlers; namespace NewHorizons.Patches { @@ -57,7 +58,7 @@ namespace NewHorizons.Patches [HarmonyPatch(typeof(ProbeCamera), nameof(ProbeCamera.HasInterference))] public static void ProbeCamera_HasInterference(ProbeCamera __instance, ref bool __result) { - __result = __result || Components.CloakSectorController.isPlayerInside != Components.CloakSectorController.isProbeInside; + __result = __result || (__instance._id != ProbeCamera.ID.PreLaunch && (Components.CloakSectorController.isPlayerInside != Components.CloakSectorController.isProbeInside || InterferenceHandler.PlayerHasInterference() != InterferenceHandler.ProbeHasInterference())); } } } From af935639d88e38ec88bedbaa790ba0154e85f43a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 31 Aug 2022 20:01:11 +0000 Subject: [PATCH 07/22] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index c095374d..a717caa9 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -2400,6 +2400,13 @@ "$ref": "#/definitions/HazardVolumeInfo" } }, + "interferenceVolumes": { + "type": "array", + "description": "Add interference volumes to this planet", + "items": { + "$ref": "#/definitions/VolumeInfo" + } + }, "mapRestrictionVolumes": { "type": "array", "description": "Add map restriction volumes to this planet", From 3f6b6fab99e55f7b8b4bd1dba94f013231cf7474 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 31 Aug 2022 16:15:16 -0400 Subject: [PATCH 08/22] Add reverb volumes. --- NewHorizons/Builder/Volumes/VolumeBuilder.cs | 2 +- NewHorizons/Builder/Volumes/VolumesBuildManager.cs | 7 +++++++ NewHorizons/External/Modules/VolumesModule.cs | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Volumes/VolumeBuilder.cs b/NewHorizons/Builder/Volumes/VolumeBuilder.cs index c8fc563f..0cf3ebe8 100644 --- a/NewHorizons/Builder/Volumes/VolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/VolumeBuilder.cs @@ -6,7 +6,7 @@ namespace NewHorizons.Builder.Volumes { public static class VolumeBuilder { - public static TVolume Make(GameObject planetGO, Sector sector, VolumesModule.VolumeInfo info) where TVolume : BaseVolume + public static TVolume Make(GameObject planetGO, Sector sector, VolumesModule.VolumeInfo info) where TVolume : MonoBehaviour { var go = new GameObject(typeof(TVolume).Name); go.SetActive(false); diff --git a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs index bc88df33..c5ec9d90 100644 --- a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs +++ b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs @@ -64,6 +64,13 @@ namespace NewHorizons.Builder.Volumes VolumeBuilder.Make(go, sector, interferenceVolume); } } + if (config.Volumes.reverbVolumes != null) + { + foreach (var reverbVolume in config.Volumes.reverbVolumes) + { + VolumeBuilder.Make(go, sector, reverbVolume); + } + } } } } diff --git a/NewHorizons/External/Modules/VolumesModule.cs b/NewHorizons/External/Modules/VolumesModule.cs index 7bbf651c..bbd3b798 100644 --- a/NewHorizons/External/Modules/VolumesModule.cs +++ b/NewHorizons/External/Modules/VolumesModule.cs @@ -44,6 +44,11 @@ namespace NewHorizons.External.Modules /// public RevealVolumeInfo[] revealVolumes; + /// + /// Add reverb volumes to this planet. Great for echoes in caves. + /// + public VolumeInfo[] reverbVolumes; + [JsonObject] public class VolumeInfo { From 9d5b955bdf0f568a8b56542fe47a9d560cb30063 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 31 Aug 2022 20:18:06 +0000 Subject: [PATCH 09/22] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index a717caa9..b6e5d364 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -2427,6 +2427,13 @@ "items": { "$ref": "#/definitions/RevealVolumeInfo" } + }, + "reverbVolumes": { + "type": "array", + "description": "Add reverb volumes to this planet. Great for echoes in caves.", + "items": { + "$ref": "#/definitions/VolumeInfo" + } } } }, From b25d13e5e825d41a2a8f20d354067691c6b4794a Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 31 Aug 2022 16:28:00 -0400 Subject: [PATCH 10/22] Add insulating volumes --- NewHorizons/Builder/Volumes/VolumesBuildManager.cs | 7 +++++++ NewHorizons/External/Modules/VolumesModule.cs | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs index c5ec9d90..9e9a9c36 100644 --- a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs +++ b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs @@ -71,6 +71,13 @@ namespace NewHorizons.Builder.Volumes VolumeBuilder.Make(go, sector, reverbVolume); } } + if (config.Volumes.insulatingVolumes != null) + { + foreach (var insulatingVolume in config.Volumes.insulatingVolumes) + { + VolumeBuilder.Make(go, sector, insulatingVolume); + } + } } } } diff --git a/NewHorizons/External/Modules/VolumesModule.cs b/NewHorizons/External/Modules/VolumesModule.cs index bbd3b798..7823692b 100644 --- a/NewHorizons/External/Modules/VolumesModule.cs +++ b/NewHorizons/External/Modules/VolumesModule.cs @@ -29,6 +29,11 @@ namespace NewHorizons.External.Modules /// public VolumeInfo[] interferenceVolumes; + /// + /// Add insulating volumes to this planet + /// + public VolumeInfo[] insulatingVolumes; + /// /// Add map restriction volumes to this planet /// From 9f0f055ff8f5291d665a675ccedc5e33d2e69843 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 31 Aug 2022 20:30:42 +0000 Subject: [PATCH 11/22] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index b6e5d364..3dc6a35b 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -2407,6 +2407,13 @@ "$ref": "#/definitions/VolumeInfo" } }, + "insulatingVolumes": { + "type": "array", + "description": "Add insulating volumes to this planet", + "items": { + "$ref": "#/definitions/VolumeInfo" + } + }, "mapRestrictionVolumes": { "type": "array", "description": "Add map restriction volumes to this planet", From 9ad1612c0f0b9db2759f68acbe7963a5289ae4ed Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 31 Aug 2022 16:40:05 -0400 Subject: [PATCH 12/22] . --- NewHorizons/External/Modules/VolumesModule.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/NewHorizons/External/Modules/VolumesModule.cs b/NewHorizons/External/Modules/VolumesModule.cs index 7823692b..c2920951 100644 --- a/NewHorizons/External/Modules/VolumesModule.cs +++ b/NewHorizons/External/Modules/VolumesModule.cs @@ -15,37 +15,37 @@ namespace NewHorizons.External.Modules public class VolumesModule { /// - /// Add audio volumes to this planet + /// Add audio volumes to this planet. /// public AudioVolumeInfo[] audioVolumes; /// - /// Add hazard volumes to this planet + /// Add hazard volumes to this planet. /// public HazardVolumeInfo[] hazardVolumes; /// - /// Add interference volumes to this planet + /// Add interference volumes to this planet. /// public VolumeInfo[] interferenceVolumes; /// - /// Add insulating volumes to this planet + /// Add insulating volumes to this planet. These will stop electricty hazard volumes from affecting you (just like the jellyfish). /// public VolumeInfo[] insulatingVolumes; /// - /// Add map restriction volumes to this planet + /// Add map restriction volumes to this planet. /// public VolumeInfo[] mapRestrictionVolumes; /// - /// Add notification volumes to this planet + /// Add notification volumes to this planet. /// public NotificationVolumeInfo[] notificationVolumes; /// - /// Add triggers that reveal parts of the ship log on this planet + /// Add triggers that reveal parts of the ship log on this planet. /// public RevealVolumeInfo[] revealVolumes; From 796e02c6a240d6db85639407e8effae9387a6ce1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 31 Aug 2022 20:41:52 +0000 Subject: [PATCH 13/22] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 3dc6a35b..45726d35 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -2388,49 +2388,49 @@ "properties": { "audioVolumes": { "type": "array", - "description": "Add audio volumes to this planet", + "description": "Add audio volumes to this planet.", "items": { "$ref": "#/definitions/AudioVolumeInfo" } }, "hazardVolumes": { "type": "array", - "description": "Add hazard volumes to this planet", + "description": "Add hazard volumes to this planet.", "items": { "$ref": "#/definitions/HazardVolumeInfo" } }, "interferenceVolumes": { "type": "array", - "description": "Add interference volumes to this planet", + "description": "Add interference volumes to this planet.", "items": { "$ref": "#/definitions/VolumeInfo" } }, "insulatingVolumes": { "type": "array", - "description": "Add insulating volumes to this planet", + "description": "Add insulating volumes to this planet. These will stop electricty hazard volumes from affecting you (just like the jellyfish).", "items": { "$ref": "#/definitions/VolumeInfo" } }, "mapRestrictionVolumes": { "type": "array", - "description": "Add map restriction volumes to this planet", + "description": "Add map restriction volumes to this planet.", "items": { "$ref": "#/definitions/VolumeInfo" } }, "notificationVolumes": { "type": "array", - "description": "Add notification volumes to this planet", + "description": "Add notification volumes to this planet.", "items": { "$ref": "#/definitions/NotificationVolumeInfo" } }, "revealVolumes": { "type": "array", - "description": "Add triggers that reveal parts of the ship log on this planet", + "description": "Add triggers that reveal parts of the ship log on this planet.", "items": { "$ref": "#/definitions/RevealVolumeInfo" } From c45783bd29d5c50c8995f32fcf80ccf3f12be035 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 31 Aug 2022 17:19:20 -0400 Subject: [PATCH 14/22] Ship Interference --- NewHorizons/Components/InterferenceVolume.cs | 8 ++++++++ NewHorizons/Handlers/InterferenceHandler.cs | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/NewHorizons/Components/InterferenceVolume.cs b/NewHorizons/Components/InterferenceVolume.cs index 7daa0238..b13276c5 100644 --- a/NewHorizons/Components/InterferenceVolume.cs +++ b/NewHorizons/Components/InterferenceVolume.cs @@ -20,6 +20,10 @@ namespace NewHorizons.Components { InterferenceHandler.OnProbeEnterInterferenceVolume(); } + else if (hitObj.CompareTag("ShipDetector")) + { + InterferenceHandler.OnShipEnterInterferenceVolume(); + } } public override void OnTriggerVolumeExit(GameObject hitObj) @@ -32,6 +36,10 @@ namespace NewHorizons.Components { InterferenceHandler.OnProbeExitInterferenceVolume(); } + else if (hitObj.CompareTag("ShipDetector")) + { + InterferenceHandler.OnShipExitInterferenceVolume(); + } } } } diff --git a/NewHorizons/Handlers/InterferenceHandler.cs b/NewHorizons/Handlers/InterferenceHandler.cs index cc0d5a90..71384f02 100644 --- a/NewHorizons/Handlers/InterferenceHandler.cs +++ b/NewHorizons/Handlers/InterferenceHandler.cs @@ -10,14 +10,19 @@ namespace NewHorizons.Handlers { public static bool _playerInterference; public static bool _probeInterference; + public static bool _shipInterference; public static bool PlayerHasInterference() => _playerInterference; public static bool ProbeHasInterference() => _probeInterference; + public static bool ShipHasInterference() => _shipInterference; public static void OnPlayerEnterInterferenceVolume() => _playerInterference = true; public static void OnPlayerExitInterferenceVolume() => _playerInterference = false; public static void OnProbeEnterInterferenceVolume() => _probeInterference = true; public static void OnProbeExitInterferenceVolume() => _probeInterference = false; + + public static void OnShipEnterInterferenceVolume() => _shipInterference = true; + public static void OnShipExitInterferenceVolume() => _shipInterference = false; } } From f5b40db0b2e5f21a4595c789201530f0d5cc68e7 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Thu, 1 Sep 2022 08:13:33 -0400 Subject: [PATCH 15/22] Rename enum member to ghost matter --- NewHorizons/External/Modules/VolumesModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/External/Modules/VolumesModule.cs b/NewHorizons/External/Modules/VolumesModule.cs index c2920951..d144b595 100644 --- a/NewHorizons/External/Modules/VolumesModule.cs +++ b/NewHorizons/External/Modules/VolumesModule.cs @@ -196,7 +196,7 @@ namespace NewHorizons.External.Modules { [EnumMember(Value = @"none")] NONE = 0, [EnumMember(Value = @"general")] GENERAL = 1, - [EnumMember(Value = @"darkMatter")] DARKMATTER = 2, + [EnumMember(Value = @"ghostMatter")] DARKMATTER = 2, [EnumMember(Value = @"heat")] HEAT = 4, [EnumMember(Value = @"fire")] FIRE = 8, [EnumMember(Value = @"sandfall")] SANDFALL = 16, From ae1e74fedcc3d62e43b26747f710e889cef78068 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 1 Sep 2022 12:15:57 +0000 Subject: [PATCH 16/22] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 45726d35..155650f1 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -2565,7 +2565,7 @@ "enum": [ "none", "general", - "darkMatter", + "ghostMatter", "heat", "fire", "sandfall", From 18d575513339708da3f53ab5ddf9e7e7c71d37d3 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 2 Sep 2022 17:55:39 -0400 Subject: [PATCH 17/22] Better interference --- NewHorizons/Components/InterferenceVolume.cs | 23 ++++++-- NewHorizons/Handlers/InterferenceHandler.cs | 60 +++++++++++++++---- NewHorizons/Main.cs | 1 + NewHorizons/Patches/HUDPatches.cs | 62 +++++++++++++++++++- 4 files changed, 127 insertions(+), 19 deletions(-) diff --git a/NewHorizons/Components/InterferenceVolume.cs b/NewHorizons/Components/InterferenceVolume.cs index b13276c5..2b2881fd 100644 --- a/NewHorizons/Components/InterferenceVolume.cs +++ b/NewHorizons/Components/InterferenceVolume.cs @@ -10,19 +10,21 @@ namespace NewHorizons.Components { public class InterferenceVolume : BaseVolume { + private string _id = Guid.NewGuid().ToString(); + public override void OnTriggerVolumeEntry(GameObject hitObj) { if (hitObj.CompareTag("PlayerDetector")) { - InterferenceHandler.OnPlayerEnterInterferenceVolume(); + InterferenceHandler.OnPlayerEnterInterferenceVolume(_id); } else if (hitObj.CompareTag("ProbeDetector")) { - InterferenceHandler.OnProbeEnterInterferenceVolume(); + InterferenceHandler.OnProbeEnterInterferenceVolume(_id); } else if (hitObj.CompareTag("ShipDetector")) { - InterferenceHandler.OnShipEnterInterferenceVolume(); + InterferenceHandler.OnShipEnterInterferenceVolume(_id); } } @@ -30,16 +32,25 @@ namespace NewHorizons.Components { if (hitObj.CompareTag("PlayerDetector")) { - InterferenceHandler.OnPlayerExitInterferenceVolume(); + InterferenceHandler.OnPlayerExitInterferenceVolume(_id); } else if (hitObj.CompareTag("ProbeDetector")) { - InterferenceHandler.OnProbeExitInterferenceVolume(); + InterferenceHandler.OnProbeExitInterferenceVolume(_id); } else if (hitObj.CompareTag("ShipDetector")) { - InterferenceHandler.OnShipExitInterferenceVolume(); + InterferenceHandler.OnShipExitInterferenceVolume(_id); } } + + public void OnPlayerEnter() => InterferenceHandler.OnPlayerEnterInterferenceVolume(_id); + public void OnPlayerExit() => InterferenceHandler.OnPlayerExitInterferenceVolume(_id); + + public void OnProbeEnter() => InterferenceHandler.OnProbeEnterInterferenceVolume(_id); + public void OnProbeExit() => InterferenceHandler.OnProbeExitInterferenceVolume(_id); + + public void OnShipEnter() => InterferenceHandler.OnShipEnterInterferenceVolume(_id); + public void OnShipExit() => InterferenceHandler.OnShipExitInterferenceVolume(_id); } } diff --git a/NewHorizons/Handlers/InterferenceHandler.cs b/NewHorizons/Handlers/InterferenceHandler.cs index 71384f02..2e854afa 100644 --- a/NewHorizons/Handlers/InterferenceHandler.cs +++ b/NewHorizons/Handlers/InterferenceHandler.cs @@ -8,21 +8,57 @@ namespace NewHorizons.Handlers { public static class InterferenceHandler { - public static bool _playerInterference; - public static bool _probeInterference; - public static bool _shipInterference; + private static List _playerInterference; + private static List _probeInterference; + private static List _shipInterference; - public static bool PlayerHasInterference() => _playerInterference; - public static bool ProbeHasInterference() => _probeInterference; - public static bool ShipHasInterference() => _shipInterference; + public static void Init() + { + _playerInterference = new List(); + _probeInterference = new List(); + _shipInterference = new List(); + } - public static void OnPlayerEnterInterferenceVolume() => _playerInterference = true; - public static void OnPlayerExitInterferenceVolume() => _playerInterference = false; + public static bool PlayerHasInterference() => _playerInterference.Any(); + public static bool ProbeHasInterference() => _probeInterference.Any(); + public static bool ShipHasInterference() => _shipInterference.Any(); - public static void OnProbeEnterInterferenceVolume() => _probeInterference = true; - public static void OnProbeExitInterferenceVolume() => _probeInterference = false; + public static bool IsPlayerSameAsProbe() => _playerInterference.All(_probeInterference.Contains) && _playerInterference.Count == _probeInterference.Count; + public static bool IsPlayerSameAsShip() => _playerInterference.All(_shipInterference.Contains) && _playerInterference.Count == _shipInterference.Count; - public static void OnShipEnterInterferenceVolume() => _shipInterference = true; - public static void OnShipExitInterferenceVolume() => _shipInterference = false; + public static void OnPlayerEnterInterferenceVolume(string id) + { + _playerInterference.SafeAdd(id); + GlobalMessenger.FireEvent("RefreshHUDVisibility"); + } + + public static void OnPlayerExitInterferenceVolume(string id) + { + _playerInterference.Remove(id); + GlobalMessenger.FireEvent("RefreshHUDVisibility"); + } + + public static void OnProbeEnterInterferenceVolume(string id) + { + _probeInterference.SafeAdd(id); + GlobalMessenger.FireEvent("RefreshHUDVisibility"); + } + + public static void OnProbeExitInterferenceVolume(string id) + { + _probeInterference.Remove(id); + GlobalMessenger.FireEvent("RefreshHUDVisibility"); + } + + public static void OnShipEnterInterferenceVolume(string id) + { + _shipInterference.SafeAdd(id); + GlobalMessenger.FireEvent("RefreshHUDVisibility"); + } + public static void OnShipExitInterferenceVolume(string id) + { + _shipInterference.Remove(id); + GlobalMessenger.FireEvent("RefreshHUDVisibility"); + } } } diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 80f5dc53..9204ed45 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -305,6 +305,7 @@ namespace NewHorizons AstroObjectLocator.Init(); StreamingHandler.Init(); AudioTypeHandler.Init(); + InterferenceHandler.Init(); RemoteHandler.Init(); AtmosphereBuilder.Init(); BrambleNodeBuilder.Init(BodyDict[CurrentStarSystem].Select(x => x.Config).Where(x => x.Bramble?.dimension != null).ToArray()); diff --git a/NewHorizons/Patches/HUDPatches.cs b/NewHorizons/Patches/HUDPatches.cs index adcde38e..fc37e4e0 100644 --- a/NewHorizons/Patches/HUDPatches.cs +++ b/NewHorizons/Patches/HUDPatches.cs @@ -10,6 +10,8 @@ namespace NewHorizons.Patches [HarmonyPatch(typeof(HUDMarker), nameof(HUDMarker.Awake))] public static void HUDMarker_Awake(HUDMarker __instance) { + GlobalMessenger.AddListener("RefreshHUDVisibility", __instance.RefreshOwnVisibility); + GlobalMessenger.AddListener("RefreshHUDVisibility", __instance.RefreshOwnVisibility); GlobalMessenger.AddListener("PlayerEnterCloakField", __instance.OnPlayerEnterCloakField); GlobalMessenger.AddListener("PlayerExitCloakField", __instance.OnPlayerExitCloakField); } @@ -18,6 +20,8 @@ namespace NewHorizons.Patches [HarmonyPatch(typeof(HUDMarker), nameof(HUDMarker.OnDestroy))] public static void HUDMarker_OnDestroy(HUDMarker __instance) { + GlobalMessenger.RemoveListener("RefreshHUDVisibility", __instance.RefreshOwnVisibility); + GlobalMessenger.RemoveListener("RefreshHUDVisibility", __instance.RefreshOwnVisibility); GlobalMessenger.RemoveListener("PlayerEnterCloakField", __instance.OnPlayerEnterCloakField); GlobalMessenger.RemoveListener("PlayerExitCloakField", __instance.OnPlayerExitCloakField); } @@ -54,11 +58,67 @@ namespace NewHorizons.Patches GlobalMessenger.RemoveListener("ShipExitCloakField", __instance.RefreshOwnVisibility); } + [HarmonyPrefix] + [HarmonyPatch(typeof(ProbeHUDMarker), nameof(ProbeHUDMarker.RefreshOwnVisibility))] + public static bool ProbeHUDMarker_RefreshOwnVisibility(ProbeHUDMarker __instance) + { + bool insideEYE = Locator.GetEyeStateManager() != null && Locator.GetEyeStateManager().IsInsideTheEye(); + bool insideQM = __instance._quantumMoon != null && (__instance._quantumMoon.IsPlayerInside() || __instance._quantumMoon.IsProbeInside()); + bool insideRW = Locator.GetRingWorldController() != null && Locator.GetRingWorldController().isPlayerInside == Locator.GetRingWorldController().isProbeInside; + bool insideIP = Locator.GetCloakFieldController() != null && Locator.GetCloakFieldController().isPlayerInsideCloak == Locator.GetCloakFieldController().isProbeInsideCloak; + bool insideCloak = Components.CloakSectorController.isPlayerInside == Components.CloakSectorController.isProbeInside; + bool sameInterference = InterferenceHandler.IsPlayerSameAsProbe(); + bool isActive = __instance.gameObject.activeInHierarchy || __instance._isTLCDuplicate; + + __instance._isVisible = isActive && !insideEYE && !insideQM && !__instance._translatorEquipped && !__instance._inConversation && __instance._launched && (__instance._isWearingHelmet || __instance._atFlightConsole) && insideRW && insideIP && insideCloak && sameInterference; + + if (__instance._canvasMarker != null) __instance._canvasMarker.SetVisibility(__instance._isVisible); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipHUDMarker), nameof(ShipHUDMarker.RefreshOwnVisibility))] + public static bool ShipHUDMarker_RefreshOwnVisibility(ShipHUDMarker __instance) + { + bool insideEYE = Locator.GetEyeStateManager() != null && Locator.GetEyeStateManager().IsInsideTheEye(); + bool insideQM = __instance._quantumMoon != null && (__instance._quantumMoon.IsPlayerInside() || __instance._quantumMoon.IsShipInside()); + bool insideRW = Locator.GetRingWorldController() != null && Locator.GetRingWorldController().isPlayerInside; + bool insideIP = Locator.GetCloakFieldController() != null ? true : Locator.GetCloakFieldController().isPlayerInsideCloak == Locator.GetCloakFieldController().isShipInsideCloak; + bool insideCloak = Components.CloakSectorController.isPlayerInside == Components.CloakSectorController.isShipInside; + bool sameInterference = InterferenceHandler.IsPlayerSameAsShip(); + + __instance._isVisible = !insideEYE && !insideQM && !insideRW && !__instance._translatorEquipped && !__instance._inConversation && !__instance._shipDestroyed && !__instance._playerInShip && PlayerState.HasPlayerEnteredShip() && __instance._isWearingHelmet && insideIP && insideCloak && sameInterference; + + if (__instance._canvasMarker != null) __instance._canvasMarker.SetVisibility(__instance._isVisible); + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ShipLogEntryHUDMarker), nameof(ShipLogEntryHUDMarker.RefreshOwnVisibility))] + public static bool ShipLogEntryHUDMarker_RefreshOwnVisibility(ShipLogEntryHUDMarker __instance) + { + bool hasEntryLocation = ShipLogEntryHUDMarker.s_entryLocation != null; + bool insideEYE = Locator.GetEyeStateManager() != null && Locator.GetEyeStateManager().IsInsideTheEye(); + bool insideQM = __instance._quantumMoon != null && __instance._quantumMoon.IsPlayerInside(); + bool insideRW = Locator.GetRingWorldController() != null && Locator.GetRingWorldController().isPlayerInside && ShipLogEntryHUDMarker.s_entryLocationID == "IP_RING_WORLD"; + bool insideIP = (hasEntryLocation && ShipLogEntryHUDMarker.s_entryLocation.IsWithinCloakField()) || !(Locator.GetCloakFieldController() != null && Locator.GetCloakFieldController().isPlayerInsideCloak); + bool insideCloak = (hasEntryLocation && ShipLogEntryHUDMarker.s_entryLocation.IsWithinCloakField()) || !Components.CloakSectorController.isPlayerInside; + + __instance._isVisible = (!insideEYE && !insideQM && !insideRW && !__instance._translatorEquipped && !__instance._inConversation && hasEntryLocation && (__instance._isWearingHelmet || __instance._atFlightConsole) && insideIP && insideCloak); + + if (__instance._canvasMarker != null) __instance._canvasMarker.SetVisibility(__instance._isVisible); + + return false; + } + + [HarmonyPostfix] [HarmonyPatch(typeof(ProbeCamera), nameof(ProbeCamera.HasInterference))] public static void ProbeCamera_HasInterference(ProbeCamera __instance, ref bool __result) { - __result = __result || (__instance._id != ProbeCamera.ID.PreLaunch && (Components.CloakSectorController.isPlayerInside != Components.CloakSectorController.isProbeInside || InterferenceHandler.PlayerHasInterference() != InterferenceHandler.ProbeHasInterference())); + __result = __result || (__instance._id != ProbeCamera.ID.PreLaunch && (Components.CloakSectorController.isPlayerInside != Components.CloakSectorController.isProbeInside || !InterferenceHandler.IsPlayerSameAsProbe())); } } } From 57e26794d9b4fa9a281184cd7282cacff4c921d4 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 3 Sep 2022 10:53:49 -0400 Subject: [PATCH 18/22] Add parentPath to volumes --- NewHorizons/Builder/ShipLog/RevealBuilder.cs | 15 +++++++++++++++ NewHorizons/Builder/Volumes/AudioVolumeBuilder.cs | 14 ++++++++++++++ .../Builder/Volumes/HazardVolumeBuilder.cs | 14 ++++++++++++++ .../Builder/Volumes/NotificationVolumeBuilder.cs | 14 ++++++++++++++ NewHorizons/Builder/Volumes/VolumeBuilder.cs | 15 +++++++++++++++ NewHorizons/External/Modules/VolumesModule.cs | 5 +++++ 6 files changed, 77 insertions(+) diff --git a/NewHorizons/Builder/ShipLog/RevealBuilder.cs b/NewHorizons/Builder/ShipLog/RevealBuilder.cs index 95f118b6..5678b1d3 100644 --- a/NewHorizons/Builder/ShipLog/RevealBuilder.cs +++ b/NewHorizons/Builder/ShipLog/RevealBuilder.cs @@ -41,7 +41,22 @@ namespace NewHorizons.Builder.ShipLog GameObject revealTriggerVolume = new GameObject("Reveal Volume (" + info.revealOn + ")"); revealTriggerVolume.SetActive(false); revealTriggerVolume.transform.parent = sector?.transform ?? planetGO.transform; + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = planetGO.transform.Find(info.parentPath); + if (newParent != null) + { + go.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}"); + } + } + revealTriggerVolume.transform.position = planetGO.transform.TransformPoint(info.position ?? Vector3.zero); + return revealTriggerVolume; } diff --git a/NewHorizons/Builder/Volumes/AudioVolumeBuilder.cs b/NewHorizons/Builder/Volumes/AudioVolumeBuilder.cs index b487670a..2952f590 100644 --- a/NewHorizons/Builder/Volumes/AudioVolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/AudioVolumeBuilder.cs @@ -19,6 +19,20 @@ namespace NewHorizons.Builder.Volumes go.SetActive(false); go.transform.parent = sector?.transform ?? planetGO.transform; + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = planetGO.transform.Find(info.parentPath); + if (newParent != null) + { + go.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}"); + } + } + go.transform.position = planetGO.transform.TransformPoint(info.position != null ? (Vector3)info.position : Vector3.zero); go.layer = LayerMask.NameToLayer("AdvancedEffectVolume"); diff --git a/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs b/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs index 67c6f22c..ef652a12 100644 --- a/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs @@ -16,6 +16,20 @@ namespace NewHorizons.Builder.Volumes go.SetActive(false); go.transform.parent = sector?.transform ?? planetGO.transform; + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = planetGO.transform.Find(info.parentPath); + if (newParent != null) + { + go.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}"); + } + } + go.transform.position = planetGO.transform.TransformPoint(info.position != null ? (Vector3)info.position : Vector3.zero); go.layer = LayerMask.NameToLayer("BasicEffectVolume"); diff --git a/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs b/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs index c91e4161..496a9ea7 100644 --- a/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs @@ -21,6 +21,20 @@ namespace NewHorizons.Builder.Volumes go.SetActive(false); go.transform.parent = sector?.transform ?? planetGO.transform; + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = planetGO.transform.Find(info.parentPath); + if (newParent != null) + { + go.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}"); + } + } + go.transform.position = planetGO.transform.TransformPoint(info.position != null ? (Vector3)info.position : Vector3.zero); go.layer = LayerMask.NameToLayer("BasicEffectVolume"); diff --git a/NewHorizons/Builder/Volumes/VolumeBuilder.cs b/NewHorizons/Builder/Volumes/VolumeBuilder.cs index 0cf3ebe8..70e6c1f7 100644 --- a/NewHorizons/Builder/Volumes/VolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/VolumeBuilder.cs @@ -1,6 +1,7 @@ using NewHorizons.Components; using NewHorizons.External.Modules; using UnityEngine; +using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.Volumes { @@ -12,6 +13,20 @@ namespace NewHorizons.Builder.Volumes go.SetActive(false); go.transform.parent = sector?.transform ?? planetGO.transform; + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = planetGO.transform.Find(info.parentPath); + if (newParent != null) + { + go.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}"); + } + } + go.transform.position = planetGO.transform.TransformPoint(info.position != null ? (Vector3)info.position : Vector3.zero); go.layer = LayerMask.NameToLayer("BasicEffectVolume"); diff --git a/NewHorizons/External/Modules/VolumesModule.cs b/NewHorizons/External/Modules/VolumesModule.cs index d144b595..a3c810a0 100644 --- a/NewHorizons/External/Modules/VolumesModule.cs +++ b/NewHorizons/External/Modules/VolumesModule.cs @@ -66,6 +66,11 @@ namespace NewHorizons.External.Modules /// The radius of this volume. /// public float radius = 1f; + + /// + /// The relative path from the planet to the parent of this object. Optional (will default to the root sector). + /// + public string parentPath; } [JsonObject] From f909832cb23288cf9303e413089418bb59ee3d50 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 3 Sep 2022 11:01:07 -0400 Subject: [PATCH 19/22] comment --- NewHorizons/Builder/Volumes/VolumeBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Volumes/VolumeBuilder.cs b/NewHorizons/Builder/Volumes/VolumeBuilder.cs index 70e6c1f7..afeffd73 100644 --- a/NewHorizons/Builder/Volumes/VolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/VolumeBuilder.cs @@ -7,7 +7,7 @@ namespace NewHorizons.Builder.Volumes { public static class VolumeBuilder { - public static TVolume Make(GameObject planetGO, Sector sector, VolumesModule.VolumeInfo info) where TVolume : MonoBehaviour + public static TVolume Make(GameObject planetGO, Sector sector, VolumesModule.VolumeInfo info) where TVolume : MonoBehaviour //Could be BaseVolume but I need to create vanilla volumes too. { var go = new GameObject(typeof(TVolume).Name); go.SetActive(false); From 12e95bce0bd0e7e60821f093f6cce6794d4dc899 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 3 Sep 2022 11:04:01 -0400 Subject: [PATCH 20/22] Indeed --- NewHorizons/Builder/ShipLog/RevealBuilder.cs | 2 +- NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/ShipLog/RevealBuilder.cs b/NewHorizons/Builder/ShipLog/RevealBuilder.cs index 5678b1d3..59662218 100644 --- a/NewHorizons/Builder/ShipLog/RevealBuilder.cs +++ b/NewHorizons/Builder/ShipLog/RevealBuilder.cs @@ -47,7 +47,7 @@ namespace NewHorizons.Builder.ShipLog var newParent = planetGO.transform.Find(info.parentPath); if (newParent != null) { - go.transform.parent = newParent; + revealTriggerVolume.transform.parent = newParent; } else { diff --git a/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs b/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs index ef652a12..d52b4352 100644 --- a/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using UnityEngine; +using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.Volumes { From ad79680388d8b70721778e39b7d2d8516bc7c0fb Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 3 Sep 2022 15:06:19 +0000 Subject: [PATCH 21/22] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 155650f1..63a70345 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -2457,6 +2457,10 @@ "description": "The radius of this volume.", "format": "float" }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." + }, "audio": { "type": "string", "description": "The audio to use. Can be a path to a .wav/.ogg/.mp3 file, or taken from the AudioClip list." @@ -2526,6 +2530,10 @@ "description": "The radius of this volume.", "format": "float" }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." + }, "type": { "description": "The type of hazard for this volume.", "default": "general", @@ -2599,6 +2607,10 @@ "type": "number", "description": "The radius of this volume.", "format": "float" + }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." } } }, @@ -2615,6 +2627,10 @@ "description": "The radius of this volume.", "format": "float" }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." + }, "target": { "description": "What the notification will show for.", "default": "all", @@ -2673,6 +2689,10 @@ "description": "The radius of this volume.", "format": "float" }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." + }, "maxAngle": { "type": "number", "description": "The max view angle (in degrees) the player can see the volume with to unlock the fact (`observe` only)", From f9882b5b00938f12835a1fd8ad214649f53ae153 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 4 Sep 2022 01:41:25 -0400 Subject: [PATCH 22/22] Use InterferenceVolume instead of id --- NewHorizons/Components/InterferenceVolume.cs | 26 ++++----- NewHorizons/Handlers/InterferenceHandler.cs | 59 ++++++++++++-------- 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/NewHorizons/Components/InterferenceVolume.cs b/NewHorizons/Components/InterferenceVolume.cs index 2b2881fd..43cf34ac 100644 --- a/NewHorizons/Components/InterferenceVolume.cs +++ b/NewHorizons/Components/InterferenceVolume.cs @@ -10,21 +10,19 @@ namespace NewHorizons.Components { public class InterferenceVolume : BaseVolume { - private string _id = Guid.NewGuid().ToString(); - public override void OnTriggerVolumeEntry(GameObject hitObj) { if (hitObj.CompareTag("PlayerDetector")) { - InterferenceHandler.OnPlayerEnterInterferenceVolume(_id); + OnPlayerEnter(); } else if (hitObj.CompareTag("ProbeDetector")) { - InterferenceHandler.OnProbeEnterInterferenceVolume(_id); + OnProbeEnter(); } else if (hitObj.CompareTag("ShipDetector")) { - InterferenceHandler.OnShipEnterInterferenceVolume(_id); + OnShipEnter(); } } @@ -32,25 +30,25 @@ namespace NewHorizons.Components { if (hitObj.CompareTag("PlayerDetector")) { - InterferenceHandler.OnPlayerExitInterferenceVolume(_id); + OnPlayerExit(); } else if (hitObj.CompareTag("ProbeDetector")) { - InterferenceHandler.OnProbeExitInterferenceVolume(_id); + OnProbeExit(); } else if (hitObj.CompareTag("ShipDetector")) { - InterferenceHandler.OnShipExitInterferenceVolume(_id); + OnShipExit(); } } - public void OnPlayerEnter() => InterferenceHandler.OnPlayerEnterInterferenceVolume(_id); - public void OnPlayerExit() => InterferenceHandler.OnPlayerExitInterferenceVolume(_id); + public void OnPlayerEnter() => InterferenceHandler.OnPlayerEnterInterferenceVolume(this); + public void OnPlayerExit() => InterferenceHandler.OnPlayerExitInterferenceVolume(this); - public void OnProbeEnter() => InterferenceHandler.OnProbeEnterInterferenceVolume(_id); - public void OnProbeExit() => InterferenceHandler.OnProbeExitInterferenceVolume(_id); + public void OnProbeEnter() => InterferenceHandler.OnProbeEnterInterferenceVolume(this); + public void OnProbeExit() => InterferenceHandler.OnProbeExitInterferenceVolume(this); - public void OnShipEnter() => InterferenceHandler.OnShipEnterInterferenceVolume(_id); - public void OnShipExit() => InterferenceHandler.OnShipExitInterferenceVolume(_id); + public void OnShipEnter() => InterferenceHandler.OnShipEnterInterferenceVolume(this); + public void OnShipExit() => InterferenceHandler.OnShipExitInterferenceVolume(this); } } diff --git a/NewHorizons/Handlers/InterferenceHandler.cs b/NewHorizons/Handlers/InterferenceHandler.cs index 2e854afa..97ff0046 100644 --- a/NewHorizons/Handlers/InterferenceHandler.cs +++ b/NewHorizons/Handlers/InterferenceHandler.cs @@ -6,58 +6,69 @@ using System.Threading.Tasks; namespace NewHorizons.Handlers { + using InterferenceVolume = NewHorizons.Components.InterferenceVolume; + public static class InterferenceHandler { - private static List _playerInterference; - private static List _probeInterference; - private static List _shipInterference; + private static List _playerInterference; + private static List _probeInterference; + private static List _shipInterference; public static void Init() { - _playerInterference = new List(); - _probeInterference = new List(); - _shipInterference = new List(); + _playerInterference = new List(); + _probeInterference = new List(); + _shipInterference = new List(); } - public static bool PlayerHasInterference() => _playerInterference.Any(); - public static bool ProbeHasInterference() => _probeInterference.Any(); - public static bool ShipHasInterference() => _shipInterference.Any(); + public static bool PlayerHasInterference() => _playerInterference.Any(volume => volume != null); + public static bool ProbeHasInterference() => _probeInterference.Any(volume => volume != null); + public static bool ShipHasInterference() => _shipInterference.Any(volume => volume != null); - public static bool IsPlayerSameAsProbe() => _playerInterference.All(_probeInterference.Contains) && _playerInterference.Count == _probeInterference.Count; - public static bool IsPlayerSameAsShip() => _playerInterference.All(_shipInterference.Contains) && _playerInterference.Count == _shipInterference.Count; - - public static void OnPlayerEnterInterferenceVolume(string id) + public static bool IsPlayerSameAsProbe() { - _playerInterference.SafeAdd(id); + _playerInterference.RemoveAll(volume => volume == null); + return _playerInterference.All(_probeInterference.Contains) && _playerInterference.Count == _probeInterference.Count; + } + + public static bool IsPlayerSameAsShip() + { + _playerInterference.RemoveAll(volume => volume == null); + return _playerInterference.All(_shipInterference.Contains) && _playerInterference.Count == _shipInterference.Count; + } + + public static void OnPlayerEnterInterferenceVolume(InterferenceVolume interferenceVolume) + { + _playerInterference.SafeAdd(interferenceVolume); GlobalMessenger.FireEvent("RefreshHUDVisibility"); } - public static void OnPlayerExitInterferenceVolume(string id) + public static void OnPlayerExitInterferenceVolume(InterferenceVolume interferenceVolume) { - _playerInterference.Remove(id); + _playerInterference.Remove(interferenceVolume); GlobalMessenger.FireEvent("RefreshHUDVisibility"); } - public static void OnProbeEnterInterferenceVolume(string id) + public static void OnProbeEnterInterferenceVolume(InterferenceVolume interferenceVolume) { - _probeInterference.SafeAdd(id); + _probeInterference.SafeAdd(interferenceVolume); GlobalMessenger.FireEvent("RefreshHUDVisibility"); } - public static void OnProbeExitInterferenceVolume(string id) + public static void OnProbeExitInterferenceVolume(InterferenceVolume interferenceVolume) { - _probeInterference.Remove(id); + _probeInterference.Remove(interferenceVolume); GlobalMessenger.FireEvent("RefreshHUDVisibility"); } - public static void OnShipEnterInterferenceVolume(string id) + public static void OnShipEnterInterferenceVolume(InterferenceVolume interferenceVolume) { - _shipInterference.SafeAdd(id); + _shipInterference.SafeAdd(interferenceVolume); GlobalMessenger.FireEvent("RefreshHUDVisibility"); } - public static void OnShipExitInterferenceVolume(string id) + public static void OnShipExitInterferenceVolume(InterferenceVolume interferenceVolume) { - _shipInterference.Remove(id); + _shipInterference.Remove(interferenceVolume); GlobalMessenger.FireEvent("RefreshHUDVisibility"); } }