Exemplo n.º 1
0
        protected override void DoExecute(WowPlayer Entity)
        {
            //on execute, first verify we have a waypoit to follow, else exit
            if (CurrentWaypoint == null)
            {
                Exit(Entity);
                return;
            }

            // Move on...
            float distance = MathFuncs.GetDistance(WaypointVector3DHelper.LocationToVector3D(CurrentWaypoint),
                                                   Entity.Location, false);

            if (Math.Abs(distance - LastDistance) < 1.0)
            {
                TravelPath = null;
                // TODO: Fix the stuck detection code
                //Entity.Unstuck();
            }
            /// We face our destination waypoint while we are already moving, so that it looks
            /// more human-like
            //float angle = MathFuncs.GetFaceRadian(WaypointVector3DHelper.LocationToVector3D(CurrentWaypoint),
            //                                      Entity.Location);

            Output.Instance.Script(string.Format("Entity Location: X:{0} Y:{1} Z:{2}", Entity.Location.X, Entity.Location.Y, Entity.Location.Z), this);
            Output.Instance.Script(string.Format("Path Waypoint: X:{0} Y:{1} Z:{2}", CurrentWaypoint.X, CurrentWaypoint.Y, CurrentWaypoint.Z), this);
            //Entity.FaceUsingMemoryWrite(angle, true);

            Output.Instance.Script(string.Format("First ClickToMove(X:{0} Y:{1} Z:{2})", CurrentWaypoint.X, CurrentWaypoint.Y, CurrentWaypoint.Z), this);
            Entity.ClickToMove(WaypointVector3DHelper.LocationToVector3D(CurrentWaypoint));
            Finish(Entity);
            Exit(Entity);
        }
Exemplo n.º 2
0
        protected override void DoEnter(WowPlayer Entity)
        {
            //if travel path is not defined then generate from location points
            if (TravelPath == null)
            {
                //get current and destination as ppather locations
                var currentLocation     = new Location(Entity.Location.X, Entity.Location.Y, Entity.Location.Z);
                var destinationLocation = new Location(Destination.X, Destination.Y, Destination.Z);
                //calculate and store travel path
                TravelPath = ProcessManager.Caronte.CalculatePath(currentLocation, destinationLocation);
                //TravelPath.locations = new List<Location>(TravelPath.locations.Distinct<Location>());
            }

            //if there are locations then set first waypoint
            if (TravelPath.locations.Count > 0)
            {
                CurrentWaypoint = TravelPath.RemoveFirst();

                //Entity.Face(new Vector3D(CurrentWaypoint.X, CurrentWaypoint.Y, CurrentWaypoint.Z));
                _LastDistance = WaypointVector3DHelper.Vector3DToLocation(Entity.Location).GetDistanceTo(CurrentWaypoint);

                //if the distance to the next waypoint is less then 1f, use the get next waypoint method
                if (_LastDistance < 3f)
                {
                    CurrentWaypoint = GetNextWayPoint();
                    _LastDistance   =
                        WaypointVector3DHelper.Vector3DToLocation(Entity.Location).GetDistanceTo(CurrentWaypoint);
                }
            }
        }
Exemplo n.º 3
0
        protected override void DoExecute(WowPlayer Entity)
        {
            //on execute, first verify we have a waypoit to follow, else exit
            if (CurrentWaypoint == null)
            {
                Exit(Entity); return;
            }

            //verify we are moving, if we aren't then start moving
            if (!Entity.IsMoving())
            {
                Entity.MoveForward();
            }

            //get distances to waypoint
            float fDistance = MathFuncs.GetDistance(
                WaypointVector3DHelper.LocationToVector3D(CurrentWaypoint),
                Entity.Location, false);

            //if distance is growing instead of shrinking them face again
            if (fDistance > _LastDistance)
            {
                Entity.Face(new Vector3D(CurrentWaypoint.X, CurrentWaypoint.Y, CurrentWaypoint.Z));
            }

            //if distance to current waypoint is less then / equal to our tolerance, then move to the next waypoint if it exists, else stop/finish.
            if (fDistance <= Tolerance)
            {
                //if another waypoint exists, then switch to it
                if (TravelPath.GetFirst() != null)
                {
                    CurrentWaypoint = TravelPath.RemoveFirst();
                    Entity.Face(new Vector3D(CurrentWaypoint.X, CurrentWaypoint.Y, CurrentWaypoint.Z));
                }
                else
                {
                    Exit(Entity);
                    Finish(Entity);
                }
            }



            _LastDistance = fDistance;
        }
Exemplo n.º 4
0
        protected override void DoEnter(WowPlayer Entity)
        {
            //if travel path is not defined then generate from location points
            if (TravelPath == null)
            {
                //get current and destination as ppather locations
                Location currentLocation     = new Location(Entity.Location.X, Entity.Location.Y, Entity.Location.Z);
                Location destinationLocation = new Location(Destination.X, Destination.Y, Destination.Z);
                //calculate and store travel path
                TravelPath = ProcessManager.Caronte.CalculatePath(currentLocation, destinationLocation);
            }

            //if there are locations then set first waypoint
            if (TravelPath.locations.Count > 0)
            {
                CurrentWaypoint = TravelPath.RemoveFirst();

                Entity.Face(new Vector3D(CurrentWaypoint.X, CurrentWaypoint.Y, CurrentWaypoint.Z));
                _LastDistance = WaypointVector3DHelper.Vector3DToLocation(Entity.Location).GetDistanceTo(CurrentWaypoint);
            }
        }
