Esempio n. 1
0
		private static void Path( Mobile from, IPoint3D p, PathAlgorithm alg, string name, int zOffset )
		{
			m_OverrideAlgorithm = alg;

			long start = DateTime.Now.Ticks;
			MovementPath path = new MovementPath( from, new Point3D( p ) );
			long end = DateTime.Now.Ticks;
			double len = Math.Round( (end-start) / 10000.0, 2 );

			if ( !path.Success )
			{
				from.SendMessage( "{0} path failed: {1}ms", name, len );
			}
			else
			{
				from.SendMessage( "{0} path success: {1}ms", name, len );

				int x = from.X;
				int y = from.Y;
				int z = from.Z;

				for ( int i = 0; i < path.Directions.Length; ++i )
				{
					Movement.Movement.Offset( path.Directions[i], ref x, ref y );

					new RecallRune().MoveToWorld( new Point3D( x, y, z+zOffset ), from.Map );
				}
			}
		}
Esempio n. 2
0
        private static void Path(Mobile from, IPoint3D p, PathAlgorithm alg, string name, int zOffset)
        {
            OverrideAlgorithm = alg;

            var watch = new Stopwatch();

            watch.Start();
            var path = new MovementPath(from, new Point3D(p));

            watch.Stop();

            if (!path.Success)
            {
                from.SendMessage("{0} path failed: {1}ms", name, watch.ElapsedMilliseconds);
            }
            else
            {
                from.SendMessage("{0} path success: {1}ms", name, watch.ElapsedMilliseconds);

                var x = from.X;
                var y = from.Y;
                var z = from.Z;

                WayPoint waypoint = null;

                for (var i = 0; i < path.Directions.Length; ++i)
                {
                    Movement.Movement.Offset(path.Directions[i], ref x, ref y);

                    waypoint = new WayPoint(waypoint);
                    waypoint.MoveToWorld(new Point3D(x, y, z + zOffset), from.Map);
                }
            }
        }
Esempio n. 3
0
        private static void Path(Mobile from, IPoint3D p, PathAlgorithm alg, string name, int zOffset)
        {
            m_OverrideAlgorithm = alg;

            long         start = DateTime.UtcNow.Ticks;
            MovementPath path  = new MovementPath(from, new Point3D(p));
            long         end   = DateTime.UtcNow.Ticks;
            double       len   = Math.Round((end - start) / 10000.0, 2);

            if (!path.Success)
            {
                from.SendMessage("{0} path failed: {1}ms", name, len);
            }
            else
            {
                from.SendMessage("{0} path success: {1}ms", name, len);

                int x = from.X;
                int y = from.Y;
                int z = from.Z;

                for (int i = 0; i < path.Directions.Length; ++i)
                {
                    Movement.Movement.Offset(path.Directions[i], ref x, ref y);

                    new Items.RecallRune().MoveToWorld(new Point3D(x, y, z + zOffset), from.Map);
                }
            }
        }
Esempio n. 4
0
        public bool CheckPath()
        {
            if (!Enabled)
            {
                return(false);
            }

            var goal = GetGoalLocation();

            if (m_Path != null && (m_Path.Success && goal == m_LastGoalLoc || m_LastPathTime + RepathDelay > DateTime.Now) &&
                !(m_Path.Success && Check(m_From.Location, m_LastGoalLoc, 0)))
            {
                return(false);
            }

            m_LastPathTime = DateTime.UtcNow;
            m_LastGoalLoc  = goal;

            m_Path = new MovementPath(m_From, goal);

            m_Index = 0;
            m_Next  = m_From.Location;

            Advance(ref m_Next, m_Index);

            return(true);
        }
Esempio n. 5
0
        public bool CheckPath()
        {
            if (!Enabled)
            {
                return(false);
            }

            bool repath = false;

            Point3D goal = this.GetGoalLocation();

            if (this.m_Path == null)
            {
                repath = true;
            }
            else if ((!this.m_Path.Success || goal != this.m_LastGoalLoc) && (this.m_LastPathTime + RepathDelay) <= DateTime.UtcNow)
            {
                repath = true;
            }
            else if (this.m_Path.Success && this.Check(this.m_From.Location, this.m_LastGoalLoc, 0))
            {
                repath = true;
            }

            if (!repath)
            {
                return(false);
            }

            this.m_LastPathTime = DateTime.UtcNow;
            this.m_LastGoalLoc  = goal;

            this.m_Path = new MovementPath(this.m_From, goal);

            this.m_Index = 0;
            this.m_Next  = this.m_From.Location;

            this.Advance(ref this.m_Next, this.m_Index);

            return(true);
        }
