Ejemplo n.º 1
0
        public bool ProcessDirections(IEnumerable <MyPathNode> path, Location destLocation, int skipNodes = 0)
        {
            List <MyPathNode> myPath = path.ToList();

            myPath.RemoveAt(0); // this is no directions let's skip this
            if (skipNodes > 0)
            {
                for (int i = 1; i <= skipNodes; i++)
                {
                    myPath.RemoveAt(myPath.Count() - i);
                }
                // we can remove last loc, becouse that is the targetLoc
            }
            int lastX, lastY;

            lastX     = 150;
            lastY     = 150;
            IsWalking = true;
            foreach (MyPathNode node in myPath)
            {
                if (!IsWalking)
                {
                    return(false);
                }
                int NextX, NextY;
                NextX = node.X - lastX;
                NextY = node.Y - lastY;

                Constants.WalkDirection d = GetDirection(NextX, NextY);
                Location nextLocation     = new Location(client.PlayerLocation.X + NextX, client.PlayerLocation.Y + NextY, client.PlayerLocation.Z);
                DateTime date             = DateTime.Now.AddMilliseconds(1000 - client.Player.MoveMentSpeed);
                Tile     t = client.Map.GetTile(nextLocation);
                if (isBlocking(t) && myPath.Count() > 1)
                {
                    IsWalking = false;
                    return(false);
                }
                KonjoBot.Packets.Pipe.Walk.Send(client, NextX, NextY);
                while (client.PlayerLocation != nextLocation && client.PlayerLocation.Z == nextLocation.Z)
                {
                    if (!IsWalking)
                    {
                        return(false);
                    }
                    if (date <= DateTime.Now)
                    {
                        IsWalking = false;
                        break;
                    }
                    Thread.Sleep(5);
                }
                lastX = node.X;
                lastY = node.Y;
            }
            IsWalking = false;

            return(true);
        }
Ejemplo n.º 2
0
        private void Process()
        {
            int lastX, lastY;

            lastX = -1;
            lastY = -1;
            foreach (MyPathNode node in myPath)
            {
                if (lastX == -1)
                {
                    // skip first node
                    lastX = node.X;
                    lastY = node.Y;
                }
                else
                {
                    Objects.Location nextLocation = new Objects.Location(client.PlayerLocation.X + node.X - lastX, client.PlayerLocation.Y + node.Y - lastY, client.PlayerLocation.Z);
                    DateTime         date = DateTime.Now.AddMilliseconds(1000 - client.Player.MoveMentSpeed);
                    int locX, locY;
                    locX = node.X - lastX;
                    locY = node.Y - lastY;

                    Constants.WalkDirection d = GetDirection(node.X - lastX, node.Y - lastY);
                    if (d == Constants.WalkDirection.Stop)
                    {
                        // stop packet so we stop now
                        myPath = null;
                        break;
                    }
                    else
                    {
                        lastX = node.X;
                        lastY = node.Y;
                        KonjoBot.Packets.Pipe.Walk.Send(client, locX, locY);
                        while (client.PlayerLocation != nextLocation && client.PlayerLocation.Z == nextLocation.Z)
                        {
                            if (date <= DateTime.Now)
                            {
                                myPath = null;

                                return;
                            }
                            Thread.Sleep(5);
                        }
                    }
                }
            }
            myPath = null;
        }