예제 #1
0
        /// <summary>
        /// Check if a destination is reachable.
        /// </summary>
        /// <param name="r">A customized Route object.</param>
        /// <returns>True: if a destination is reachable.</returns>
        public static bool Go(Route r)
        {
            if (r.StopIfStuck)
            {
                r.MaxRetry = 1;
            }

            DateTime timeStart, timeEnd;

            timeStart = DateTime.Now;
            timeEnd   = (r.Timeout < 0) ? timeStart.AddDays(1) : timeStart.AddSeconds(r.Timeout);

            float       timeLeft;
            List <Tile> road;
            bool        success;

            while (r.MaxRetry == -1 || r.MaxRetry > 0)
            {
                road     = PathMove.GetPath(r.X, r.Y, r.IgnoreMobile);
                timeLeft = (int)timeEnd.Subtract(DateTime.Now).TotalSeconds;
                success  = RunPath(road, timeLeft, r.DebugMessage, r.UseResync);
                if (r.MaxRetry > 0)
                {
                    r.MaxRetry -= 1;
                }
                if (success)
                {
                    return(true);
                }
                if (DateTime.Now.CompareTo(timeEnd) > 0)
                {
                    return(false);
                }
            }
            return(false);
        }
예제 #2
0
 /// <summary>
 /// Compute the path for the given destination and returns a list of Tile (coordinates).
 /// </summary>
 /// <param name="dst_x">Destination X.</param>
 /// <param name="dst_y">Destination Y.</param>
 /// <param name="ignoremob">Ignores any mobiles with the path calculation.</param>
 /// <returns>List of Tile objects, each holds a .X and .Y coordinates.</returns>
 public static List <Tile> GetPath(int dst_x, int dst_y, bool ignoremob)
 {
     return(PathMove.GetPath(dst_x, dst_y, ignoremob));
 }
예제 #3
0
 public static List <Tile> GetPath(int x, int y, bool ignoremob)
 {
     return(PathMove.GetPath(x, y, ignoremob));
 }
예제 #4
0
        private static bool Engine(Route r)
        {
            List <Tile> road = PathMove.GetPath(r.X, r.Y, r.IgnoreMobile);

            if (road == null) // No way to destination
            {
                Misc.SendMessage("PathFind: Destination not valid", 33);
                return(false);
            }

            foreach (Tile step in road)
            {
                if (Player.Position.X == r.X && Player.Position.Y == r.Y)
                {
                    Misc.SendMessage("PathFind: Destination reached", 66);
                    return(true);
                }
                bool walkok = false;
                if (step.X > Player.Position.X && step.Y == Player.Position.Y) //East
                {
                    Rotate(Direction.East, r.DebugMessage);
                    walkok = Run(Direction.East, r.DebugMessage);
                }
                else if (step.X < Player.Position.X && step.Y == Player.Position.Y) // West
                {
                    Rotate(Direction.West, r.DebugMessage);
                    walkok = Run(Direction.West, r.DebugMessage);
                }
                else if (step.X == Player.Position.X && step.Y < Player.Position.Y) //North
                {
                    Rotate(Direction.North, r.DebugMessage);
                    walkok = Run(Direction.North, r.DebugMessage);
                }
                else if (step.X == Player.Position.X && step.Y > Player.Position.Y) //South
                {
                    Rotate(Direction.South, r.DebugMessage);
                    walkok = Run(Direction.South, r.DebugMessage);
                }
                else if (step.X > Player.Position.X && step.Y > Player.Position.Y) //Down
                {
                    Rotate(Direction.Down, r.DebugMessage);
                    walkok = Run(Direction.Down, r.DebugMessage);
                }
                else if (step.X < Player.Position.X && step.Y < Player.Position.Y) //UP
                {
                    Rotate(Direction.Up, r.DebugMessage);
                    walkok = Run(Direction.Up, r.DebugMessage);
                }
                else if (step.X > Player.Position.X && step.Y < Player.Position.Y) //Right
                {
                    Rotate(Direction.Right, r.DebugMessage);
                    walkok = Run(Direction.Right, r.DebugMessage);
                }
                else if (step.X < Player.Position.X && step.Y > Player.Position.Y) //Left
                {
                    Rotate(Direction.Left, r.DebugMessage);
                    walkok = Run(Direction.Left, r.DebugMessage);
                }
                else if (Player.Position.X == step.X && Player.Position.Y == step.Y) // no action
                {
                    walkok = true;
                }

                if (!walkok)
                {
                    if (r.DebugMessage)
                    {
                        Misc.SendMessage("PathFind: Move action FAIL", 33);
                    }

                    if (r.UseResync)
                    {
                        Misc.Resync();
                        Misc.Pause(200);
                    }

                    return(false);
                }
                else
                {
                    if (r.DebugMessage)
                    {
                        Misc.SendMessage("PathFind: Move action OK", 66);
                    }
                }
            }

            if (Player.Position.X == r.X && Player.Position.Y == r.Y)
            {
                Misc.SendMessage("PathFind: Destination reached", 66);
                return(true);
            }
            else
            {
                Go(r);
                return(false);
            }
        }