Esempio n. 6
0
        public bool CheckPath()
        {
            if (!Enabled)
            {
                return(false);
            }

            bool repath = false;

            Point3D goal = GetGoalLocation();

            if (m_Path == null)
            {
                repath = true;
            }
            else if ((!m_Path.Success || goal != m_LastGoalLoc) && (m_LastPathTime + RepathDelay) <= DateTime.UtcNow)
            {
                repath = true;
            }
            else if (m_Path.Success && Check(m_From.Location, m_LastGoalLoc, 0))
            {
                repath = true;
            }

            if (!repath)
            {
                return(false);
            }

            m_LastPathTime = DateTime.UtcNow;
            m_LastGoalLoc  = goal;

            m_Path = new MovementPath(m_From, goal);

            m_Index = 0;
            m_Next  = m_From.Location;

            Advance(ref m_Next, m_Index);

            return(true);
        }
Esempio n. 7
0
        public PathFollowerResult Follow(bool run, int range)
        {
            Point3D   goal = GetGoalLocation();
            Direction d;

            if (Check(m_From.Location, goal, range))
            {
                return(PathFollowerResult.ReachedDestination);
            }

            bool repathed = CheckPath();

            if (!Enabled || !m_Path.Success)
            {
                d = m_From.GetDirectionTo(goal);

                if (run)
                {
                    d |= Direction.Running;
                }

                m_From.SetDirection(d);
                Move(d);

                if (Check(m_From.Location, goal, range))
                {
                    return(PathFollowerResult.ReachedDestination);
                }
            }

            d = m_From.GetDirectionTo(m_Next);

            if (run)
            {
                d |= Direction.Running;
            }

            m_From.SetDirection(d);

            MoveResult res = Move(d);

            if (m_From is PathTester)
            {
                m_From.Say("Move attempt: " + res);
            }

            // If blocked or change direction because blocked then need to repath
            if (res == MoveResult.Blocked || res == MoveResult.SuccessAutoTurn)
            {
                if (repathed)
                {
                    return(PathFollowerResult.UnableToFindPath);
                }

                m_Path = null;
                CheckPath();

                if (!m_Path.Success)
                {
                    d = m_From.GetDirectionTo(goal);

                    if (run)
                    {
                        d |= Direction.Running;
                    }

                    m_From.SetDirection(d);
                    Move(d);

                    if (Check(m_From.Location, goal, range))
                    {
                        return(PathFollowerResult.ReachedDestination);
                    }
                }

                d = m_From.GetDirectionTo(m_Next);

                if (run)
                {
                    d |= Direction.Running;
                }

                m_From.SetDirection(d);

                res = Move(d);

                if (res == MoveResult.Blocked)
                {
                    return(PathFollowerResult.UnableToFindPath);
                }
            }

            if (m_From.X == m_Next.X && m_From.Y == m_Next.Y)
            {
                if (m_From.Z == m_Next.Z)
                {
                    ++m_Index;
                    Advance(ref m_Next, m_Index);

                    if (Check(m_From.Location, goal, range))
                    {
                        return(PathFollowerResult.ReachedDestination);
                    }
                    else
                    {
                        return(PathFollowerResult.FollowingPath);
                    }
                }
                else
                {
                    m_Path = null;

                    if (Check(m_From.Location, goal, range))
                    {
                        return(PathFollowerResult.ReachedDestination);
                    }
                    else
                    {
                        return(PathFollowerResult.UnableToFindPath);
                    }
                }
            }

            if (Check(m_From.Location, goal, range))
            {
                return(PathFollowerResult.ReachedDestination);
            }
            else
            {
                return(PathFollowerResult.UnableToFindPath);
            }
        }
