From 2ac85ac61dd031faec621e9c78f061611e005deb Mon Sep 17 00:00:00 2001 From: dnqbob Date: Fri, 28 Jul 2023 14:32:24 +0800 Subject: [PATCH] Add InstantlyRepairsProperties --- .../Activities/InstantRepair.cs | 5 ++- .../Properties/InstantlyRepairsProperties.cs | 41 +++++++++++++++++++ OpenRA.Mods.Common/Traits/InstantlyRepairs.cs | 2 +- 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 OpenRA.Mods.Common/Scripting/Properties/InstantlyRepairsProperties.cs diff --git a/OpenRA.Mods.Common/Activities/InstantRepair.cs b/OpenRA.Mods.Common/Activities/InstantRepair.cs index 2b525dc800..c415ed1434 100644 --- a/OpenRA.Mods.Common/Activities/InstantRepair.cs +++ b/OpenRA.Mods.Common/Activities/InstantRepair.cs @@ -10,6 +10,7 @@ #endregion using OpenRA.Mods.Common.Traits; +using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Activities @@ -22,8 +23,8 @@ namespace OpenRA.Mods.Common.Activities IHealth enterHealth; InstantlyRepairable enterInstantlyRepariable; - public InstantRepair(Actor self, in Target target, InstantlyRepairsInfo info) - : base(self, target, info.TargetLineColor) + public InstantRepair(Actor self, in Target target, InstantlyRepairsInfo info, Color? targetLineColor) + : base(self, target, targetLineColor) { this.info = info; } diff --git a/OpenRA.Mods.Common/Scripting/Properties/InstantlyRepairsProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/InstantlyRepairsProperties.cs new file mode 100644 index 0000000000..f4efce2184 --- /dev/null +++ b/OpenRA.Mods.Common/Scripting/Properties/InstantlyRepairsProperties.cs @@ -0,0 +1,41 @@ +#region Copyright & License Information +/* + * Copyright (c) The OpenRA Developers and Contributors + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Linq; +using OpenRA.Mods.Common.Activities; +using OpenRA.Mods.Common.Traits; +using OpenRA.Scripting; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Scripting +{ + [ScriptPropertyGroup("Ability")] + public class InstantlyRepairsProperties : ScriptActorProperties, Requires, Requires + { + readonly InstantlyRepairs[] instantlyRepairs; + + public InstantlyRepairsProperties(ScriptContext context, Actor self) + : base(context, self) + { + instantlyRepairs = Self.TraitsImplementing().ToArray(); + } + + [ScriptActorPropertyActivity] + [Desc("Enter the target actor to repair it instantly.")] + public void InstantlyRepair(Actor target) + { + // NB: Scripted actions get no visible targetlines. + var repair = instantlyRepairs.FirstEnabledConditionalTraitOrDefault(); + if (repair != null) + Self.QueueActivity(new InstantRepair(Self, Target.FromActor(target), repair.Info, null)); + } + } +} diff --git a/OpenRA.Mods.Common/Traits/InstantlyRepairs.cs b/OpenRA.Mods.Common/Traits/InstantlyRepairs.cs index d76822afd2..cd67e36d13 100644 --- a/OpenRA.Mods.Common/Traits/InstantlyRepairs.cs +++ b/OpenRA.Mods.Common/Traits/InstantlyRepairs.cs @@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Traits if (order.OrderString != "InstantRepair" || !IsValidOrder(order)) return; - self.QueueActivity(order.Queued, new InstantRepair(self, order.Target, Info)); + self.QueueActivity(order.Queued, new InstantRepair(self, order.Target, Info, Info.TargetLineColor)); self.ShowTargetLines(); }