Exemplo n.º 1
0
        private void UpdatePath()
        {
            WowPosition myPosition        = StateMachine.WowDataAdapter.ActivePlayerPosition;
            Vector3     myPosAsVector     = new Vector3(myPosition.x, myPosition.y, myPosition.z);
            Vector3     targetPosAsVector = new Vector3(UnitToFollow.Position.x, UnitToFollow.Position.y, UnitToFollow.Position.z);

            List <Vector3> waypoints = new List <Vector3> {
                targetPosAsVector
            };

            if (StateMachine.PathfindingClient != null)
            {
                waypoints = StateMachine.PathfindingClient.GetPath(myPosAsVector, targetPosAsVector, StateMachine.WowDataAdapter.MapId);
                AmeisenBotLogger.Instance.Log($"[{StateMachine.WowActionExecutor.ProcessId.ToString("X", CultureInfo.InvariantCulture.NumberFormat)}]\tFound Path with {waypoints.Count} nodes", LogLevel.Verbose);
            }

            foreach (Vector3 pos in waypoints)
            {
                WowPosition wpos = new WowPosition(pos);
                if (pos.X != myPosAsVector.X && pos.Y != myPosAsVector.Y && pos.Z != myPosAsVector.Z && CurrentPath != null && !CurrentPath.Contains(wpos))
                {
                    CurrentPath.Enqueue(wpos);
                }
            }

            if (targetPosAsVector.X != myPosAsVector.X && targetPosAsVector.Y != myPosAsVector.Y && targetPosAsVector.Z != myPosAsVector.Z)
            {
                CurrentPath.Enqueue(new WowPosition(targetPosAsVector));
            }
        }
Exemplo n.º 2
0
    public void CreateStaticPath()
    {
        CurrentPath.Enqueue(new Vector2Int(8, 0));
        CurrentPath.Enqueue(new Vector2Int(9, 0));
        CurrentPath.Enqueue(new Vector2Int(10, 0));

        CurrentPath.Enqueue(new Vector2Int(10, -1));
        CurrentPath.Enqueue(new Vector2Int(10, -2));
        CurrentPath.Enqueue(new Vector2Int(10, -3));

        CurrentPath.Enqueue(new Vector2Int(9, -3));
        CurrentPath.Enqueue(new Vector2Int(8, -3));
        CurrentPath.Enqueue(new Vector2Int(7, -3));

        CurrentPath.Enqueue(new Vector2Int(7, -2));
        CurrentPath.Enqueue(new Vector2Int(7, -1));
        CurrentPath.Enqueue(new Vector2Int(7, 0));
    }
Exemplo n.º 3
0
        public void Execute()
        {
            if ((DateTime.Now - LastLastPositionUpdate > TimeSpan.FromMilliseconds(1000) && LastPosition.GetDistance(GetPosition.Invoke()) > 24) || TryCount > 2)
            {
                Reset();
                return;
            }

            if (CurrentPath.Count == 0)
            {
                TryCount = 0;
                List <Vector3> nodes = GeneratePath.Invoke(GetPosition.Invoke(), TargetPosition);

                if (nodes.Count == 0)
                {
                    // pathfinding was unsuccessful
                    return;
                }

                foreach (Vector3 node in nodes)
                {
                    CurrentPath.Enqueue(node);
                }

                CurrentPathTargetPosition = TargetPosition;
            }

            List <Vector3> forces                   = new List <Vector3>();
            Vector3        currentPosition          = GetPosition.Invoke();
            Vector3        targetPosition           = CurrentPath.Peek();
            double         distanceToTargetPosition = currentPosition.GetDistance(targetPosition);

            if (distanceToTargetPosition > 128)
            {
                Reset();
                return;
            }
            else if (distanceToTargetPosition < MovementSettings.WaypointCheckThreshold)
            {
                if (CurrentPath.Count > 0)
                {
                    targetPosition = CurrentPath.Dequeue();
                }
                else if (CurrentPath.Count == 0)
                {
                    return;
                }
            }

            Vector3 positionToGoTo = BotUtils.MoveAhead(GetRotation.Invoke(), targetPosition, 2);
            bool    updateForces   = true;

            switch (State)
            {
            case MovementEngineState.Moving:
                forces.Add(PlayerVehicle.Seek(positionToGoTo, 1));
                break;

            case MovementEngineState.DirectMoving:
                PlayerVehicle.MoveToPosition(targetPosition);
                updateForces = false;
                break;

            case MovementEngineState.Following:
                forces.Add(PlayerVehicle.Seek(positionToGoTo, 1));
                forces.Add(PlayerVehicle.Seperate(1));
                break;

            case MovementEngineState.Chasing:
                forces.Add(PlayerVehicle.Seek(positionToGoTo, 1));
                break;

            case MovementEngineState.Fleeing:
                forces.Add(PlayerVehicle.Flee(positionToGoTo, 1));
                break;

            case MovementEngineState.Evading:
                forces.Add(PlayerVehicle.Evade(positionToGoTo, 1, TargetRotation));
                break;

            case MovementEngineState.Wandering:
                forces.Add(PlayerVehicle.Wander(1));
                break;

            case MovementEngineState.Stuck:
                forces.Add(PlayerVehicle.Unstuck(1));
                break;

            default:
                return;
            }

            if (updateForces)
            {
                PlayerVehicle.Update(forces);
            }

            if (DateTime.Now - LastJumpCheck > TimeSpan.FromMilliseconds(250))
            {
                double distanceTraveled = LastPosition.GetDistance(GetPosition.Invoke());
                if ((LastPosition.X == 0 && LastPosition.Y == 0 && LastPosition.Z == 0) || distanceTraveled < 0.3)
                {
                    Jump.Invoke();
                    TryCount++;
                }

                LastPosition           = GetPosition.Invoke();
                LastLastPositionUpdate = DateTime.Now;
                LastJumpCheck          = DateTime.Now;
            }

            LastTargetPosition = GetPosition.Invoke();
            HasMoved           = true;
        }
