Expose a Attack method to lua
This commit is contained in:
@@ -23,11 +23,13 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
public class CombatProperties : ScriptActorProperties, Requires<AttackBaseInfo>, Requires<IMoveInfo>
|
||||
{
|
||||
readonly IMove move;
|
||||
readonly AttackBase attackBase;
|
||||
|
||||
public CombatProperties(ScriptContext context, Actor self)
|
||||
: base(context, self)
|
||||
{
|
||||
move = self.Trait<IMove>();
|
||||
attackBase = self.Trait<AttackBase>();
|
||||
}
|
||||
|
||||
[ScriptActorPropertyActivity]
|
||||
@@ -73,5 +75,18 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
using (var f = func.CopyReference() as LuaFunction)
|
||||
Self.QueueActivity(new CallFunc(() => PatrolUntil(waypoints, f, wait)));
|
||||
}
|
||||
|
||||
[Desc("Attack the target actor. The target actor needs to be visible.")]
|
||||
public void Attack(Actor targetActor, bool allowMove = true)
|
||||
{
|
||||
var target = Target.FromActor(targetActor);
|
||||
if (!target.IsValidFor(Self) || target.Type == TargetType.FrozenActor)
|
||||
Log.Write("lua", "{1} is an invalid target for {0}!", Self, targetActor);
|
||||
|
||||
if (!targetActor.HasTrait<FrozenUnderFog>() && !Self.Owner.CanTargetActor(targetActor))
|
||||
Log.Write("lua", "{1} is not revealed for player {0}!", Self.Owner, targetActor);
|
||||
|
||||
attackBase.AttackTarget(target, true, allowMove);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,17 +35,4 @@ namespace OpenRA.Mods.Common.Scripting
|
||||
Self.QueueActivity(new ReturnToBase(Self, airfield));
|
||||
}
|
||||
}
|
||||
|
||||
[ScriptPropertyGroup("Combat")]
|
||||
public class PlaneCombatProperties : ScriptActorProperties, Requires<AttackPlaneInfo>
|
||||
{
|
||||
public PlaneCombatProperties(ScriptContext context, Actor self)
|
||||
: base(context, self) { }
|
||||
|
||||
[Desc("Fly an attack against the target actor.")]
|
||||
public void Attack(Actor target)
|
||||
{
|
||||
Self.QueueActivity(new FlyAttack(Self, Target.FromActor(target)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user