Skip to content

Commit

Permalink
Add an option to check if an actor can be captured via Lua
Browse files Browse the repository at this point in the history
  • Loading branch information
azarus authored and PunkPun committed Jan 30, 2023
1 parent 393fd58 commit 7ad6cfd
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions OpenRA.Mods.Common/Scripting/Properties/CaptureProperties.cs
Expand Up @@ -9,7 +9,6 @@
*/
#endregion

using Eluant;
using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Traits;
using OpenRA.Scripting;
Expand All @@ -31,12 +30,18 @@ public CaptureProperties(ScriptContext context, Actor self)
[Desc("Captures the target actor.")]
public void Capture(Actor target)
{
var targetManager = target.TraitOrDefault<CaptureManager>();
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<CaptureManager>();
return targetManager != null && targetManager.CanBeTargetedBy(target, Self, captureManager);
}
}
}

0 comments on commit 7ad6cfd

Please sign in to comment.