Exemplo n.º 5
0
        private void MoveTo()
        {
            Path     path = null;
            Vector3D dest = null;

            if (_wp != null)
            {
                path = new Path();
                foreach (Vector3D v in _wp.List)
                {
                    path.AddLast(WaypointVector3DHelper.Vector3DToLocation(v));
                }
                dest = _wp[_wp.Count - 1];
            }
            else
            {
                // Calculate path
                Output.Instance.Debug("Calculating path from player position " +
                                      _player.Location + " to dest " + dest + " ...");
                path = ProcessManager.Caronte.CalculatePath(
                    WaypointVector3DHelper.Vector3DToLocation(_player.Location),
                    WaypointVector3DHelper.Vector3DToLocation(_dest), _step_dist);

                if (path == null || _terminated)
                {
                    return;
                }

                dest = _dest;
            }

            float distance = MoveToDest(path, dest, _step_dist);

            ProcessManager.OnBotProgressEnd();

            if (distance <= _step_dist)
            {
                Output.Instance.Log("Destination has been reached !!!");
            }
        }
Exemplo n.º 6
0
        private float MoveToDest(Path path, Vector3D dest, float step)
        {
            float  distance = _player.Location.GetDistanceTo(dest);
            string tooltip  = _tooltip;

            while ((distance > 5F) && (_retry <= _max_retry) && !_terminated)
            {
                if (_retry > 0)
                {
                    string r = "Retrying " + _retry + " of " +
                               _max_retry + " to reach the destination";

                    Output.Instance.Log(r);
                    tooltip = _tooltip + " " + r;
                }

                Vector3D[] v_arr = new Vector3D[path.Count];
                for (int i = 0; i < path.Count; i++)
                {
                    v_arr[i] = WaypointVector3DHelper.LocationToVector3D(path[i]);
                }

                ProcessManager.OnPathCalculated(v_arr, _retry);

                Output.Instance.Debug("Path calculating completed. Moving to dest ... ");

                // Test
                // return 0;

                // Travel path
                int      max   = path.Count;
                Vector3D vprev = _player.Location;
                Vector3D vnext;

                if (_retry == 0)
                {
                    ProcessManager.OnBotProgressStart(max, tooltip);

                    // Jump b4 start to clear AFK
                    ProcessManager.CommandManager.SendKeys(CommandManager.SK_SPACE);
                    Thread.Sleep(1000);
                }

                for (int i = 0; i < max; i++)
                {
                    if (_terminated)
                    {
                        break;
                    }

                    // Get next coordinate
                    vnext = WaypointVector3DHelper.LocationToVector3D(path.Get(i));

                    // Remember cur bot loc
                    Vector3D cur_loc = _player.Location;

                    // Calculate travel time
                    distance = vprev.GetDistanceTo(vnext);
                    if (distance == 0)
                    {
                        continue;
                    }
                    int t = (int)((distance / 7F) * 1000);

                    // Calc climb height
                    float z = vnext.Z - cur_loc.Z;

                    _player.ClickToMove(vnext);
                    if ((_retry == 0) && (z > 2) || (_retry > 0))
                    {
                        // Add jump if going too high up or trying unstack
                        Thread.Sleep(200);
                        ProcessManager.CommandManager.SendKeys(CommandManager.SK_SPACE);

                        // Need wait for jump
                        t += 500;
                    }

                    if (t > 0)
                    {
                        // Click a bit earlier for smooth movement
                        Thread.Sleep((int)(0.98 * t));
                    }

                    // Check for stuck
                    if (IsStuck(cur_loc, distance))
                    {
                        // Bot pass less than 80% of step.
                        // Something wrong
                        // Wait a bit we might still moving
                        float dd = _player.Location.GetDistanceTo(cur_loc);
                        Thread.Sleep((int)(((distance - dd) / 7F) * 1000));

                        // Check again
                        if (IsStuck(cur_loc, distance))
                        {
                            // We stuck
                            if (_retry < _max_retry)
                            {
                                Output.Instance.Debug("Player stuck. Trying unstuck ...");
                                _retry++;

                                // Recalculate path to next waypoint but with smaller step
                                float new_step = (float)(step * 0.618);
                                Output.Instance.Debug("Calculating path from player position " +
                                                      _player.Location + " to dest " + vnext + " ...");
                                Path new_path = ProcessManager.Caronte.CalculatePath(
                                    WaypointVector3DHelper.Vector3DToLocation(_player.Location),
                                    WaypointVector3DHelper.Vector3DToLocation(vnext), new_step);
                                float d = MoveToDest(new_path, vnext, new_step);
                                if (d > new_step)
                                {
                                    return(_player.Location.GetDistanceTo(_dest));
                                }

                                Output.Instance.Debug("Player unstuck. Continue traveling.");
                                _retry--;
                            }
                            else
                            {
                                // Just exit
                                return(_player.Location.GetDistanceTo(_dest));
                            }
                        }
                    }

                    if (_retry == 0)
                    {
                        ProcessManager.OnBotProgressChange(i + 1);
                    }

                    vprev = vnext;
                }

                distance = _player.Location.GetDistanceTo(dest);
            }

            return(distance);
        }