Exemplo n.º 4
0
        public void Execute()
        {
            if (DateTime.Now - LastAction < TimeSpan.FromMilliseconds(250))
            {
                return;
            }

            LastAction = DateTime.Now;

            if ((DateTime.Now - LastLastPositionUpdate > TimeSpan.FromMilliseconds(1000) || TryCount > 2))
            {
                Reset();
                return;
            }

            if (CurrentPath.Count == 0)
            {
                TryCount = 0;
                List <Vector3> nodes = new List <Vector3>();

                if (WowInterface.ObjectManager.Player.Position.GetDistance(TargetPosition) > 5)
                {
                    List <Vector3> getPathResult = WowInterface.PathfindingHandler.GetPath((int)WowInterface.ObjectManager.MapId, WowInterface.ObjectManager.Player.Position, TargetPosition);

                    if (getPathResult != null && getPathResult.Count > 0)
                    {
                        nodes.AddRange(getPathResult);
                    }
                }
                else
                {
                    Vector3 moveAlongSurfaceResult = WowInterface.PathfindingHandler.MoveAlongSurface((int)WowInterface.ObjectManager.MapId, WowInterface.ObjectManager.Player.Position, TargetPosition);

                    if (moveAlongSurfaceResult != default && moveAlongSurfaceResult != Vector3.Zero)
                    {
                        nodes.Add(moveAlongSurfaceResult);
                    }
                }

                if (nodes == null || nodes.Count == 0)
                {
                    // pathfinding was unsuccessful
                    return;
                }

                foreach (Vector3 node in nodes)
                {
                    CurrentPath.Enqueue(node);
                }

                CurrentPathTargetPosition = TargetPosition;
            }

            List <Vector3> forces                   = new List <Vector3>();
            Vector3        currentPosition          = WowInterface.ObjectManager.Player.Position;
            Vector3        targetPosition           = CurrentPath.Peek();
            double         distanceToTargetPosition = currentPosition.GetDistance(targetPosition);

            if (distanceToTargetPosition > 4096)
            {
                Reset();
                return;
            }
            else if (distanceToTargetPosition < MovementSettings.WaypointCheckThreshold)
            {
                if (CurrentPath.Count > 0)
                {
                    targetPosition = CurrentPath.Dequeue();
                }
                else if (CurrentPath.Count == 0)
                {
                    return;
                }
            }

            Vector3 positionToGoTo = targetPosition;
            bool    updateForces   = true;

            switch (State)
            {
            case MovementEngineState.Moving:
                forces.Add(PlayerVehicle.Seek(positionToGoTo, 1));
                forces.Add(PlayerVehicle.AvoidObstacles(2));
                break;

            case MovementEngineState.DirectMoving:
                WowInterface.CharacterManager.MoveToPosition(targetPosition);
                updateForces = false;
                break;

            case MovementEngineState.Following:
                forces.Add(PlayerVehicle.Seek(positionToGoTo, 1));
                forces.Add(PlayerVehicle.Seperate(0.5f));
                forces.Add(PlayerVehicle.AvoidObstacles(2));
                break;

            case MovementEngineState.Chasing:
                forces.Add(PlayerVehicle.Seek(positionToGoTo, 1));
                break;

            case MovementEngineState.Fleeing:
                forces.Add(PlayerVehicle.Flee(positionToGoTo, 1));
                break;

            case MovementEngineState.Evading:
                forces.Add(PlayerVehicle.Evade(positionToGoTo, 1, TargetRotation));
                break;

            case MovementEngineState.Wandering:
                forces.Add(PlayerVehicle.Wander(1));
                break;

            case MovementEngineState.Stuck:
                forces.Add(PlayerVehicle.Unstuck(1));
                break;

            default:
                return;
            }

            if (DateTime.Now - LastJumpCheck > TimeSpan.FromMilliseconds(250))
            {
                double distanceTraveled = LastPosition.GetDistance(WowInterface.ObjectManager.Player.Position);
                if ((LastPosition.X == 0 && LastPosition.Y == 0 && LastPosition.Z == 0) || distanceTraveled < 0.01)
                {
                    ++TryCount;
                }
                else
                {
                    TryCount = 0;

                    // if (Straving)
                    // {
                    //     WowInterface.HookManager.LuaDoString("StrafeLeftStop();MoveBackwardStop();StrafeRightStop();MoveBackwardStop();");
                    //     Straving = false;
                    // }
                }

                // if the target position is higher than us, jump
                if (TryCount > 1 || (distanceToTargetPosition < 3 && currentPosition.Z + 2 < targetPosition.Z))
                {
                    WowInterface.CharacterManager.Jump();
                    TryCount = 0;

                    // if (DateTime.Now > StrafeEnd)
                    // {
                    //     int msToStrafe = Rnd.Next(1000, 5000);
                    //
                    //     if (Rnd.Next(0, 2) == 0)
                    //     {
                    //         WowInterface.HookManager.LuaDoString("StrafeLeftStart();MoveBackwardStart();");
                    //         Straving = true;
                    //     }
                    //     else
                    //     {
                    //         WowInterface.HookManager.LuaDoString("StrafeRightStart();MoveBackwardStart();");
                    //         Straving = true;
                    //     }
                    //
                    //     StrafeEnd = DateTime.Now + TimeSpan.FromMilliseconds(msToStrafe + 200);
                    // }
                }

                if (updateForces && !Straving)
                {
                    PlayerVehicle.Update(forces);
                }

                LastPosition           = WowInterface.ObjectManager.Player.Position;
                LastLastPositionUpdate = DateTime.Now;
                LastJumpCheck          = DateTime.Now;
            }

            LastTargetPosition = WowInterface.ObjectManager.Player.Position;
            HasMoved           = true;
        }
