Aura.Channel.World.Region.ActivateAis C# (CSharp) Method

ActivateAis() public method

Activates AIs in range of the movement path.
public ActivateAis ( Creature creature, Position from, Position to ) : void
creature Aura.Channel.World.Entities.Creature
from Position
to Position
return void
		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 (var npc in _creatures.Values.OfType<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 speed = creature.GetSpeed();
					if (speed < 1)
						speed = 1;

					var time = (from.GetDistance(to) / speed) * 1000;

					npc.AI.Activate(time);
				}
			}
			finally
			{
				_creaturesRWLS.ExitReadLock();
			}
		}