From 4a80fa70761d1929c79eae910ac33e38ff26f39c Mon Sep 17 00:00:00 2001 From: xen-42 Date: Fri, 4 Oct 2024 15:04:50 -0400 Subject: [PATCH] Allow system change volumes to specify custom targets #917 --- .../Builder/Body/SingularityBuilder.cs | 28 +++++++++---------- .../Builder/General/SpawnPointBuilder.cs | 2 +- .../Volumes/ChangeStarSystemVolumeBuilder.cs | 1 + .../Components/Volumes/BlackHoleWarpVolume.cs | 4 +++ NewHorizons/Components/Volumes/WarpVolume.cs | 3 ++ NewHorizons/External/Modules/SpawnModule.cs | 10 +++++++ .../Modules/VariableSize/SingularityModule.cs | 6 ++++ .../VolumeInfos/ChangeStarSystemVolumeInfo.cs | 6 ++++ NewHorizons/Handlers/PlayerSpawnHandler.cs | 8 ++++++ 9 files changed, 53 insertions(+), 15 deletions(-) diff --git a/NewHorizons/Builder/Body/SingularityBuilder.cs b/NewHorizons/Builder/Body/SingularityBuilder.cs index a961c9d5..eb8863c8 100644 --- a/NewHorizons/Builder/Body/SingularityBuilder.cs +++ b/NewHorizons/Builder/Body/SingularityBuilder.cs @@ -1,18 +1,17 @@ -using NewHorizons.External.Configs; -using NewHorizons.Utility; -using NewHorizons.External.Modules.VariableSize; -using UnityEngine; - -using System.Collections.Generic; -using NewHorizons.Components.SizeControllers; -using Color = UnityEngine.Color; -using NewHorizons.Components.Volumes; using NewHorizons.Builder.Props; -using NewHorizons.Utility.OWML; -using NewHorizons.Utility.OuterWilds; -using NewHorizons.External.SerializableData; using NewHorizons.Builder.Volumes; +using NewHorizons.Components.SizeControllers; +using NewHorizons.Components.Volumes; +using NewHorizons.External.Configs; +using NewHorizons.External.Modules.VariableSize; +using NewHorizons.External.SerializableData; +using NewHorizons.Utility; +using NewHorizons.Utility.OuterWilds; +using NewHorizons.Utility.OWML; using System; +using System.Collections.Generic; +using UnityEngine; +using Color = UnityEngine.Color; namespace NewHorizons.Builder.Body { @@ -88,7 +87,7 @@ namespace NewHorizons.Builder.Body Vector3 localRotation = singularity?.rotation == null ? Vector3.zero : singularity.rotation; GameObject newSingularity = MakeSingularity(go, sector, localPosition, localRotation, polarity, horizonRadius, distortRadius, - hasHazardVolume, singularity.targetStarSystem, singularity.curve, singularity.hasWarpEffects, singularity.renderQueueOverride, singularity.rename, singularity.parentPath, singularity.isRelativeToParent); + hasHazardVolume, singularity.targetStarSystem, singularity.spawnPointID, singularity.curve, singularity.hasWarpEffects, singularity.renderQueueOverride, singularity.rename, singularity.parentPath, singularity.isRelativeToParent); var uniqueID = string.IsNullOrEmpty(singularity.uniqueID) ? config.name : singularity.uniqueID; @@ -161,7 +160,7 @@ namespace NewHorizons.Builder.Body } public static GameObject MakeSingularity(GameObject planetGO, Sector sector, Vector3 position, Vector3 rotation, bool polarity, float horizon, float distort, - bool hasDestructionVolume, string targetStarSystem = null, TimeValuePair[] curve = null, bool warpEffects = true, int renderQueue = 2985, string rename = null, string parentPath = null, bool isRelativeToParent = false) + bool hasDestructionVolume, string targetStarSystem = null, string targetSpawnID = null, TimeValuePair[] curve = null, bool warpEffects = true, int renderQueue = 2985, string rename = null, string parentPath = null, bool isRelativeToParent = false) { // polarity true = black, false = white @@ -233,6 +232,7 @@ namespace NewHorizons.Builder.Body { var wormholeVolume = destructionVolumeGO.AddComponent(); wormholeVolume.TargetSolarSystem = targetStarSystem; + wormholeVolume.TargetSpawnID = targetSpawnID; } } else diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index f5ad5728..0e1eee40 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -94,6 +94,7 @@ namespace NewHorizons.Builder.General suitUpQueued = true; Delay.RunWhen(() => Main.IsSystemReady, () => { + suitUpQueued = false; if (Main.Instance.IsWarpingFromVessel || (!Main.Instance.IsWarpingFromShip && (PlayerSpawnInfo?.startWithSuit ?? false))) { SuitUp(); @@ -108,7 +109,6 @@ namespace NewHorizons.Builder.General public static void SuitUp() { - suitUpQueued = false; if (!Locator.GetPlayerController()._isWearingSuit) { Locator.GetPlayerSuit().SuitUp(false, true, true); diff --git a/NewHorizons/Builder/Volumes/ChangeStarSystemVolumeBuilder.cs b/NewHorizons/Builder/Volumes/ChangeStarSystemVolumeBuilder.cs index c3b8c5db..5557da98 100644 --- a/NewHorizons/Builder/Volumes/ChangeStarSystemVolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/ChangeStarSystemVolumeBuilder.cs @@ -11,6 +11,7 @@ namespace NewHorizons.Builder.Volumes var volume = VolumeBuilder.Make(planetGO, sector, info); volume.TargetSolarSystem = info.targetStarSystem; + volume.TargetSpawnID = info.spawnPointID; return volume; } diff --git a/NewHorizons/Components/Volumes/BlackHoleWarpVolume.cs b/NewHorizons/Components/Volumes/BlackHoleWarpVolume.cs index bd99fee5..941bff2b 100644 --- a/NewHorizons/Components/Volumes/BlackHoleWarpVolume.cs +++ b/NewHorizons/Components/Volumes/BlackHoleWarpVolume.cs @@ -1,8 +1,11 @@ +using NewHorizons.Handlers; + namespace NewHorizons.Components.Volumes { public class BlackHoleWarpVolume : BlackHoleDestructionVolume { public string TargetSolarSystem { get; set; } + public string TargetSpawnID { get; set; } public override void Awake() { @@ -19,6 +22,7 @@ namespace NewHorizons.Components.Volumes { Locator.GetPlayerAudioController().PlayOneShotInternal(AudioType.BH_BlackHoleEmission); Main.Instance.ChangeCurrentStarSystem(TargetSolarSystem, PlayerState.AtFlightConsole()); + PlayerSpawnHandler.TargetSpawnID = TargetSpawnID; } } } diff --git a/NewHorizons/Components/Volumes/WarpVolume.cs b/NewHorizons/Components/Volumes/WarpVolume.cs index fa07d6e4..25892833 100644 --- a/NewHorizons/Components/Volumes/WarpVolume.cs +++ b/NewHorizons/Components/Volumes/WarpVolume.cs @@ -1,3 +1,4 @@ +using NewHorizons.Handlers; using UnityEngine; namespace NewHorizons.Components.Volumes @@ -5,6 +6,7 @@ namespace NewHorizons.Components.Volumes internal class WarpVolume : BaseVolume { public string TargetSolarSystem; + public string TargetSpawnID; public override void OnTriggerVolumeEntry(GameObject hitObj) { @@ -13,6 +15,7 @@ namespace NewHorizons.Components.Volumes if (Main.Instance.CurrentStarSystem != TargetSolarSystem) // Otherwise it really breaks idk why { Main.Instance.ChangeCurrentStarSystem(TargetSolarSystem, PlayerState.AtFlightConsole()); + PlayerSpawnHandler.TargetSpawnID = TargetSpawnID; } } } diff --git a/NewHorizons/External/Modules/SpawnModule.cs b/NewHorizons/External/Modules/SpawnModule.cs index ddfeadcf..3c62766a 100644 --- a/NewHorizons/External/Modules/SpawnModule.cs +++ b/NewHorizons/External/Modules/SpawnModule.cs @@ -1,3 +1,4 @@ +using NewHorizons.Builder.General; using NewHorizons.External.SerializableData; using NewHorizons.Handlers; using Newtonsoft.Json; @@ -61,8 +62,17 @@ namespace NewHorizons.External.Modules /// public string makeDefaultIfPersistentCondition; + /// + /// ID used to have a black hole or warp volume bring the player to this spawn specifically + /// + public string id; + public int GetPriority() { + if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(PlayerSpawnHandler.TargetSpawnID) && id == PlayerSpawnHandler.TargetSpawnID) + { + return 3; + } if (!string.IsNullOrEmpty(makeDefaultIfFactRevealed) && ShipLogHandler.KnowsFact(makeDefaultIfFactRevealed)) { return 2; diff --git a/NewHorizons/External/Modules/VariableSize/SingularityModule.cs b/NewHorizons/External/Modules/VariableSize/SingularityModule.cs index d85a399c..042cbe02 100644 --- a/NewHorizons/External/Modules/VariableSize/SingularityModule.cs +++ b/NewHorizons/External/Modules/VariableSize/SingularityModule.cs @@ -54,6 +54,12 @@ namespace NewHorizons.External.Modules.VariableSize /// public string targetStarSystem; + /// + /// If this is a black hole loading a new star system, set the ID of the spawn point you want to use + /// Otherwise, will use the default spawn + /// + public string spawnPointID; + /// /// Type of singularity (white hole or black hole) /// diff --git a/NewHorizons/External/Modules/Volumes/VolumeInfos/ChangeStarSystemVolumeInfo.cs b/NewHorizons/External/Modules/Volumes/VolumeInfos/ChangeStarSystemVolumeInfo.cs index 969a5945..24b492db 100644 --- a/NewHorizons/External/Modules/Volumes/VolumeInfos/ChangeStarSystemVolumeInfo.cs +++ b/NewHorizons/External/Modules/Volumes/VolumeInfos/ChangeStarSystemVolumeInfo.cs @@ -10,5 +10,11 @@ namespace NewHorizons.External.Modules.Volumes.VolumeInfos /// The star system that entering this volume will send you to. /// [DefaultValue("SolarSystem")] public string targetStarSystem; + + /// + /// ID assigned to a spawn point in the other system that the player will be sent to + /// Uses the default spawn if not set + /// + public string spawnPointID; } } diff --git a/NewHorizons/Handlers/PlayerSpawnHandler.cs b/NewHorizons/Handlers/PlayerSpawnHandler.cs index af78874a..8ee1a007 100644 --- a/NewHorizons/Handlers/PlayerSpawnHandler.cs +++ b/NewHorizons/Handlers/PlayerSpawnHandler.cs @@ -9,6 +9,11 @@ namespace NewHorizons.Handlers { public static class PlayerSpawnHandler { + /// + /// Set during the previous loop, force the player to spawn here + /// + public static string TargetSpawnID { get; set; } + public static void SetUpPlayerSpawn() { if (UsingCustomSpawn()) @@ -146,6 +151,9 @@ namespace NewHorizons.Handlers FixPlayerVelocity(); InvulnerabilityHandler.MakeInvulnerable(false); + + // Done spawning + TargetSpawnID = null; } private static void FixPlayerVelocity(bool recenter = true)