Server.PathFollower.Follow C# (CSharp) Méthode

Follow() public méthode

public Follow ( bool run, int range ) : bool
run bool
range int
Résultat bool
		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 );
		}
	}

Usage Example

Exemple #1
0
        /*
         *  Walk at range distance from mobile
         *
         *	iSteps : Number of steps
         *	bRun   : Do we run
         *	iWantDistMin : The minimum distance we want to be
         *  iWantDistMax : The maximum distance we want to be
         *
         */
        public virtual bool WalkMobileRange( Mobile m, int iSteps, bool bRun, int iWantDistMin, int iWantDistMax )
        {
            if( m_Mobile.Deleted || m_Mobile.DisallowAllMoves )
                return false;

            if( m != null )
            {
                for( int i=0; i<iSteps; i++ )
                {
                    // Get the curent distance
                    int iCurrDist = (int)m_Mobile.GetDistanceToSqrt( m );

                    if( iCurrDist < iWantDistMin || iCurrDist > iWantDistMax )
                    {
                        bool needCloser = (iCurrDist > iWantDistMax);
                        bool needFurther = !needCloser;

                        if( needCloser && m_Path != null && m_Path.Goal == m )
                        {
                            if( m_Path.Follow( bRun, 1 ) )
                                m_Path = null;
                        }
                        else
                        {
                            Direction dirTo;

                            if( iCurrDist > iWantDistMax )
                                dirTo = m_Mobile.GetDirectionTo( m );
                            else
                                dirTo = m.GetDirectionTo( m_Mobile );

                            // Add the run flag
                            if( bRun )
                                dirTo = dirTo | Direction.Running;

                            if( !DoMove( dirTo, true ) && needCloser )
                            {
                                m_Path = new PathFollower( m_Mobile, m );
                                m_Path.Mover = new MoveMethod( DoMoveImpl );

                                if( m_Path.Follow( bRun, 1 ) )
                                    m_Path = null;
                            }
                            else
                            {
                                m_Path = null;
                            }
                        }
                    }
                    else
                    {
                        return true;
                    }
                }

                // Get the curent distance
                int iNewDist = (int)m_Mobile.GetDistanceToSqrt( m );

                if( iNewDist >= iWantDistMin && iNewDist <= iWantDistMax )
                    return true;
                else
                    return false;
            }

            return false;
        }
All Usage Examples Of Server.PathFollower::Follow