From 77b06ac9f7b310adb5a9bb8f21d9029d6b382d18 Mon Sep 17 00:00:00 2001 From: Azarus Date: Fri, 9 Sep 2022 20:54:03 +0700 Subject: [PATCH] Add an option to check if an actor can be captured via Lua --- .../Scripting/Properties/CaptureProperties.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Scripting/Properties/CaptureProperties.cs b/OpenRA.Mods.Common/Scripting/Properties/CaptureProperties.cs index de6d0f0978..fc6c09262e 100644 --- a/OpenRA.Mods.Common/Scripting/Properties/CaptureProperties.cs +++ b/OpenRA.Mods.Common/Scripting/Properties/CaptureProperties.cs @@ -9,7 +9,6 @@ */ #endregion -using Eluant; using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Traits; using OpenRA.Scripting; @@ -31,12 +30,18 @@ namespace OpenRA.Mods.Common.Scripting [Desc("Captures the target actor.")] public void Capture(Actor target) { - var targetManager = target.TraitOrDefault(); - if (targetManager == null || !targetManager.CanBeTargetedBy(target, Self, captureManager)) - throw new LuaException($"Actor '{Self}' cannot capture actor '{target}'!"); + if (!CanCapture(target)) + return; // NB: Scripted actions get no visible targetlines. Self.QueueActivity(new CaptureActor(Self, Target.FromActor(target), null)); } + + [Desc("Checks if the target actor can be catured.")] + public bool CanCapture(Actor target) + { + var targetManager = target.TraitOrDefault(); + return targetManager != null && targetManager.CanBeTargetedBy(target, Self, captureManager); + } } }