Introduce OnDiscovered and OnPlayerDiscovered Lua triggers
This commit is contained in:
@@ -406,6 +406,20 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
GetScriptTriggers(a).RegisterCallback(Trigger.OnInfiltrated, func, Context);
|
GetScriptTriggers(a).RegisterCallback(Trigger.OnInfiltrated, func, Context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Desc("Call a function when this actor is discovered by an enemy or a player with a Neutral stance. " +
|
||||||
|
"The callback function will be called as func(Actor discovered, Player discoverer)")]
|
||||||
|
public void OnDiscovered(Actor a, LuaFunction func)
|
||||||
|
{
|
||||||
|
GetScriptTriggers(a).RegisterCallback(Trigger.OnDiscovered, func, Context);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Desc("Call a function when this player is discovered by an enemy or neutral player. " +
|
||||||
|
"The callback function will be called as func(Player discovered, Player discoverer, Actor discoveredActor)")]
|
||||||
|
public void OnPlayerDiscovered(Player discovered, LuaFunction func)
|
||||||
|
{
|
||||||
|
GetScriptTriggers(discovered.PlayerActor).RegisterCallback(Trigger.OnPlayerDiscovered, func, Context);
|
||||||
|
}
|
||||||
|
|
||||||
[Desc("Removes all triggers from this actor." +
|
[Desc("Removes all triggers from this actor." +
|
||||||
"Note that the removal will only take effect at the end of a tick, " +
|
"Note that the removal will only take effect at the end of a tick, " +
|
||||||
"so you must not add new triggers at the same time that you are calling this function.")]
|
"so you must not add new triggers at the same time that you are calling this function.")]
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
public enum Trigger
|
public enum Trigger
|
||||||
{
|
{
|
||||||
OnIdle, OnDamaged, OnKilled, OnProduction, OnOtherProduction, OnPlayerWon, OnPlayerLost,
|
OnIdle, OnDamaged, OnKilled, OnProduction, OnOtherProduction, OnPlayerWon, OnPlayerLost,
|
||||||
OnObjectiveAdded, OnObjectiveCompleted, OnObjectiveFailed, OnCapture, OnInfiltrated, OnAddedToWorld, OnRemovedFromWorld
|
OnObjectiveAdded, OnObjectiveCompleted, OnObjectiveFailed, OnCapture, OnInfiltrated,
|
||||||
|
OnAddedToWorld, OnRemovedFromWorld, OnDiscovered, OnPlayerDiscovered
|
||||||
}
|
}
|
||||||
|
|
||||||
[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.")]
|
||||||
@@ -31,7 +32,7 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
}
|
}
|
||||||
|
|
||||||
public sealed class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, INotifyOtherProduction,
|
public sealed class ScriptTriggers : INotifyIdle, INotifyDamage, INotifyKilled, INotifyProduction, INotifyOtherProduction,
|
||||||
INotifyObjectivesUpdated, INotifyCapture, INotifyInfiltrated, INotifyAddedToWorld, INotifyRemovedFromWorld, IDisposable
|
INotifyObjectivesUpdated, INotifyCapture, INotifyInfiltrated, INotifyAddedToWorld, INotifyRemovedFromWorld, IDisposable, INotifyDiscovered
|
||||||
{
|
{
|
||||||
readonly World world;
|
readonly World world;
|
||||||
|
|
||||||
@@ -324,6 +325,40 @@ namespace OpenRA.Mods.Common.Scripting
|
|||||||
OnOtherProducedInternal(producee, produced);
|
OnOtherProducedInternal(producee, produced);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OnDiscovered(Actor self, Player discoverer, bool playNotification)
|
||||||
|
{
|
||||||
|
foreach (var f in Triggers[Trigger.OnDiscovered])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var a = self.ToLuaValue(f.Second))
|
||||||
|
using (var b = discoverer.ToLuaValue(f.Second))
|
||||||
|
f.First.Call(a, b).Dispose();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
f.Second.FatalError(ex.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var f in Triggers[Trigger.OnPlayerDiscovered])
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var a = self.Owner.ToLuaValue(f.Second))
|
||||||
|
using (var b = discoverer.ToLuaValue(f.Second))
|
||||||
|
using (var c = self.ToLuaValue(f.Second))
|
||||||
|
f.First.Call(a, b, c).Dispose();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
f.Second.FatalError(ex.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Clear(Trigger trigger)
|
public void Clear(Trigger trigger)
|
||||||
{
|
{
|
||||||
world.AddFrameEndTask(w =>
|
world.AddFrameEndTask(w =>
|
||||||
|
|||||||
Reference in New Issue
Block a user