Esempio n. 8
0
        public bool Follow(bool run, int range)
        {
            Point3D goal = this.GetGoalLocation();
            Direction d;

            if (this.Check(this.m_From.Location, goal, range))
                return true;

            bool repathed = this.CheckPath();

            if (!Enabled || !this.m_Path.Success)
            {
                d = this.m_From.GetDirectionTo(goal);

                if (run)
                    d |= Direction.Running;

                this.m_From.SetDirection(d);
                this.Move(d);

                return this.Check(this.m_From.Location, goal, range);
            }

            d = this.m_From.GetDirectionTo(this.m_Next);

            if (run)
                d |= Direction.Running;

            this.m_From.SetDirection(d);

            MoveResult res = this.Move(d);

            if (res == MoveResult.Blocked)
            {
                if (repathed)
                    return false;

                this.m_Path = null;
                this.CheckPath();

                if (!this.m_Path.Success)
                {
                    d = this.m_From.GetDirectionTo(goal);

                    if (run)
                        d |= Direction.Running;

                    this.m_From.SetDirection(d);
                    this.Move(d);

                    return this.Check(this.m_From.Location, goal, range);
                }

                d = this.m_From.GetDirectionTo(this.m_Next);

                if (run)
                    d |= Direction.Running;

                this.m_From.SetDirection(d);

                res = this.Move(d);

                if (res == MoveResult.Blocked)
                    return false;
            }

            if (this.m_From.X == this.m_Next.X && this.m_From.Y == this.m_Next.Y)
            {
                if (this.m_From.Z == this.m_Next.Z)
                {
                    ++this.m_Index;
                    this.Advance(ref this.m_Next, this.m_Index);
                }
                else
                {
                    this.m_Path = null;
                }
            }

            return this.Check(this.m_From.Location, goal, range);
        }
Esempio n. 9
0
        public bool CheckPath()
        {
            if (!Enabled)
                return false;

            bool repath = false;

            Point3D goal = this.GetGoalLocation();

            if (this.m_Path == null)
                repath = true;
            else if ((!this.m_Path.Success || goal != this.m_LastGoalLoc) && (this.m_LastPathTime + RepathDelay) <= DateTime.UtcNow)
                repath = true;
            else if (this.m_Path.Success && this.Check(this.m_From.Location, this.m_LastGoalLoc, 0))
                repath = true;

            if (!repath)
                return false;

            this.m_LastPathTime = DateTime.UtcNow;
            this.m_LastGoalLoc = goal;

            this.m_Path = new MovementPath(this.m_From, goal);

            this.m_Index = 0;
            this.m_Next = this.m_From.Location;

            this.Advance(ref this.m_Next, this.m_Index);

            return true;
        }
Esempio n. 10
0
		public bool CheckPath()
		{
			if ( !Enabled )
				return false;

			bool repath = false;

			Point3D goal = GetGoalLocation();

			if ( m_Path == null )
				repath = true;
			else if ( (!m_Path.Success || goal != m_LastGoalLoc) && (m_LastPathTime + RepathDelay) <= DateTime.Now )
				repath = true;
			else if ( m_Path.Success && Check( m_From.Location, m_LastGoalLoc, 0 ) )
				repath = true;

			if ( !repath )
				return false;

			m_LastPathTime = DateTime.Now;
			m_LastGoalLoc = goal;

			m_Path = new MovementPath( m_From, goal );

			m_Index = 0;
			m_Next = m_From.Location;

			Advance( ref m_Next, m_Index );

			return true;
		}
Esempio n. 11
0
		public void ForceRepath()
		{
			m_Path = null;
			m_SectorPoints = null;
			m_LastPathTime = DateTime.Now - RepathDelay;
		}
Esempio n. 12
0
        public bool CheckPath()
        {
            if (!Enabled)
            {
                return(false);
            }

            bool repath  = false;
            bool bigpath = false;

            Point3D goal = GetEndGoalLocation(0);

            // check if we need to use SectorPath, or if goal is close enough to use FastAStar
            if (!FastAStarAlgorithm.Instance.CheckCondition(m_From, m_From.Map, m_From.Location, goal) &&
                (m_SectorPoints == null || goal != m_LastEndGoalLoc) && (m_LastPathTime + RepathDelay) <= DateTime.Now)
            {
                m_LastEndGoalLoc  = goal;
                m_SectorPoints    = Server.PathAlgorithms.Sector.SectorPathAlgorithm.FindWaypoints(m_From, m_From.Map, m_From.Location, goal);
                m_NextSectorPoint = 0;
            }

            goal = GetGoalLocation(0);

            if (bigpath || m_Path == null)
            {
                repath = true;
            }
            else if ((!m_Path.Success || goal != m_LastGoalLoc) && (m_LastPathTime + RepathDelay) <= DateTime.Now)
            {
                repath = true;
            }
            else if (m_Path.Success && Check(m_From.Location, m_LastGoalLoc, 0))
            {
                repath = true;
            }

            if (!repath)
            {
                return(false);
            }

            // go as far forward in the list of waypoints as we can reach
            // FastAStar paths will have only one stack entry
            Stack s = new Stack();
            int   i = 1;

            do
            {
                s.Push(goal);
                goal = GetGoalLocation(i++);
            } while (goal != Point3D.Zero && FastAStarAlgorithm.Instance.CheckCondition(m_From, m_From.Map, m_From.Location, goal));

            // now find the farthest waypoint that we can path to, smooths and shortens pathing
            while (s.Count > 0)
            {
                goal = (Point3D)s.Pop();

                m_LastPathTime = DateTime.Now;
                m_LastGoalLoc  = goal;

                if ((m_Path = new MovementPath(m_From, goal)).Success)
                {
                    m_Index            = 0;
                    m_Next             = m_From.Location;
                    m_NextSectorPoint += s.Count;

                    Advance(ref m_Next, m_Index);
                    break;
                }
            }

            return(true);
        }
