Add Actor.OnDamaged

Allows the AI to react to its units being attacked.
This commit is contained in:
Oliver Brakmann
2014-02-08 16:04:29 +01:00
parent ba1558259b
commit bfc34df581
2 changed files with 11 additions and 1 deletions

View File

@@ -15,12 +15,13 @@ namespace OpenRA.Mods.RA.Scripting
{ {
public class LuaScriptEventsInfo : TraitInfo<LuaScriptEvents> { } public class LuaScriptEventsInfo : TraitInfo<LuaScriptEvents> { }
public class LuaScriptEvents : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyCapture public class LuaScriptEvents : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyCapture, INotifyDamage
{ {
public event Action<Actor, AttackInfo> OnKilled = (self, e) => { }; public event Action<Actor, AttackInfo> OnKilled = (self, e) => { };
public event Action<Actor> OnAddedToWorld = self => { }; public event Action<Actor> OnAddedToWorld = self => { };
public event Action<Actor> OnRemovedFromWorld = self => { }; public event Action<Actor> OnRemovedFromWorld = self => { };
public event Action<Actor, Actor, Player, Player> OnCaptured = (self, captor, oldOwner, newOwner) => { }; public event Action<Actor, Actor, Player, Player> OnCaptured = (self, captor, oldOwner, newOwner) => { };
public event Action<Actor, AttackInfo> OnDamaged = (self, e) => { };
public void Killed(Actor self, AttackInfo e) public void Killed(Actor self, AttackInfo e)
{ {
@@ -41,5 +42,10 @@ namespace OpenRA.Mods.RA.Scripting
{ {
OnCaptured(self, captor, oldOwner, newOwner); OnCaptured(self, captor, oldOwner, newOwner);
} }
public void Damaged(Actor self, AttackInfo e)
{
OnDamaged(self, e);
}
} }
} }

View File

@@ -143,6 +143,10 @@ Actor.SetStance = function(actor, stance)
Internal.SetUnitStance(actor, stance) Internal.SetUnitStance(actor, stance)
end end
Actor.OnDamaged = function(actor, eh)
Actor.Trait(actor, "LuaScriptEvents").OnDamaged:Add(eh)
end
Actor.OnKilled = function(actor, eh) Actor.OnKilled = function(actor, eh)
Actor.Trait(actor, "LuaScriptEvents").OnKilled:Add(eh) Actor.Trait(actor, "LuaScriptEvents").OnKilled:Add(eh)
end end