Beispiel #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);
        }
Beispiel #2
0
        /// <summary>
        /// Update all player informations: hp,mana,xp,position,etc...
        /// </summary>
        public static void UpdatePlayer()
        {
            if (_gstatus != GameStatuses.INITIALIZED)
            {
                return;
            }

            if (PlayerUpdate != null)
            {
                PlayerUpdate();
            }

            //update last player location
            Player.LastLocation = Player.Location;

            if (PlayerWayPoint != null)
            {
                Vector3D current = Player.Location;
                WayPoint wpLast  = (WayPointManager.Instance.NormalNodeCount > 0) ?
                                   WayPointManager.Instance.NormalPath[WayPointManager.Instance.NormalPath.Count - 1] : null;

                if (wpLast != null && MathFuncs.GetDistance(current, wpLast.Location, false) > 5 || wpLast == null)
                {
                    PlayerWayPoint(current);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// We are roaming through the waypoints with nothing else to do
        /// </summary>
        protected override void DoExecute(WowPlayer entity)
        {
            WayPoint wp = null;

            Output.Instance.Script("Checking if we have a last waypoint defined", this);
            if (LastWayPoint != null)
            {
                Output.Instance.Script("We have a last waypoint. Checking if we reached it", this);

                float distanceFromLast = MathFuncs.GetDistance(LastWayPoint.Location, entity.Location, false);
                if (distanceFromLast <= 3.0f)
                {
                    Output.Instance.Script("We reached the last waypoint. Let's get a new one", this);
                    wp = WayPointManager.Instance.GetNextWayPoint(WayPointType.Normal);
                }
                else
                {
                    Output.Instance.Script("We still need to reach the last waypoint. We reuse the last one.", this);
                    wp = LastWayPoint;
                }
            }
            else
            {
                Output.Instance.Script("This is the first waypoint. We try to get a new one.", this);
                wp = WayPointManager.Instance.GetNextWayPoint(WayPointType.Normal);
            }

            // Id we do have a waypoint we actually move
            if (wp != null)
            {
                LastWayPoint = wp;
                Output.Instance.Script(string.Format("Moving to waypoint. Index:{0}", WayPointManager.Instance.CurrentNormalWayPointIndex), this);
                Output.Instance.Script(string.Format("WayPoint: X:{0} Y:{1} Z:{2}", wp.Location.X, wp.Location.Y, wp.Location.Z), this);
                //MoveTo(wp.Location);
                float distance = MathFuncs.GetDistance(wp.Location, entity.Location, false);
                if (distance > 3.0f)
                {
                    var mtsTarget = new MoveToState(wp.Location, 3.0f);

                    //request that we move to this location
                    CallChangeStateEvent(entity, mtsTarget, true, false);

                    return;
                }
            }
            else
            {
                Output.Instance.Script("We are supposed to walk through waypoints but there's no waypoints defined", this);
            }
        }
Beispiel #4
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;
        }
Beispiel #5
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);
            }
        }
Beispiel #6
0
        /// <summary>
        /// This happens when we are being attacked by some mobs or when we
        /// have found something to kill
        /// </summary>
        protected override void DoExecute(WowPlayer entity)
        {
            Output.Instance.Script("OnPreCombat() Begin", this);

            DateTime start = DateTime.Now;

            if (entity.IsBeingAttacked())
            {
                Output.Instance.Script("OnPreCombat() - We are being attacked", this);
                /// We are being attacked by a Mob. That means that we should fight back
                /// by finding the mob first of all
                if (entity.SelectWhoIsAttackingUsWithCTM())
                {
                    /// We found who is attacking us and we fight back (no rebuffing now)
                    /// (If everything is correct at this point the StateManager will take care
                    /// of switching to the OnCombat state)
                    MobToAttack     = entity.CurTarget;
                    AttackTimeStart = DateTime.Now; // Reset the time check for blacklisting mobs
                }
            }
            else
            {
                Output.Instance.Script("OnPreCombat() - We are going to attack someone", this);

                // Check if we already have a valid Unit to attack from a previous state
                if (MobToAttack == null)
                {
                    Output.Instance.Script("Looking for a new enemy to attack", this);
                    // Find a new mob to attack
                    if (entity.EnemyInSight())
                    {
                        Output.Instance.Script("We have something", this);
                        MobToAttack = entity.GetClosestEnemyInSight();
                        if (MobToAttack != null)
                        {
                            Output.Instance.Script(
                                string.Format("The mob we're going to attack is a {0} with GUID {1:X}",
                                              MobToAttack.Name, MobToAttack.Guid), this);
                            AttackTimeStart = DateTime.Now; // Reset the time check for blacklisting mobs
                        }
                        else
                        {
                            Output.Instance.Script("Couldn't find the closest enemy in sight", this);
                        }
                    }
                }

                // Check if this is good
                if (MobToAttack != null)
                {
                    Output.Instance.Script("We have a mob, checking if it's dead", this);
                    if (!MobToAttack.IsDead)
                    {
                        TimeSpan attackTimeDiff = start - AttackTimeStart;
                        if (attackTimeDiff.TotalMilliseconds > 10000)
                        {
                            Output.Instance.Script("We spent more than 10 seconds trying to attack the same mob without reaching it. Moving on and blacklisting it.", this);
                            entity.MobBlackList.Add(MobToAttack);
                            MobToAttack = null;
                            return;
                        }

                        Output.Instance.Script("Checking distance", this);
                        float distance = MathFuncs.GetDistance(MobToAttack.Location, entity.Location, false);
                        if (distance > 10.0f)
                        {
                            Output.Instance.Script("We're too far to CTM it, moving closer first", this);
                            var mtsTarget = new MoveToState(MobToAttack.Location, 3.0f);

                            //request that we move to this location
                            CallChangeStateEvent(entity, mtsTarget, true, false);

                            return;
                        }

                        Output.Instance.Script("Attacking it with CTM", this);
                        TimeSpan timeDiff = start - LastCtmCheck;
                        if (timeDiff.TotalMilliseconds > 2000)
                        {
                            entity.AttackMobWithCTM(MobToAttack);
                            LastCtmCheck = DateTime.Now;
                        }
                    }
                    else
                    {
                        Output.Instance.Script("The mob we were looking for is dead :(", this);
                        MobToAttack = null;
                    }
                }

                /*
                 * if (entity.EnemyInSight())
                 * {
                 *  // Face the closest enemy
                 *  Output.Instance.Script("OnPreCombat() - Facing closest enemy (we should get a target this way)", this);
                 *  //entity.FaceClosestEnemy();
                 *  //entity.AttackClosestEnemyWithCTM();
                 *  // Get the enemy unit and save it
                 *  // Check that it's not dead or anything like that
                 *  // Move to it
                 *
                 *  entity.MoveToClosestEnemy();
                 *
                 *  // Let's check if we actually got it as our target
                 *  if ((entity.HasTarget) && (!entity.IsTargetDead()) && (entity.IsTargetInEnemyList()))
                 *  {
                 *      Output.Instance.Script("OnPreCombat() - Affirmative. We have a target", this);
                 *      /// Ok, we have the target, it's time to start attacking,
                 *      /// but first we rebuff and drink up just in case
                 *  }
                 *  else
                 *  {
                 *      // Let's try moving closer. We should already be facing our wanted target
                 *      // TODO: Change this so that we use clicktomove instead
                 *      entity.MoveForward(1000);
                 *      Output.Instance.Script("OnPreCombat() - Can't target. This should not happen :-P", this);
                 *  }
                 * }
                 * */
            }
        }