Esempio n. 13
0
 public void ForceRepath()
 {
     m_Path         = null;
     m_SectorPoints = null;
     m_LastPathTime = DateTime.Now - RepathDelay;
 }
Esempio n. 14
0
        private void DropCrack(MovementPath path)
        {
            int time = 10;
            int x = this.X;
            int y = this.Y;

            for (int i = 0; i < path.Directions.Length; ++i)
            {
                Movement.Movement.Offset(path.Directions[i], ref x, ref y);
                IPoint3D p = new Point3D(x, y, this.Map.GetAverageZ(x, y)) as IPoint3D;

                Timer.DelayCall(TimeSpan.FromMilliseconds(time), new TimerStateCallback(ManaDrainEffects_Callback), new object[] { p, this.Map });

                time += 200;
            }
        }
Esempio n. 15
0
        private bool DoEffects(Direction d)
        {
            int x = this.X;
            int y = this.Y;
            int z = this.Z;
            int range = 10;
            int offset = 8;

            switch (d)
            {
                case Direction.North:
                    x = this.X + Utility.RandomMinMax(-offset, offset);
                    y = this.Y - range;
                    break;
                case Direction.West:
                    x = this.X - range;
                    y = this.Y + Utility.RandomMinMax(-offset, offset); 
                    break;
                case Direction.South:
                    x = this.X + Utility.RandomMinMax(-offset, offset);
                    y = this.Y + range;
                    break;
                case Direction.East:
                    x = this.X + range;
                    y = this.Y + Utility.RandomMinMax(-offset, offset); 
                    break;
            }

            for (int i = 0; i < range; i++)
            {
                switch (d)
                {
                    case Direction.North: y += i; break;
                    case Direction.West: x += i; break;
                    case Direction.South: y -= i; break;
                    case Direction.East: x -= i; break;
                }

                z = this.Map.GetAverageZ(x, y);
                Point3D p = new Point3D(x, y, z);

                if (Server.Spells.SpellHelper.AdjustField(ref p, this.Map, 12, false))/*this.Map.CanFit(x, y, z, 16, false, false, true))/*this.Map.CanSpawnMobile(x, y, z)*/
                {
                    MovementPath path = new MovementPath(this, p);

                    if (path.Success)
                    {
                        DropCrack(path);
                        return true;
                    }
                }
            }

            return false;
        }
Esempio n. 16
0
		public void TrySetAnchor(Mobile from, IPoint3D p)
		{
            if (!CheckOwnerAlignment() || from != m_Owner)
				return;
				
			if(p is Item && (((Item)p).RootParent != null || ((Item)p).Movable))
			{
				from.SendMessage("That wouldn't be a suitable anchor.");
				return;
			}

            if (p is Mobile)
            {
                Mobile m = p as Mobile;

                Anchor = m;
                from.SendLocalizedMessage(1153280, m == m_Owner ? "You!" : m.Name + ".");

                m_Pet.ControlTarget = m;
                m_Pet.ControlOrder = OrderType.Follow;

                return;
            }

            Point3D point = new Point3D(p);
            bool success = false;

            for (int x = -1; x <= 1; x++)
            {
                for (int y = -1; y <= 1; y++)
                {
                    int xx = point.X + x;
                    int yy = point.Y + y;
                    Point3D newPoint = new Point3D(xx, yy, from.Map.GetAverageZ(xx, yy));

                    MovementPath path = new MovementPath(m_Pet, newPoint);

                    if (path.Success)
                    {
                        success = true;
                        break;
                    }
                }

                if (success)
                    break;
            }

			if(success)
			{
				Anchor = p;
				
				object name = GetAnchorName(); // Your possessed creature is now anchored to ~1_NAME~
				
				if(name is int)
					from.SendLocalizedMessage(1153280, String.Format("#{0}", (int) name)); 
				else if (name is string)
					from.SendLocalizedMessage(1153280, (string)name);

                m_Pet.ControlOrder = OrderType.None;
                m_Pet.CurrentSpeed = m_Pet.ActiveSpeed;
                m_Pet.Home = new Point3D(p);
			}
			else
				from.SendMessage("There must be a clear path to set an anchor.");
		}
