diff --git a/NewHorizons/Builder/Props/TornadoBuilder.cs b/NewHorizons/Builder/Props/TornadoBuilder.cs index 90987169..1aa64134 100644 --- a/NewHorizons/Builder/Props/TornadoBuilder.cs +++ b/NewHorizons/Builder/Props/TornadoBuilder.cs @@ -1,3 +1,4 @@ +using NewHorizons.Builder.Volumes; using NewHorizons.Components.Props; using NewHorizons.External.Modules.Props; using NewHorizons.Handlers; @@ -169,6 +170,11 @@ namespace NewHorizons.Builder.Props ApplyWanderer(tornadoGO, planetGO, info); } + if (info.hazardType != null || info.firstContactDamageType != null) + { + HazardVolumeBuilder.AddHazardVolume(fluidGO.gameObject, sector, planetGO.GetAttachedOWRigidbody(), info.hazardType, info.firstContactDamageType, info.firstContactDamage, info.damagePerSecond); + } + soundGO.SetActive(true); tornadoGO.SetActive(true); } @@ -228,6 +234,11 @@ namespace NewHorizons.Builder.Props ApplyWanderer(hurricaneGO, planetGO, info); } + if (info.hazardType != null || info.firstContactDamageType != null) + { + HazardVolumeBuilder.AddHazardVolume(fluidVolume.gameObject, sector, planetGO.GetAttachedOWRigidbody(), info.hazardType, info.firstContactDamageType, info.firstContactDamage, info.damagePerSecond); + } + hurricaneGO.SetActive(true); } diff --git a/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs b/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs index a4a7e795..f26f0c2e 100644 --- a/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/HazardVolumeBuilder.cs @@ -21,23 +21,32 @@ namespace NewHorizons.Builder.Volumes var owTriggerVolume = go.AddComponent(); owTriggerVolume._shape = shape; + var volume = AddHazardVolume(go, sector, owrb, info.type, info.firstContactDamageType, info.firstContactDamage, info.damagePerSecond); + + go.SetActive(true); + + return volume; + } + + public static HazardVolume AddHazardVolume(GameObject go, Sector sector, OWRigidbody owrb, HazardVolumeInfo.HazardType? type, HazardVolumeInfo.InstantDamageType? firstContactDamageType, float firstContactDamage, float damagePerSecond) + { HazardVolume hazardVolume = null; - if (info.type == HazardVolumeInfo.HazardType.RIVERHEAT) + if (type == HazardVolumeInfo.HazardType.RIVERHEAT) { hazardVolume = go.AddComponent(); } - else if (info.type == HazardVolumeInfo.HazardType.HEAT) + else if (type == HazardVolumeInfo.HazardType.HEAT) { hazardVolume = go.AddComponent(); } - else if (info.type == HazardVolumeInfo.HazardType.DARKMATTER) + else if (type == HazardVolumeInfo.HazardType.DARKMATTER) { hazardVolume = go.AddComponent(); var visorFrostEffectVolume = go.AddComponent(); visorFrostEffectVolume._frostRate = 0.5f; visorFrostEffectVolume._maxFrost = 0.91f; - var water = planetGO.GetComponentsInChildren().FirstOrDefault(x => x._fluidType == FluidVolume.Type.WATER); + var water = owrb.GetComponentsInChildren().FirstOrDefault(x => x._fluidType == FluidVolume.Type.WATER); if (water != null) { var submerge = go.AddComponent(); @@ -58,7 +67,7 @@ namespace NewHorizons.Builder.Volumes submerge._fluidDetector = detector; } } - else if (info.type == HazardVolumeInfo.HazardType.ELECTRICITY) + else if (type == HazardVolumeInfo.HazardType.ELECTRICITY) { var electricityVolume = go.AddComponent(); electricityVolume._shockAudioPool = new OWAudioSource[0]; @@ -67,15 +76,17 @@ namespace NewHorizons.Builder.Volumes else { var simpleHazardVolume = go.AddComponent(); - simpleHazardVolume._type = EnumUtils.Parse(info.type.ToString(), HazardVolume.HazardType.GENERAL); + simpleHazardVolume._type = EnumUtils.Parse(type.ToString(), HazardVolume.HazardType.GENERAL); hazardVolume = simpleHazardVolume; } hazardVolume._attachedBody = owrb; - hazardVolume._damagePerSecond = info.damagePerSecond; - hazardVolume._firstContactDamageType = EnumUtils.Parse(info.firstContactDamageType.ToString(), InstantDamageType.Impact); - hazardVolume._firstContactDamage = info.firstContactDamage; + hazardVolume._damagePerSecond = type == null ? 0f : damagePerSecond; - go.SetActive(true); + if (firstContactDamageType != null) + { + hazardVolume._firstContactDamageType = EnumUtils.Parse(firstContactDamageType.ToString(), InstantDamageType.Impact); + hazardVolume._firstContactDamage = firstContactDamage; + } return hazardVolume; } diff --git a/NewHorizons/External/Modules/Props/TornadoInfo.cs b/NewHorizons/External/Modules/Props/TornadoInfo.cs index 6ec121c4..18eb1f50 100644 --- a/NewHorizons/External/Modules/Props/TornadoInfo.cs +++ b/NewHorizons/External/Modules/Props/TornadoInfo.cs @@ -1,3 +1,4 @@ +using NewHorizons.External.Modules.Volumes.VolumeInfos; using NewHorizons.External.SerializableData; using NewHorizons.External.SerializableEnums; using Newtonsoft.Json; @@ -69,6 +70,26 @@ namespace NewHorizons.External.Modules.Props /// Fluid type for sounds/effects when colliding with this tornado. /// [DefaultValue("cloud")] public NHFluidType fluidType = NHFluidType.CLOUD; + + /// + /// The type of hazard for this volume. Leave empty for this tornado to not be hazardous. + /// + public HazardVolumeInfo.HazardType? hazardType; + + /// + /// The amount of damage you will take per second while inside this tornado. Only used it hazardType is set. + /// + [DefaultValue(10f)] public float damagePerSecond = 10f; + + /// + /// The type of damage you will take when you first touch this volume. Leave empty for this tornado to not cause damage on first contact. + /// + public HazardVolumeInfo.InstantDamageType? firstContactDamageType; + + /// + /// The amount of damage you will take when you first touch this volume. Only relevant if firstContactDamageType is set. + /// + [DefaultValue(10f)] public float firstContactDamage = 10f; } }