Exemplo n.º 7
0
        protected override void DoExecute(WowPlayer Entity)
        {
            //on execute, first verify we have a waypoit to follow, else exit
            if (CurrentWaypoint == null)
            {
                Exit(Entity);
                return;
            }

            const CommandManager.ArrowKey key = CommandManager.ArrowKey.Up;


            // Move on...
            float distance = MathFuncs.GetDistance(WaypointVector3DHelper.LocationToVector3D(CurrentWaypoint),
                                                   Entity.Location, false);

            Entity.PlayerCM.ArrowKeyDown(key);

            /// We face our destination waypoint while we are already moving, so that it looks
            /// more human-like
            float angle = MathFuncs.GetFaceRadian(WaypointVector3DHelper.LocationToVector3D(CurrentWaypoint),
                                                  Entity.Location);

            Entity.FaceUsingMemoryWrite(angle, false);

            // Start profiler for WayPointTimeOut
            DateTime start = DateTime.Now;

            while (distance > Tolerance)
            {
                float currentDistance = distance;

                distance = MathFuncs.GetDistance(WaypointVector3DHelper.LocationToVector3D(CurrentWaypoint),
                                                 Entity.Location, false);

                Thread.Sleep(50);
                Application.DoEvents();

                DateTime end          = DateTime.Now;
                TimeSpan tsTravelTime = end - start;


                // we take as granted that we should move at least 0.1 yards per cycle (might be a good idea to get this routine synchronized so that
                // we can actually know exactly how much we move "per-tick")
                if (Math.Abs(currentDistance - distance) < 0.1f && Math.Abs(currentDistance - distance) > 0.0001f)
                {
                    //Console.WriteLine(string.Format("Stuck! Distance difference: {0}", Math.Abs(currentDistance - distance)));
                    Entity.Unstuck();
                }

                //repoint at the waypoint if we are getting off course
                //angle = MathFuncs.GetFaceRadian(WaypointVector3DHelper.LocationToVector3D(CurrentWaypoint), Entity.Location);
                //if (Math.Abs(Entity.Rotation - angle) > 0.1f)
                //{
                //    Entity.FaceUsingMemoryWrite(angle, false);
                //}
            }

            //get next waypoint (may be null)
            CurrentWaypoint = GetNextWayPoint();

            if (CurrentWaypoint == null)
            {
                Finish(Entity);
                Exit(Entity);
                //stop going forward
                Entity.PlayerCM.ArrowKeyUp(key);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Move character to destination
        /// </summary>
        /// <param name="dest"></param>
        public static bool MoveToDest(Vector3D dest, string lfs, string tooltip_text)
        {
            WowPlayer player = ProcessManager.Player;

            if (UseState)
            {
                // Use NavigationState
                NavigationState ns = new NavigationState(dest, lfs, tooltip_text);

                if (player.StateMachine.IsRunning)
                {
                    // Assume bot doesn't do anything and wait
                    // for manual state change
                    // Otherwise we can't call this method outside of bot thread
                    player.StateMachine.SafeStateChange(ns);
                }
                else
                {
                    StartNavState(ns, player, lfs);
                }
            }
            else
            {
                float distance = dest.GetDistanceTo(player.Location);

                // We have a 3 tries by default to reach target NPC
                int retry     = 0;
                int max_retry = ProcessManager.AppConfig.MaxTargetGetRetries;

                // We might be already at the target
                while ((distance > 5F) && (retry <= max_retry))
                {
                    if (retry > 0)
                    {
                        Output.Instance.Log("Retrying " + retry + " of " +
                                            max_retry + " to reach the destination");
                    }
                    // Click to move on each waypoint
                    // dynamically calculate time between each click
                    // based on distance to the next waypoint

                    // Lets calculate path from character to NPC and move
                    Path p = ProcessManager.Caronte.CalculatePath(
                        WaypointVector3DHelper.Vector3DToLocation(ProcessManager.Player.Location),
                        WaypointVector3DHelper.Vector3DToLocation(dest));

                    // Travel path
                    int      max   = p.Count;
                    Vector3D vprev = dest;
                    Vector3D vnext;
                    for (int i = 0; i < max; i++)
                    {
                        vnext = WaypointVector3DHelper.LocationToVector3D(p.Get(i));

                        // Calculate travel time
                        distance = vprev.GetDistanceTo(vnext);
                        int t = (int)((distance / 7F) * 1000);

                        ProcessManager.Player.ClickToMove(vnext);
                        Thread.Sleep(t);
                        vprev = vnext;
                    }
                }

                distance = dest.GetDistanceTo(player.Location);

                if (distance < 5F)
                {
                    retry++;
                }
            }

            return(dest.GetDistanceTo(player.Location) <= 5F);
        }