Exemplo n.º 5
0
        public void Execute()
        {
            if (CurrentPath.Count == 0 || CurrentPathTargetPosition.GetDistance(TargetPosition) > 1)
            {
                List <Vector3> nodes = GeneratePath.Invoke(GetPosition.Invoke(), TargetPosition);

                if (nodes.Count == 0)
                {
                    // pathfinding was unsuccessful
                    return;
                }

                foreach (Vector3 node in nodes)
                {
                    CurrentPath.Enqueue(node);
                }

                CurrentPathTargetPosition = TargetPosition;
            }

            List <Vector3> forces                   = new List <Vector3>();
            Vector3        currentPosition          = GetPosition.Invoke();
            Vector3        targetPosition           = CurrentPath.Peek();
            double         distanceToTargetPosition = currentPosition.GetDistance2D(targetPosition);

            if (distanceToTargetPosition < MovementSettings.WaypointCheckThreshold)
            {
                if (CurrentPath.Count > 0)
                {
                    targetPosition = CurrentPath.Dequeue();
                }
                else if (CurrentPath.Count == 0)
                {
                    return;
                }
            }

            Vector3 positionToGoTo = MoveAhead(targetPosition, 1.5);

            switch (State)
            {
            case MovementEngineState.Moving:
                forces.Add(PlayerVehicle.Seek(positionToGoTo, 1));
                break;

            case MovementEngineState.Following:
                forces.Add(PlayerVehicle.Seek(positionToGoTo, 1));
                forces.Add(PlayerVehicle.Seperate(1));
                break;

            case MovementEngineState.Chasing:
                forces.Add(PlayerVehicle.Pursuit(positionToGoTo, 1, TargetRotation));
                break;

            case MovementEngineState.Fleeing:
                forces.Add(PlayerVehicle.Flee(positionToGoTo, 1));
                break;

            case MovementEngineState.Evading:
                forces.Add(PlayerVehicle.Evade(positionToGoTo, 1, TargetRotation));
                break;

            case MovementEngineState.Wandering:
                forces.Add(PlayerVehicle.Wander(1));
                break;

            case MovementEngineState.Stuck:
                forces.Add(PlayerVehicle.Unstuck(1));
                break;

            default:
                return;
            }

            // move
            PlayerVehicle.Update(forces);

            if (DateTime.Now - LastJumpCheck > TimeSpan.FromMilliseconds(500))
            {
                double distanceTraveled = LastPosition.GetDistance(GetPosition.Invoke());
                if ((LastPosition.X == 0 && LastPosition.Y == 0 && LastPosition.Z == 0) || distanceTraveled < 0.5)
                {
                    Jump.Invoke();
                }

                LastPosition  = GetPosition.Invoke();
                LastJumpCheck = DateTime.Now;
            }

            HasMoved = true;
        }