Add an option to check if an actor can be captured via Lua

This commit is contained in:
Azarus
2022-09-09 20:54:03 +07:00
committed by Gustas
parent 3f2007cd2c
commit 77b06ac9f7

View File

@@ -9,7 +9,6 @@
*/ */
#endregion #endregion
using Eluant;
using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits; using OpenRA.Mods.Common.Traits;
using OpenRA.Scripting; using OpenRA.Scripting;
@@ -31,12 +30,18 @@ namespace OpenRA.Mods.Common.Scripting
[Desc("Captures the target actor.")] [Desc("Captures the target actor.")]
public void Capture(Actor target) public void Capture(Actor target)
{ {
var targetManager = target.TraitOrDefault<CaptureManager>(); if (!CanCapture(target))
if (targetManager == null || !targetManager.CanBeTargetedBy(target, Self, captureManager)) return;
throw new LuaException($"Actor '{Self}' cannot capture actor '{target}'!");
// NB: Scripted actions get no visible targetlines. // NB: Scripted actions get no visible targetlines.
Self.QueueActivity(new CaptureActor(Self, Target.FromActor(target), null)); 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<CaptureManager>();
return targetManager != null && targetManager.CanBeTargetedBy(target, Self, captureManager);
}
} }
} }