Beispiel #1
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);
                }
            }
        }
Beispiel #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
                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);
            }
        }
Beispiel #3
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 !!!");
            }
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }