Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jan 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
}
}