Esempio n. 17
0
		public bool Follow( bool run, int range )
		{
			Point3D goal = GetGoalLocation();
			Direction d;

			if ( Check( m_From.Location, goal, range ) )
				return true;

			bool repathed = CheckPath();

			if ( !Enabled || !m_Path.Success )
			{
				d = m_From.GetDirectionTo( goal );

				if ( run )
					d |= Direction.Running;

				m_From.SetDirection( d );
				Move( d );

				return Check( m_From.Location, goal, range );
			}

			d = m_From.GetDirectionTo( m_Next );

			if ( run )
				d |= Direction.Running;

			m_From.SetDirection( d );

			MoveResult res = Move( d );

			if ( res == MoveResult.Blocked )
			{
				if ( repathed )
					return false;

				m_Path = null;
				CheckPath();

				if ( !m_Path.Success )
				{
					d = m_From.GetDirectionTo( goal );

					if ( run )
						d |= Direction.Running;

					m_From.SetDirection( d );
					Move( d );

					return Check( m_From.Location, goal, range );
				}

				d = m_From.GetDirectionTo( m_Next );

				if ( run )
					d |= Direction.Running;

				m_From.SetDirection( d );

				res = Move( d );

				if ( res == MoveResult.Blocked )
					return false;
			}

			if ( m_From.X == m_Next.X && m_From.Y == m_Next.Y )
			{
				if ( m_From.Z == m_Next.Z )
				{
					++m_Index;
					Advance( ref m_Next, m_Index );
				}
				else
				{
					m_Path = null;
				}
			}

			return Check( m_From.Location, goal, range );
		}
Esempio n. 18
0
		public void ForceRepath()
		{
			m_Path = null;
		}
Esempio n. 19
0
        public bool Follow(bool run, int range)
        {
            Point3D   goal = GetGoalLocation();
            Direction d;

            if (Check(m_From.Location, goal, range))
            {
                return(true);
            }

            bool repathed = CheckPath();

            if (!Enabled || !m_Path.Success)
            {
                d = m_From.GetDirectionTo(goal);

                if (run)
                {
                    d |= Direction.Running;
                }

                m_From.SetDirection(d);
                Move(d);

                return(Check(m_From.Location, goal, range));
            }

            d = m_From.GetDirectionTo(m_Next);

            if (run)
            {
                d |= Direction.Running;
            }

            m_From.SetDirection(d);

            MoveResult res = Move(d);

            if (res == MoveResult.Blocked)
            {
                if (repathed)
                {
                    return(false);
                }

                m_Path = null;
                CheckPath();

                if (!m_Path.Success)
                {
                    d = m_From.GetDirectionTo(goal);

                    if (run)
                    {
                        d |= Direction.Running;
                    }

                    m_From.SetDirection(d);
                    Move(d);

                    return(Check(m_From.Location, goal, range));
                }

                d = m_From.GetDirectionTo(m_Next);

                if (run)
                {
                    d |= Direction.Running;
                }

                m_From.SetDirection(d);

                res = Move(d);

                if (res == MoveResult.Blocked)
                {
                    return(false);
                }
            }

            if (m_From.X == m_Next.X && m_From.Y == m_Next.Y)
            {
                if (m_From.Z == m_Next.Z)
                {
                    ++m_Index;
                    Advance(ref m_Next, m_Index);
                }
                else
                {
                    m_Path = null;
                }
            }

            return(Check(m_From.Location, goal, range));
        }
