Jump to content

How can i make the bot attack the closest target in AV?


Recommended Posts

The bot tends to target someone super far away and walk through a group of enemies before it gets to the target, making it look very obvious its a bot.
How can i make the bot attack the closest target to me while ignoring pets? Im want this mostly for bridge fights in AV

Link to comment
Share on other sites

I did some research and created my own pluging. It is kinda janky but seems to work well enough for what i want.
Any suggestions on how to improve it are appreciated.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using robotManager.Helpful;
using wManager.Plugin;
using wManager.Wow.Helpers;
using wManager.Wow.ObjectManager;


public class Main : IPlugin
{
    private bool __isRunning;

    private string __zone;

    private List<WoWPlayer> __hordePlayers;

    private System.Timers.Timer __bgTimer;
    private System.Timers.Timer __workTimer;
    private System.Timers.Timer __restTimer;
    public void Initialize()
    {
        __isRunning = true;
        Logging.Write("BG Assist plugin started");

        __hordePlayers = new List<WoWPlayer>();

        __bgTimer = new System.Timers.Timer();
        __bgTimer.Interval = 60 * 60 * 1000; //1h
        __bgTimer.Elapsed += LeaveBg;
        __bgTimer.AutoReset = false;

        __workTimer = new System.Timers.Timer();
        __workTimer.Interval = 3 * 60 * 1000; // 3 mins
        __workTimer.Elapsed += PauseBot;
        __workTimer.AutoReset = false;

        __restTimer = new System.Timers.Timer();
        __restTimer.Interval = 2 * 60 * 1000; // 2 mins
        __restTimer.Elapsed += ResumeBot;
        __restTimer.AutoReset = false;

        MainLoop();
    }

    public void Dispose()
    {
        __isRunning = false;

        __bgTimer.Stop();
        __workTimer.Stop();
        __restTimer.Stop();

        __bgTimer.Elapsed -= LeaveBg;
        __workTimer.Elapsed -= PauseBot;
        __restTimer.Elapsed -= ResumeBot;

        Logging.Write("BG Assist plugin stopped");

    }

    public void Settings()
    {
        
    }

    private void MainLoop()
    {
        while (__isRunning)
        {
            if (Conditions.InGameAndConnectedAndProductStarted)
            {
                __zone = Usefuls.MapZoneName;

                if (__zone == "Alterac Valley" && !__bgTimer.Enabled)
                {
                    // play for 1 hour max then leave the BG
                    Logging.Write("BG Assist - timer started");
                    __bgTimer.Start();

                    // play for 3 mins, rest for 2 mins
                    __workTimer.Start();
                }

                // Try to always fight the closest target
                if (__zone == "Alterac Valley" && !Conditions.ProductInPause && ObjectManager.Me.IsAlive && (!ObjectManager.Me.InCombat || !ObjectManager.Me.HasTarget))
                {
                    if (ObjectManager.GetObjectWoWPlayer().Any(x => x.IsHorde))
                    {
                        __hordePlayers = new List<WoWPlayer>();

                        // Grab a list of players and add all horde units to a list
                        foreach (WoWPlayer _unit in ObjectManager.GetObjectWoWPlayer())
                        {
                            if (_unit.IsHorde && _unit.IsAlive)
                            {
                                __hordePlayers.Add(_unit);
                            }
                        }

                        // Spammy but useful for now...
                        Logging.Write($"BG Assist - starting fight with...{__hordePlayers.OrderBy(x => x.Position.DistanceTo(ObjectManager.Me.Position)).FirstOrDefault().Name}");
                        Fight.StopFight();
                        Fight.StartFight(__hordePlayers.OrderBy(x => x.Position.DistanceTo(ObjectManager.Me.Position)).FirstOrDefault().Guid, false);
                    }
                }
            }

            Thread.Sleep(1000);
        }

    }

    private void LeaveBg(Object source, System.Timers.ElapsedEventArgs e)
    {
        Logging.Write($"BG Assist plugin - This bg has run for more than an hour. Taking a break...");
        Battleground.ExitBattleGround();
        __bgTimer.Stop();
        Thread.Sleep(10000);

    }

    private void PauseBot(Object source, System.Timers.ElapsedEventArgs e)
    {
        if (__zone == "Alterac Valley")
        {
            Logging.Write("BG Assist - resting...");
            robotManager.Products.Products.InPause = true;
            __restTimer.Start();
        }
    }

    private void ResumeBot(Object source, System.Timers.ElapsedEventArgs e)
    {
        Logging.Write("BG Assist - working again...");
        robotManager.Products.Products.InPause = false;
        __workTimer.Start();

    }
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...