Add hazard volumes

This commit is contained in:
Noah Pilarski 2022-08-31 13:44:35 -04:00
parent 0921b23f8f
commit 2f7eb0c695
4 changed files with 109 additions and 2 deletions

View File

@ -0,0 +1,40 @@
using NewHorizons.External.Modules;
using OWML.Common;
using OWML.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace NewHorizons.Builder.Volumes
{
public static class HazardVolumeBuilder
{
public static HazardVolume Make(GameObject planetGO, Sector sector, OWRigidbody owrb, VolumesModule.HazardVolumeInfo info, IModBehaviour mod)
{
var go = new GameObject("HazardVolume");
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<SphereShape>();
shape.radius = info.radius;
var owTriggerVolume = go.AddComponent<OWTriggerVolume>();
owTriggerVolume._shape = shape;
var hazardVolume = go.AddComponent<SimpleHazardVolume>();
hazardVolume._attachedBody = owrb;
hazardVolume._type = EnumUtils.Parse<HazardVolume.HazardType>(info.type.ToString(), HazardVolume.HazardType.GENERAL);
hazardVolume._damagePerSecond = info.damagePerSecond;
hazardVolume._firstContactDamageType = EnumUtils.Parse<InstantDamageType>(info.firstContactDamage.ToString(), InstantDamageType.Impact);
hazardVolume._firstContactDamage = info.firstContactDamage;
go.SetActive(true);
return hazardVolume;
}
}
}

View File

@ -12,7 +12,7 @@ namespace NewHorizons.Builder.Volumes
{
public static class VolumesBuildManager
{
public static void Make(GameObject go, Sector sector, PlanetConfig config, IModBehaviour mod)
public static void Make(GameObject go, Sector sector, OWRigidbody planetBody, PlanetConfig config, IModBehaviour mod)
{
if (config.Volumes.revealVolumes != null)
{
@ -42,6 +42,13 @@ namespace NewHorizons.Builder.Volumes
NotificationVolumeBuilder.Make(go, sector, notificationVolume, mod);
}
}
if (config.Volumes.hazardVolumes != null)
{
foreach (var hazardVolume in config.Volumes.hazardVolumes)
{
HazardVolumeBuilder.Make(go, sector, planetBody, hazardVolume, mod);
}
}
}
}
}

View File

@ -19,6 +19,11 @@ namespace NewHorizons.External.Modules
/// </summary>
public AudioVolumeInfo[] audioVolumes;
/// <summary>
/// Add hazard volumes to this planet
/// </summary>
public HazardVolumeInfo[] hazardVolumes;
/// <summary>
/// Add notification volumes to this planet
/// </summary>
@ -158,6 +163,61 @@ namespace NewHorizons.External.Modules
[EnumMember(Value = @"player")] Player = 2,
}
}
[JsonObject]
public class HazardVolumeInfo
{
/// <summary>
/// The location of this hazard volume. Optional (will default to 0,0,0).
/// </summary>
public MVector3 position;
/// <summary>
/// The radius of this hazard volume.
/// </summary>
public float radius;
/// <summary>
/// The type of hazard for this volume.
/// </summary>
[DefaultValue("general")] public HazardType type = HazardType.GENERAL;
/// <summary>
/// The amount of damage you will take per second while inside this volume.
/// </summary>
[DefaultValue(10f)] public float damagePerSecond = 10f;
/// <summary>
/// The type of damage you will take when you first touch this volume.
/// </summary>
[DefaultValue("impact")] public InstantDamageType _firstContactDamageType = InstantDamageType.Impact;
/// <summary>
/// The amount of damage you will take when you first touch this volume.
/// </summary>
public float firstContactDamage;
[JsonConverter(typeof(StringEnumConverter))]
public enum HazardType
{
[EnumMember(Value = @"none")] NONE = 0,
[EnumMember(Value = @"general")] GENERAL = 1,
[EnumMember(Value = @"darkMatter")] DARKMATTER = 2,
[EnumMember(Value = @"heat")] HEAT = 4,
[EnumMember(Value = @"fire")] FIRE = 8,
[EnumMember(Value = @"sandfall")] SANDFALL = 16,
[EnumMember(Value = @"electricity")] ELECTRICITY = 32,
[EnumMember(Value = @"rapids")] RAPIDS = 64
}
[JsonConverter(typeof(StringEnumConverter))]
public enum InstantDamageType
{
[EnumMember(Value = @"impact")] Impact,
[EnumMember(Value = @"puncture")] Puncture,
[EnumMember(Value = @"electrical")] Electrical
}
}
}
[JsonConverter(typeof(StringEnumConverter))]

View File

@ -611,7 +611,7 @@ namespace NewHorizons.Handlers
if (body.Config.Volumes != null)
{
VolumesBuildManager.Make(go, sector, body.Config, body.Mod);
VolumesBuildManager.Make(go, sector, rb, body.Config, body.Mod);
}
if (body.Config.Funnel != null)