From 54f341d16e97438fee8b4e71cbc5e51b6ae3aa66 Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 2 May 2022 02:09:36 -0400 Subject: [PATCH] Fix meteors + document --- NewHorizons/Builder/Props/PropBuildManager.cs | 4 +- NewHorizons/Builder/Props/VolcanoBuilder.cs | 38 +++++++++++++---- NewHorizons/External/PropModule.cs | 6 ++- NewHorizons/Main.cs | 1 + NewHorizons/manifest.json | 2 +- NewHorizons/schema.json | 42 +++++++++++++++++++ 6 files changed, 80 insertions(+), 13 deletions(-) diff --git a/NewHorizons/Builder/Props/PropBuildManager.cs b/NewHorizons/Builder/Props/PropBuildManager.cs index 8b1c696d..1d248e72 100644 --- a/NewHorizons/Builder/Props/PropBuildManager.cs +++ b/NewHorizons/Builder/Props/PropBuildManager.cs @@ -49,9 +49,9 @@ namespace NewHorizons.Builder.Props TornadoBuilder.Make(go, sector, tornadoInfo, config.Atmosphere?.Cloud != null); } } - if (config.Props.Volcanos != null) + if (config.Props.Volcanoes != null) { - foreach (var volcanoInfo in config.Props.Volcanos) + foreach (var volcanoInfo in config.Props.Volcanoes) { VolcanoBuilder.Make(go, sector, volcanoInfo); } diff --git a/NewHorizons/Builder/Props/VolcanoBuilder.cs b/NewHorizons/Builder/Props/VolcanoBuilder.cs index 6526c6b3..172f45a1 100644 --- a/NewHorizons/Builder/Props/VolcanoBuilder.cs +++ b/NewHorizons/Builder/Props/VolcanoBuilder.cs @@ -17,6 +17,7 @@ namespace NewHorizons.Builder.Props var launcherGO = prefab.InstantiateInactive(); launcherGO.transform.parent = sector.transform; launcherGO.transform.localPosition = info.position == null ? Vector3.zero : (Vector3) info.position; + launcherGO.transform.rotation = Quaternion.FromToRotation(launcherGO.transform.TransformDirection(Vector3.up), ((Vector3)info.position).normalized).normalized; launcherGO.name = "MeteorLauncher"; var meteorLauncher = launcherGO.GetComponent(); @@ -24,30 +25,49 @@ namespace NewHorizons.Builder.Props meteorLauncher._detectableFluid = null; meteorLauncher._detectableField = null; - meteorLauncher._launchDirection = info.position == null ? Vector3.up : ((Vector3)info.position).normalized; + meteorLauncher._launchDirection = Vector3.up; - var meteorPrefab = GameObject.Instantiate(meteorLauncher._meteorPrefab); - FixMeteor(meteorPrefab, info); + meteorLauncher._dynamicProbability = 0f; - meteorLauncher._meteorPrefab = meteorPrefab; + meteorLauncher._minLaunchSpeed = info.minLaunchSpeed; + meteorLauncher._maxLaunchSpeed = info.maxLaunchSpeed; + meteorLauncher._minInterval = info.minInterval; + meteorLauncher._maxInterval = info.maxInterval; launcherGO.SetActive(true); - // Kill the prefab when its done with it - Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => meteorPrefab.SetActive(false)); + // Have to null check else it breaks on reload configs + Main.Instance.ModHelper.Events.Unity.RunWhen(() => Main.IsSystemReady && meteorLauncher._meteorPool != null, () => { + foreach (var meteor in meteorLauncher._meteorPool) + { + FixMeteor(meteor, info); + } + }); } - private static void FixMeteor(GameObject meteor, PropModule.VolcanoInfo info) + private static void FixMeteor(MeteorController meteor, PropModule.VolcanoInfo info) { var mat = meteor.GetComponentInChildren().material; mat.SetColor("_Color", info.stoneTint == null ? defaultStoneTint : info.stoneTint.ToColor()); mat.SetColor("_EmissionColor", info.lavaTint == null ? defaultLavaTint : info.lavaTint.ToColor()); - var detectors = meteor.transform.Find("ConstantDetectors"); + var detectors = meteor.transform.Find("ConstantDetectors").gameObject; GameObject.Destroy(detectors.GetComponent()); GameObject.Destroy(detectors.GetComponent()); - detectors.gameObject.AddComponent(); + var forceDetector = detectors.gameObject.AddComponent(); detectors.gameObject.AddComponent(); + + detectors.layer = LayerMask.NameToLayer("BasicDetector"); + + var sphere = detectors.AddComponent(); + sphere.radius = 1; + + var sphere2 = detectors.AddComponent(); + sphere2._collisionMode = Shape.CollisionMode.Detector; + sphere2.radius = 1; + + forceDetector._collider = sphere; + forceDetector._shape = sphere2; } } } diff --git a/NewHorizons/External/PropModule.cs b/NewHorizons/External/PropModule.cs index cc60bdf9..ca037ae5 100644 --- a/NewHorizons/External/PropModule.cs +++ b/NewHorizons/External/PropModule.cs @@ -14,7 +14,7 @@ namespace NewHorizons.External public RaftInfo[] Rafts; public GeyserInfo[] Geysers; public TornadoInfo[] Tornados; - public VolcanoInfo[] Volcanos; + public VolcanoInfo[] Volcanoes; public DialogueInfo[] Dialogue; public RevealInfo[] Reveal; public EntryLocationInfo[] EntryLocation; @@ -67,6 +67,10 @@ namespace NewHorizons.External public MVector3 position = null; public MColor stoneTint = null; public MColor lavaTint = null; + public float minLaunchSpeed = 50f; + public float maxLaunchSpeed = 150f; + public float minInterval = 5f; + public float maxInterval = 20f; } public class DialogueInfo diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index ed69b1f5..83d571f0 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -135,6 +135,7 @@ namespace NewHorizons SearchUtilities.ClearCache(); ImageUtilities.ClearCache(); AudioUtilities.ClearCache(); + IsSystemReady = false; } private void OnSceneLoaded(Scene scene, LoadSceneMode mode) diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index 20f2a2eb..5eee3458 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -3,7 +3,7 @@ "author": "xen, Bwc9876, & Book", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "0.10.3", + "version": "0.11.0", "owmlVersion": "2.1.0", "dependencies": [ "PacificEngine.OW_CommonResources" ], "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "Vesper.OuterWildsMMO", "Vesper.AutoResume" ], diff --git a/NewHorizons/schema.json b/NewHorizons/schema.json index e6c30389..218d000a 100644 --- a/NewHorizons/schema.json +++ b/NewHorizons/schema.json @@ -760,6 +760,48 @@ } } } + }, + "volcanoes": { + "type": "array", + "description": "A set of meteor-spewing volcanoes", + "items": { + "type": "object", + "additionalProperties": false, + "properties": { + "position": { + "$ref": "#/$defs/vector3", + "description": "The position of this volcano." + }, + "stoneTint": { + "$ref": "#/$defs/color", + "description": "The colour of the meteor's stone." + }, + "lavaTint": { + "$ref": "#/$defs/color", + "description": "The colour of the meteor's lava." + }, + "minLaunchSpeed": { + "type": "number", + "description": "Minimum random speed at which meteors are launched.", + "default": 50 + }, + "maxLaunchSpeed": { + "type": "number", + "description": "Maximum random speed at which meteors are launched.", + "default": 150 + }, + "minInterval": { + "type": "number", + "description": "Minimum time between meteor launches.", + "default": 5 + }, + "maxInterval": { + "type": "number", + "description": "Maximum time between meteor launches." + "default": 20 + } + } + } } } },