NotifyBlocker extension method for Actor

This commit is contained in:
atimoschenkow
2015-01-10 12:01:29 +01:00
parent ae03fa9af5
commit cefd554a5e
4 changed files with 25 additions and 23 deletions

View File

@@ -8,7 +8,9 @@
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
@@ -77,5 +79,24 @@ namespace OpenRA.Mods.Common
return Target.Invalid;
}
public static void NotifyBlocker(this Actor self, IEnumerable<Actor> blockers)
{
foreach (var blocker in blockers)
{
foreach (var moveBlocked in blocker.TraitsImplementing<INotifyBlockingMove>())
moveBlocked.OnNotifyBlockingMove(blocker, self);
}
}
public static void NotifyBlocker(this Actor self, CPos position)
{
NotifyBlocker(self, self.World.ActorMap.GetUnitsAt(position));
}
public static void NotifyBlocker(this Actor self, IEnumerable<CPos> positions)
{
NotifyBlocker(self, positions.SelectMany(p => self.World.ActorMap.GetUnitsAt(p)));
}
}
}