Пример #1
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...");
        }
Пример #2
0
        private void RunningHandler(Route route, Waypoint waypoint)
        {
            //Check if too close to starting-waypoint
            if (_player.WaypointLocation.Distance(waypoint) < 5)
            {
                Globals.Instance.ExpFamingLogger.Log("Too close to starting waypoint. Skipping to next waypoint...");
                waypoint = route.NextWaypoint(waypoint);
            }

            Globals.Instance.KeySenderInstance.SendDown(Keys.W);

            while (Running)
            {
                Globals.Instance.ExpFamingLogger.Log("Running to point: " + route.Points.IndexOf(waypoint));
                string runningOutcome = _player.RunToPoint(waypoint, () => Running);

                switch (runningOutcome)
                {
                case ("died"):
                    Globals.Instance.ExpFamingLogger.Log("Died while running...");
                    MainForm.Get.BeginInvoke(MainForm.Get.SEFDelegate);
                    return;

                case ("stuck"):
                    Globals.Instance.ExpFamingLogger.Log("Stuck while running. Trying to turn and select new point");
                    _player.Turn180();
                    break;

                case ("point reached"):
                    Globals.Instance.ExpFamingLogger.Log("Reached point: " + route.Points.IndexOf(waypoint));
                    break;

                case ("running cancelled"):
                    Globals.Instance.ExpFamingLogger.Log("RunToPoint() cancelled");
                    return;
                }

                //We have reached end of escape route
                if (Escaping && (waypoint == route.Points.Last()))
                {
                    Globals.Instance.ExpFamingLogger.Log("End of escape route reached..");

                    if (RestartExpFarming)
                    {
                        Globals.Instance.ExpFamingLogger.Log("Escape successful. Exp farming restarting shortly...");
                        //It does not matter that the minutes here is small
                        //because when the farming restarts the player waits until healed
                        const int minutesToRestart = 1;
                        var       timer            = new Timer {
                            Interval = minutesToRestart * 60000, AutoReset = false
                        };
                        timer.Elapsed += OnTimedEvent_ExpFarmingRestart;
                        timer.Start();
                    }

                    MainForm.Get.BeginInvoke(MainForm.Get.SEFDelegate);
                    return;
                }

                waypoint = route.NextWaypoint(waypoint);
            }

            //Important because running is often stopped while w/a/d is still pressed
            ReleaseAllButtons();

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