Allow setting hazard volume info on tornados #496

This commit is contained in:
Nick 2023-07-20 19:42:20 -04:00
parent 212e16b5f0
commit f62c8ba377
3 changed files with 53 additions and 10 deletions

View File

@ -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);
}

View File

@ -21,23 +21,32 @@ namespace NewHorizons.Builder.Volumes
var owTriggerVolume = go.AddComponent<OWTriggerVolume>();
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<RiverHeatHazardVolume>();
}
else if (info.type == HazardVolumeInfo.HazardType.HEAT)
else if (type == HazardVolumeInfo.HazardType.HEAT)
{
hazardVolume = go.AddComponent<HeatHazardVolume>();
}
else if (info.type == HazardVolumeInfo.HazardType.DARKMATTER)
else if (type == HazardVolumeInfo.HazardType.DARKMATTER)
{
hazardVolume = go.AddComponent<DarkMatterVolume>();
var visorFrostEffectVolume = go.AddComponent<VisorFrostEffectVolume>();
visorFrostEffectVolume._frostRate = 0.5f;
visorFrostEffectVolume._maxFrost = 0.91f;
var water = planetGO.GetComponentsInChildren<RadialFluidVolume>().FirstOrDefault(x => x._fluidType == FluidVolume.Type.WATER);
var water = owrb.GetComponentsInChildren<RadialFluidVolume>().FirstOrDefault(x => x._fluidType == FluidVolume.Type.WATER);
if (water != null)
{
var submerge = go.AddComponent<DarkMatterSubmergeController>();
@ -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>();
electricityVolume._shockAudioPool = new OWAudioSource[0];
@ -67,15 +76,17 @@ namespace NewHorizons.Builder.Volumes
else
{
var simpleHazardVolume = go.AddComponent<SimpleHazardVolume>();
simpleHazardVolume._type = EnumUtils.Parse<HazardVolume.HazardType>(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<InstantDamageType>(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;
}

View File

@ -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.
/// </summary>
[DefaultValue("cloud")] public NHFluidType fluidType = NHFluidType.CLOUD;
/// <summary>
/// The type of hazard for this volume. Leave empty for this tornado to not be hazardous.
/// </summary>
public HazardVolumeInfo.HazardType? hazardType;
/// <summary>
/// The amount of damage you will take per second while inside this tornado. Only used it hazardType is set.
/// </summary>
[DefaultValue(10f)] public float damagePerSecond = 10f;
/// <summary>
/// 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.
/// </summary>
public HazardVolumeInfo.InstantDamageType? firstContactDamageType;
/// <summary>
/// The amount of damage you will take when you first touch this volume. Only relevant if firstContactDamageType is set.
/// </summary>
[DefaultValue(10f)] public float firstContactDamage = 10f;
}
}