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); }
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; }
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); } }
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); }
/// <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); }