Esempio n. 20
0
		public bool CheckPath()
		{
			if ( !Enabled )
				return false;

			bool repath = false;
			bool bigpath = false;

			Point3D goal = GetEndGoalLocation(0);

			// check if we need to use SectorPath, or if goal is close enough to use FastAStar
			if (!FastAStarAlgorithm.Instance.CheckCondition(m_From, m_From.Map, m_From.Location, goal) &&
				(m_SectorPoints == null || goal != m_LastEndGoalLoc) && (m_LastPathTime + RepathDelay) <= DateTime.Now)
			{
				m_LastEndGoalLoc = goal;
				m_SectorPoints = Server.PathAlgorithms.Sector.SectorPathAlgorithm.FindWaypoints(m_From, m_From.Map, m_From.Location, goal);
				m_NextSectorPoint = 0;
			}

			goal = GetGoalLocation(0);

			if ( bigpath || m_Path == null )
				repath = true;
			else if ( (!m_Path.Success || goal != m_LastGoalLoc) && (m_LastPathTime + RepathDelay) <= DateTime.Now )
				repath = true;
			else if ( m_Path.Success && Check( m_From.Location, m_LastGoalLoc, 0 ) )
				repath = true;

			if ( !repath )
				return false;

			// go as far forward in the list of waypoints as we can reach
			// FastAStar paths will have only one stack entry
			Stack s = new Stack();
			int i = 1;
			do
			{
				s.Push(goal);
				goal = GetGoalLocation(i++);
			} while (goal != Point3D.Zero && FastAStarAlgorithm.Instance.CheckCondition(m_From, m_From.Map, m_From.Location, goal));

			// now find the farthest waypoint that we can path to, smooths and shortens pathing
			while (s.Count > 0)
			{
				goal = (Point3D)s.Pop();

				m_LastPathTime = DateTime.Now;
				m_LastGoalLoc = goal;

				if ((m_Path = new MovementPath(m_From, goal)).Success)
				{
					m_Index = 0;
					m_Next = m_From.Location;
					m_NextSectorPoint += s.Count;
					
					Advance( ref m_Next, m_Index );
					break;
				}
			}

			return true;
		}
Esempio n. 21
0
 public void ForceRepath()
 {
     this.m_Path = null;
 }
Esempio n. 22
0
 public void ForceRepath()
 {
     m_Path = null;
 }
Esempio n. 23
0
        public bool Follow( bool run, int range )
        {
            Point3D goal = GetGoalLocation();
            Direction d;

            if ( Check( m_From.Location, goal, range ) )
                return true;

            bool repathed = CheckPath();

            if ( !Enabled || !m_Path.Success )
            {
                // path failed somehow, let's use a cheap method
                if ( !m_EscapeGoal ) // move towards
                    d = m_From.GetDirectionTo( goal );
                else // move away
                    d = Utility.GetDirection( new Point2D( goal.X, goal.Y ), new Point2D( m_From.Location.X, m_From.Location.Y ) );

                if ( run )
                    d |= Direction.Running;

                m_From.SetDirection( d );
                Move( d );

                return Check( m_From.Location, goal, range );
            }

            d = m_From.GetDirectionTo( m_Next );

            if ( run )
                d |= Direction.Running;

            m_From.SetDirection( d );

            MoveResult res = Move( d );

            if ( res == MoveResult.Blocked )
            {
                if ( repathed )
                    return false;

                m_Path = null;
                CheckPath();

                if ( !m_Path.Success )
                {
                    d = m_From.GetDirectionTo( goal );

                    if ( run )
                        d |= Direction.Running;

                    m_From.SetDirection( d );
                    Move( d );

                    return Check( m_From.Location, goal, range );
                }

                d = m_From.GetDirectionTo( m_Next );

                if ( run )
                    d |= Direction.Running;

                m_From.SetDirection( d );

                res = Move( d );

                if ( res == MoveResult.Blocked )
                    return false;
            }

            if ( m_From.X == m_Next.X && m_From.Y == m_Next.Y )
            {
                if ( m_From.Z == m_Next.Z )
                {
                    ++m_Index;
                    Advance( ref m_Next, m_Index );
                }
                else
                {
                    m_Path = null;
                }
            }

            return Check( m_From.Location, goal, range );
        }
Esempio n. 24
0
                private bool CanPath()
                {
                    IPoint3D p = m_Tamer as IPoint3D;

                    if ( p == null )
                        return false;

                    if( m_Creature.InRange( new Point3D( p ), 1 ) )
                        return true;

                    MovementPath path = new MovementPath( m_Creature, new Point3D( p ) );
                    return path.Success;
                }
Esempio n. 25
0
        public bool Follow(bool run, int range)
        {
            Point3D   goal = this.GetGoalLocation();
            Direction d;

            if (this.Check(this.m_From.Location, goal, range))
            {
                return(true);
            }

            bool repathed = this.CheckPath();

            if (!Enabled || !this.m_Path.Success)
            {
                d = this.m_From.GetDirectionTo(goal);

                if (run)
                {
                    d |= Direction.Running;
                }

                this.m_From.SetDirection(d);
                this.Move(d);

                return(this.Check(this.m_From.Location, goal, range));
            }

            d = this.m_From.GetDirectionTo(this.m_Next);

            if (run)
            {
                d |= Direction.Running;
            }

            this.m_From.SetDirection(d);

            MoveResult res = this.Move(d);

            if (res == MoveResult.Blocked)
            {
                if (repathed)
                {
                    return(false);
                }

                this.m_Path = null;
                this.CheckPath();

                if (!this.m_Path.Success)
                {
                    d = this.m_From.GetDirectionTo(goal);

                    if (run)
                    {
                        d |= Direction.Running;
                    }

                    this.m_From.SetDirection(d);
                    this.Move(d);

                    return(this.Check(this.m_From.Location, goal, range));
                }

                d = this.m_From.GetDirectionTo(this.m_Next);

                if (run)
                {
                    d |= Direction.Running;
                }

                this.m_From.SetDirection(d);

                res = this.Move(d);

                if (res == MoveResult.Blocked)
                {
                    return(false);
                }
            }

            if (this.m_From.X == this.m_Next.X && this.m_From.Y == this.m_Next.Y)
            {
                if (this.m_From.Z == this.m_Next.Z)
                {
                    ++this.m_Index;
                    this.Advance(ref this.m_Next, this.m_Index);
                }
                else
                {
                    this.m_Path = null;
                }
            }

            return(this.Check(this.m_From.Location, goal, range));
        }
		public static void BuildSectorNodeNetwork(CommandEventArgs e)
		{
			if (m_Nodes == null)
			{
				try
				{
					Console.Write("Initializing SectorNodes...");
					DateTime dt = DateTime.Now;

					m_Nodes = new SectorNode[Map.Felucca.Width >> Map.SectorShift, Map.Felucca.Height >> Map.SectorShift];

					for (int y = 0; y < (Map.Felucca.Height >> Map.SectorShift); y++)
					{
						for (int x = 0; x < (Map.Felucca.Width >> Map.SectorShift); x++)
						{
							SectorNode sn = new SectorNode();
							sn.Point = Point3D.Zero;
							sn.Island = -1;
							sn.Links = new SectorNode[8];
							sn.Distances = new int[8];
							sn.NumLinks = 0;

							for (int sy = 0; sy < Map.SectorSize && sn.Point == Point3D.Zero; sy++)
							{
								for (int sx = 0; sx < Map.SectorSize && sn.Point == Point3D.Zero; sx++)
								{
									if (Map.Felucca.CanSpawnMobile((x << Map.SectorShift) + sx, (y << Map.SectorShift) + sy, 
										Map.Felucca.GetAverageZ((x << Map.SectorShift) + sx, (y << Map.SectorShift) + sy)))
									{
										sn.Point = new Point3D((x << Map.SectorShift) + sx, (y << Map.SectorShift) + sy, 
											Map.Felucca.GetAverageZ((x << Map.SectorShift) + sx, (y << Map.SectorShift) + sy));
									}
								}
							}

							m_Nodes[x, y] = sn;
						}
					}

					Console.WriteLine("done in {0} seconds.", (DateTime.Now - dt).TotalSeconds);
					Console.Write("Computing SectorNode network...");
					dt = DateTime.Now;

					Mobile m = new Server.Mobiles.WanderingHealer();
					MovementPath mp = null;
			
					for (int y = 0; y < (Map.Felucca.Height >> Map.SectorShift); y++)
					{
						for (int x = 0; x < (Map.Felucca.Width >> Map.SectorShift); x++)
						{
							if (m_Nodes[x, y].Point != Point3D.Zero)
							{
								m.MoveToWorld(m_Nodes[x, y].Point, Map.Felucca);

								if (x < (Map.Felucca.Width >> Map.SectorShift) - 1 && y > 0 && m_Nodes[x + 1, y - 1].Point != Point3D.Zero &&
									(mp = new MovementPath(m, m_Nodes[x + 1, y - 1].Point)).Success)
								{
									m_Nodes[x, y].Links[m_Nodes[x, y].NumLinks] = m_Nodes[x + 1, y - 1];
									m_Nodes[x, y].Distances[m_Nodes[x, y].NumLinks] = mp.Directions.Length;
									m_Nodes[x, y].NumLinks++;

									m_Nodes[x + 1, y - 1].Links[m_Nodes[x + 1, y - 1].NumLinks] = m_Nodes[x, y];
									m_Nodes[x + 1, y - 1].Distances[m_Nodes[x + 1, y - 1].NumLinks] = mp.Directions.Length;
									m_Nodes[x + 1, y - 1].NumLinks++;
								}
						
								if (x < (Map.Felucca.Width >> Map.SectorShift) - 1 && m_Nodes[x + 1, y].Point != Point3D.Zero &&
									(mp = new MovementPath(m, m_Nodes[x + 1, y].Point)).Success)
								{
									m_Nodes[x, y].Links[m_Nodes[x, y].NumLinks] = m_Nodes[x + 1, y];
									m_Nodes[x, y].Distances[m_Nodes[x, y].NumLinks] = mp.Directions.Length;
									m_Nodes[x, y].NumLinks++;

									m_Nodes[x + 1, y].Links[m_Nodes[x + 1, y].NumLinks] = m_Nodes[x, y];
									m_Nodes[x + 1, y].Distances[m_Nodes[x + 1, y].NumLinks] = mp.Directions.Length;
									m_Nodes[x + 1, y].NumLinks++;
								}

								if (x < (Map.Felucca.Width >> Map.SectorShift) - 1 && y < (Map.Felucca.Height >> Map.SectorShift) - 1 &&
									m_Nodes[x + 1, y + 1].Point != Point3D.Zero && (mp = new MovementPath(m, m_Nodes[x + 1, y + 1].Point)).Success)
								{
									m_Nodes[x, y].Links[m_Nodes[x, y].NumLinks] = m_Nodes[x + 1, y + 1];
									m_Nodes[x, y].Distances[m_Nodes[x, y].NumLinks] = mp.Directions.Length;
									m_Nodes[x, y].NumLinks++;

									m_Nodes[x + 1, y + 1].Links[m_Nodes[x + 1, y + 1].NumLinks] = m_Nodes[x, y];
									m_Nodes[x + 1, y + 1].Distances[m_Nodes[x + 1, y + 1].NumLinks] = mp.Directions.Length;
									m_Nodes[x + 1, y + 1].NumLinks++;
								}

								if (y < (Map.Felucca.Height >> Map.SectorShift) - 1 && m_Nodes[x, y + 1].Point != Point3D.Zero &&
									(mp = new MovementPath(m, m_Nodes[x, y + 1].Point)).Success)
								{
									m_Nodes[x, y].Links[m_Nodes[x, y].NumLinks] = m_Nodes[x, y + 1];
									m_Nodes[x, y].Distances[m_Nodes[x, y].NumLinks] = mp.Directions.Length;
									m_Nodes[x, y].NumLinks++;

									m_Nodes[x, y + 1].Links[m_Nodes[x, y + 1].NumLinks] = m_Nodes[x, y];
									m_Nodes[x, y + 1].Distances[m_Nodes[x, y + 1].NumLinks] = mp.Directions.Length;
									m_Nodes[x, y + 1].NumLinks++;
								}
							}
						}
					}

					m.Delete();

					Console.WriteLine("done in {0} seconds.", (DateTime.Now - dt).TotalSeconds);
					Console.Write("Finding islands...");
					dt = DateTime.Now;

					int nextIsland = 0;
					Queue open = new Queue();
					ArrayList closed = new ArrayList();

					for (int y = 0; y < (Map.Felucca.Height >> Map.SectorShift); y++)
					{
						for (int x = 0; x < (Map.Felucca.Width >> Map.SectorShift); x++)
						{
							if (m_Nodes[x, y].Point == Point3D.Zero)
								continue;

							if (m_Nodes[x, y].Island == -1)
							{
								int island = nextIsland++;

								// now use dijkstra-style flood fill to find all connected nodes
								open.Clear();
								closed.Clear();

								open.Enqueue(m_Nodes[x, y]);

								while (open.Count > 0)
								{
									SectorNode sn = (SectorNode)open.Dequeue();
									closed.Add(sn);

									sn.Island = island;

									for (int i = 0; i < sn.NumLinks; i++)
										if (!closed.Contains(sn.Links[i]) && !open.Contains(sn.Links[i]))
											open.Enqueue(sn.Links[i]);
								}
							}
						}
					}

					Console.WriteLine("done in {0} seconds.", (DateTime.Now - dt).TotalSeconds);
				}
				catch (Exception ex)
				{
					LogHelper.LogException(ex);
					Console.WriteLine("error!");
					Console.WriteLine(ex);
				}
			}
		}
Esempio n. 27
0
 public void ForceRepath()
 {
     this.m_Path = null;
 }