예제 #1
0
파일: MoveToState.cs 프로젝트: uvbs/babbot
        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);
            }
        }