Пример #1
0
        public void Escape(Route escapeRoute)
        {
            Globals.Instance.ExpFamingLogger.Log("Initiating escape from closest waypoint through " + escapeRoute.Name);
            Escaping = true;
            StopAttacking();
            StopRunning();

            StartRunning(escapeRoute, escapeRoute.ClosestWaypoint(_player.WaypointLocation), true);
        }
Пример #2
0
        //Tabs for enemies and reacts to outcome of attacking
        //It only restarts running in the cases that it has tried to attack something (so _running is then always false)
        private void AttackHandler(Route route, Route escapeRoute)
        {
            while (Attacking)
            {
                Thread.Sleep(Utils.getRandom(200, 400)); //Sleep before checking for targets again

                //First check if any enemies are attacking us
                Aggro = false;
                Globals.Instance.KeySenderInstance.SendKey(Keys.NumPad8, KeySender.ModifierControl);
                Character target = _player.GetTarget(_targetTwoBaseOffset);
                if (target != null)
                {
                    Globals.Instance.ExpFamingLogger.Log("Targeting aggressor...");
                    Aggro = true;
                }

                //If no aggro, make sure we aren't too far from first waypoint, then try regular targetting
                if (target == null)
                {
                    //If no aggro and attacking-spree has taken player too far from first point on route, run back there
                    //AttackThread is slept until player is back at that waypoint
                    if (!StandStill && _player.WaypointLocation.Distance(route.ClosestWaypoint(_player.WaypointLocation)) > MaxDistanceFromPath)
                    {
                        Globals.Instance.ExpFamingLogger.Log("Now too far from closest waypoint. Returning to waypoint 1...");
                        StartRunning(route, route.Points[0], true);
                        continue;
                    }

                    Globals.Instance.KeySenderInstance.SendKey(Keys.Tab);
                    target = _player.GetTarget(_targetBaseOffset);
                }

                //If any enemy targeted, attack it
                if (target != null)
                {
                    if (!Aggro && StandStill)
                    {
                        while (Attacking && target.WaypointLocation.Distance(_player.WaypointLocation) > MaxPullingDistance)
                        {
                            Globals.Instance.KeySenderInstance.SendKey(Keys.Tab);
                            target = _player.GetTarget(_targetBaseOffset);
                            Thread.Sleep(Utils.getRandom(500, 1000));
                        }
                    }

                    //If this is the first enemy we target while running loop, then Running bool == true.
                    //If it is a new enemy, then it is false. Check is done in method
                    StopRunning();

                    string attackOutcome = _player.AttackTarget(target);

                    switch (attackOutcome)
                    {
                    case "escape":
                        if (StandStill)
                        {
                            return;
                        }
                        Globals.Instance.ExpFamingLogger.Log("Danger in battle, initiating escape...");
                        RestartExpFarming = true;
                        Escape(escapeRoute);
                        return;

                    case "Stuck. Jumping not successful.":
                        Globals.Instance.ExpFamingLogger.Log("Stuck. Jumping not successful. Attempting to turn around and pick another target...");
                        Globals.Instance.KeySenderInstance.SendKey(Keys.Escape);
                        _player.Turn180();
                        break;

                    case "target too far":
                        Globals.Instance.ExpFamingLogger.Log("Target now too far away. Proceeding to search for next target...");
                        Globals.Instance.KeySenderInstance.SendKey(Keys.Escape);
                        break;

                    case ("target defeated"):
                        Globals.Instance.ExpFamingLogger.Log("Attack successful. Proceeding to search for next target...");
                        break;

                    case ("attack cancelled"):
                        Globals.Instance.ExpFamingLogger.Log("Attack cancelled...");
                        return;
                    }
                    continue;
                }

                //No target found, going back to closest current waypoint and start running path again while searching for targets
                //Globals.Instance.ExpFamingLogger.Log("Could not find any targets. Continuing on path...");
                if (StandStill)
                {
                    continue;
                }

                StartRunning(route, route.ClosestWaypoint(_player.WaypointLocation), false);
            }

            //Important because attacking can be stopped while w is still pressed
            ReleaseAllButtons();

            Globals.Instance.ExpFamingLogger.Log("AttackHandler thread terminated...");
        }