예제 #1
0
 public GoalFactory(AddonReader addonReader, ILogger logger, WowProcess wowProcess, NpcNameFinder npcNameFinder)
 {
     this.logger        = logger;
     this.addonReader   = addonReader;
     this.NpcNameFinder = npcNameFinder;
     this.wowProcess    = wowProcess;
 }
예제 #2
0
        public BotController(ILogger logger)
        {
            wowProcess     = new WowProcess(logger);
            this.WowScreen = new WowScreen(logger);
            this.logger    = logger;

            var frames = DataFrameConfiguration.ConfigurationExists()
                ? DataFrameConfiguration.LoadConfiguration()
                : new List <DataFrame>(); //config.CreateConfiguration(WowScreen.GetAddonBitmap());

            AddonReader = new AddonReader(WowScreen, frames, logger);

            addonThread = new Thread(AddonRefreshThread);
            addonThread.Start();

            // wait for addon to read the wow state
            while (AddonReader.PlayerReader.Sequence == 0 || !Enum.GetValues(typeof(PlayerClassEnum)).Cast <PlayerClassEnum>().Contains(AddonReader.PlayerReader.PlayerClass))
            {
                logger.LogWarning("There is a problem with the addon, I have been unable to read the player class. Is it running ?");
                Thread.Sleep(100);
            }

            npcNameFinder = new NpcNameFinder(wowProcess, AddonReader.PlayerReader, logger);
            ActionFactory = new ActionFactory(AddonReader, logger, wowProcess, npcNameFinder);

            screenshotThread = new Thread(ScreenshotRefreshThread);
            screenshotThread.Start();
        }
예제 #3
0
        public static Bitmap GetAddonBitmap(int width = 600, int height = 200)
        {
            RECT    rect       = new RECT();
            Process?wowProcess = WowProcess.Get();

            if (WowProcess.Get() != null)
            {
#pragma warning disable CS8602 // 可能 null 參考的取值 (dereference)。
                var handle = wowProcess.MainWindowHandle;
#pragma warning restore CS8602 // 可能 null 參考的取值 (dereference)。
                NativeMethods.GetWindowRect(handle, ref rect);
            }

            int bottom       = rect.bottom;                   //= 609;
            int left         = rect.left;                     //-9;
            int leftoffset   = 9;                             //-9;
            int rightoffset  = 7;                             //-9;
            int right        = rect.right;                    //809;
            int top          = rect.top;                      //-29;
            int topoffset    = 29;                            //-29;
            int bottomoffset = 9;                             //-29;

            width  = right - left - leftoffset - rightoffset; // 817 - 1 800 8+1
            height = bottom - top - topoffset - bottomoffset; // 638 - 0 600 29

            var bmpScreen = new Bitmap(width, height);
            using (var graphics = Graphics.FromImage(bmpScreen))
            {
                graphics.CopyFromScreen(left + leftoffset, top + topoffset, 0, 0, bmpScreen.Size);
            }
            return(bmpScreen);
        }
예제 #4
0
        public StuckDetector(PlayerReader playerReader, WowProcess wowProcess, IPlayerDirection playerDirection, StopMoving stopMoving, ILogger logger)
        {
            this.playerReader    = playerReader;
            this.wowProcess      = wowProcess;
            this.stopMoving      = stopMoving;
            this.logger          = logger;
            this.playerDirection = playerDirection;

            ResetStuckParameters();
        }
예제 #5
0
        public async Task FindAndClickNpc(int threshold)
        {
            //if (!canFindNpcs) { return; }

            if (this.playerReader.HasTarget)
            {
                return;
            }

            var npc = GetClosestNpc();

            if (npc != null)
            {
                if (npc.Height >= threshold)
                {
                    var locations = new List <Point>
                    {
                        new Point(0, 0),
                        new Point(10, 10),
                        new Point(-10, -10),
                        new Point(20, 20),
                        new Point(-20, -20),
                    };

                    foreach (var location in locations)
                    {
                        var clickPostion = Screenshot.ToScreenCoordinates(npc.ClickPoint.X + location.X, npc.ClickPoint.Y + location.Y);

                        clickPostion.X = wowProcess.ScaleDown(clickPostion.X);
                        clickPostion.Y = wowProcess.ScaleDown(clickPostion.Y);

                        WowProcess.SetCursorPosition(clickPostion);
                        await Task.Delay(100);

                        CursorClassifier.Classify(out var cls).Dispose();
                        if (cls == CursorClassification.Kill)
                        {
                            await AquireTargetAtCursor(clickPostion, npc);

                            return;
                        }
                    }
                }
                else
                {
                    logger.LogInformation($"{ this.GetType().Name}.FindAndClickNpc: NPC found but below threshold {threshold}! Height={npc.Height}, width={npc.Width}");
                }
            }
            else
            {
                logger.LogInformation($"{ this.GetType().Name}.FindAndClickNpc: No NPC found!");
            }
        }
예제 #6
0
        public BotController(ILogger logger, IPPather pather)
        {
            wowProcess = new WowProcess(logger);
            wowProcess.KeyPress(ConsoleKey.F3, 400).Wait(); // clear target
            this.WowScreen = new WowScreen(logger);
            this.logger    = logger;
            this.pather    = pather;

            var frames = DataFrameConfiguration.ConfigurationExists()
                ? DataFrameConfiguration.LoadConfiguration()
                : new List <DataFrame>(); //config.CreateConfiguration(WowScreen.GetAddonBitmap());

            AddonReader = new AddonReader(WowScreen, frames, logger);

            minimapNodeFinder  = new MinimapNodeFinder(new PixelClassifier());
            MinimapImageFinder = minimapNodeFinder as IImageProvider;

            addonThread = new Thread(AddonRefreshThread);
            addonThread.Start();

            // wait for addon to read the wow state
            var sw = new Stopwatch();

            sw.Start();
            while (AddonReader.PlayerReader.Sequence == 0 || !Enum.GetValues(typeof(PlayerClassEnum)).Cast <PlayerClassEnum>().Contains(AddonReader.PlayerReader.PlayerClass))
            {
                if (sw.ElapsedMilliseconds > 5000)
                {
                    logger.LogWarning("There is a problem with the addon, I have been unable to read the player class. Is it running ?");
                    sw.Restart();
                }
                Thread.Sleep(100);
            }

            logger.LogDebug($"Woohoo, I have read the player class. You are a {AddonReader.PlayerReader.PlayerClass}.");

            npcNameFinder = new NpcNameFinder(wowProcess, AddonReader.PlayerReader, logger);
            //ActionFactory = new GoalFactory(AddonReader, logger, wowProcess, npcNameFinder);

            screenshotThread = new Thread(ScreenshotRefreshThread);
            screenshotThread.Start();
        }
예제 #7
0
 public NpcNameFinder(WowProcess wowProcess, PlayerReader playerReader, ILogger logger)
 {
     this.wowProcess   = wowProcess;
     this.logger       = logger;
     this.playerReader = playerReader;
 }
예제 #8
0
 public PlayerDirection(PlayerReader playerReader, WowProcess wowProcess, ILogger logger)
 {
     this.playerReader = playerReader;
     this.wowProcess   = wowProcess;
     this.logger       = logger;
 }