Added OnInfiltrated function to lua
This commit is contained in:
@@ -278,6 +278,13 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
context.World.ActorMap.RemoveCellTrigger(id);
|
context.World.ActorMap.RemoveCellTrigger(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Desc("Call a function when this actor is infiltrated. The callback function " +
|
||||||
|
"will be called as func(Actor self, Actor infiltrator).")]
|
||||||
|
public void OnInfiltrated(Actor a, LuaFunction func)
|
||||||
|
{
|
||||||
|
GetScriptTriggers(a).RegisterCallback(Trigger.OnInfiltrated, func, context);
|
||||||
|
}
|
||||||
|
|
||||||
[Desc("Removes all triggers from this actor.")]
|
[Desc("Removes all triggers from this actor.")]
|
||||||
public void ClearAll(Actor a)
|
public void ClearAll(Actor a)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ using OpenRA.Traits;
|
|||||||
namespace OpenRA.Mods.RA.Scripting
|
namespace OpenRA.Mods.RA.Scripting
|
||||||
{
|
{
|
||||||
public enum Trigger { OnIdle, OnDamaged, OnKilled, OnProduction, OnOtherProduction, OnPlayerWon, OnPlayerLost,
|
public enum Trigger { OnIdle, OnDamaged, OnKilled, OnProduction, OnOtherProduction, OnPlayerWon, OnPlayerLost,
|
||||||
OnObjectiveAdded, OnObjectiveCompleted, OnObjectiveFailed, OnCapture, OnAddedToWorld, OnRemovedFromWorld };
|
OnObjectiveAdded, OnObjectiveCompleted, OnObjectiveFailed, OnCapture, OnInfiltrated, OnAddedToWorld, OnRemovedFromWorld };
|
||||||
|
|
||||||
[Desc("Allows map scripts to attach triggers to this actor via the Triggers global.")]
|
[Desc("Allows map scripts to attach triggers to this actor via the Triggers global.")]
|
||||||
public class ScriptTriggersInfo : ITraitInfo
|
public class ScriptTriggersInfo : ITraitInfo
|
||||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
public object Create(ActorInitializer init) { return new ScriptTriggers(init.world); }
|
public object Create(ActorInitializer init) { return new ScriptTriggers(init.world); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, INotifyOtherProduction, INotifyObjectivesUpdated, INotifyCapture, INotifyAddedToWorld, INotifyRemovedFromWorld, IDisposable
|
public sealed class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, INotifyOtherProduction, INotifyObjectivesUpdated, INotifyCapture, INotifyInfiltrated, INotifyAddedToWorld, INotifyRemovedFromWorld, IDisposable
|
||||||
{
|
{
|
||||||
readonly World world;
|
readonly World world;
|
||||||
|
|
||||||
@@ -238,6 +238,24 @@ namespace OpenRA.Mods.RA.Scripting
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Infiltrated(Actor self, Actor infiltrator)
|
||||||
|
{
|
||||||
|
foreach (var f in Triggers[Trigger.OnInfiltrated])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var a = self.ToLuaValue(f.Second))
|
||||||
|
using (var b = infiltrator.ToLuaValue(f.Second))
|
||||||
|
f.First.Call(a, b).Dispose();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
f.Second.FatalError(ex.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void AddedToWorld(Actor self)
|
public void AddedToWorld(Actor self)
|
||||||
{
|
{
|
||||||
foreach (var f in Triggers[Trigger.OnAddedToWorld])
|
foreach (var f in Triggers[Trigger.OnAddedToWorld])
|
||||||
|
|||||||
Reference in New Issue
Block a user