/// <summary>
/// Activates AIs in range of the movement path.
/// </summary>
/// <param name="from"></param>
/// <param name="to"></param>
public void ActivateAis(Creature creature, Position from, Position to)
{
// Bounding rectangle
var minX = Math.Min(from.X, to.X) - VisibleRange;
var minY = Math.Min(from.Y, to.Y) - VisibleRange;
var maxX = Math.Max(from.X, to.X) + VisibleRange;
var maxY = Math.Max(from.Y, to.Y) + VisibleRange;
// Activation
_creaturesRWLS.EnterReadLock();
try
{
foreach (NPC npc in _creatures.Values.Where(a => a.Is(EntityType.NPC)))
{
if (npc.AI == null)
continue;
var pos = npc.GetPosition();
if (!(pos.X >= minX && pos.X <= maxX && pos.Y >= minY && pos.Y <= maxY))
continue;
var time = (from.GetDistance(to) / creature.GetSpeed()) * 1000;
npc.AI.Activate(time);
}
}
finally
{
_creaturesRWLS.ExitReadLock();
}
}