diff --git a/NewHorizons/Builder/Volumes/RepairVolumeBuilder.cs b/NewHorizons/Builder/Volumes/RepairVolumeBuilder.cs new file mode 100644 index 00000000..7f51dc2c --- /dev/null +++ b/NewHorizons/Builder/Volumes/RepairVolumeBuilder.cs @@ -0,0 +1,52 @@ +using NewHorizons.Builder.Props; +using NewHorizons.Components.Volumes; +using NewHorizons.External.Modules.Props; +using NewHorizons.External.Modules.Volumes.VolumeInfos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Builder.Volumes +{ + public static class RepairVolumeBuilder + { + public static NHRepairReceiver Make(GameObject planetGO, Sector sector, RepairVolumeInfo info) + { + // Repair receivers aren't technically volumes (no OWTriggerVolume) so we don't use the VolumeBuilder + + var go = GeneralPropBuilder.MakeNew("RepairVolume", planetGO, sector, info); + + if (info.shape != null) + { + ShapeBuilder.AddCollider(go, info.shape); + } + else + { + var shapeInfo = new ShapeInfo() + { + type = ShapeType.Sphere, + useShape = false, + hasCollision = true, + radius = info.radius, + }; + ShapeBuilder.AddCollider(go, shapeInfo); + } + + var repairReceiver = go.AddComponent(); + repairReceiver.displayName = info.name ?? info.rename ?? go.name; + repairReceiver.repairFraction = info.repairFraction; + repairReceiver.repairTime = info.repairTime; + repairReceiver.repairDistance = info.repairDistance; + repairReceiver.damagedCondition = info.damagedCondition; + repairReceiver.repairedCondition = info.repairedCondition; + repairReceiver.revealFact = info.revealFact; + + go.SetActive(true); + + return repairReceiver; + } + } +} diff --git a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs index 161f1d6a..40303a0c 100644 --- a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs +++ b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs @@ -222,6 +222,13 @@ namespace NewHorizons.Builder.Volumes VolumeBuilder.MakeAndEnable(go, sector, referenceFrameBlockerVolume); } } + if (config.Volumes.repairVolumes != null) + { + foreach (var repairVolume in config.Volumes.repairVolumes) + { + RepairVolumeBuilder.Make(go, sector, repairVolume); + } + } if (config.Volumes.speedTrapVolumes != null) { foreach (var speedTrapVolume in config.Volumes.speedTrapVolumes) diff --git a/NewHorizons/External/Modules/Volumes/VolumeInfos/RepairVolumeInfo.cs b/NewHorizons/External/Modules/Volumes/VolumeInfos/RepairVolumeInfo.cs new file mode 100644 index 00000000..550e2a3d --- /dev/null +++ b/NewHorizons/External/Modules/Volumes/VolumeInfos/RepairVolumeInfo.cs @@ -0,0 +1,49 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.External.Modules.Volumes.VolumeInfos +{ + [JsonObject] + public class RepairVolumeInfo : VolumeInfo + { + /// + /// The name displayed in the UI when the player is repairing this object. If not set, the name of the object will be used. + /// + public string name; + + /// + /// How much of the object is initially repaired. 0 = not repaired, 1 = fully repaired. + /// + [DefaultValue(0f)] public float repairFraction = 0f; + + /// + /// The time it takes to repair the object. Defaults to 3 seconds. + /// + [DefaultValue(3f)] public float repairTime = 3f; + + /// + /// The distance from the object that the player can be to repair it. Defaults to 3 meters. + /// + [DefaultValue(3f)] public float repairDistance = 3f; + + /// + /// A dialogue condition that will be set while the object is damaged. It will be unset when the object is repaired. + /// + public string damagedCondition; + + /// + /// A dialogue condition that will be set when the object is repaired. It will be unset if the object is damaged again. + /// + public string repairedCondition; + + /// + /// A ship log fact that will be revealed when the object is repaired. + /// + public string revealFact; + } +} diff --git a/NewHorizons/External/Modules/Volumes/VolumesModule.cs b/NewHorizons/External/Modules/Volumes/VolumesModule.cs index 34795d15..800e94bd 100644 --- a/NewHorizons/External/Modules/Volumes/VolumesModule.cs +++ b/NewHorizons/External/Modules/Volumes/VolumesModule.cs @@ -85,6 +85,11 @@ namespace NewHorizons.External.Modules.Volumes /// public VolumeInfo[] referenceFrameBlockerVolumes; + /// + /// Add repair volumes to this planet. + /// + public RepairVolumeInfo[] repairVolumes; + /// /// Add triggers that reveal parts of the ship log on this planet. ///