/// <summary>
            /// Generates a markup for a menu option in Overwatch.
            /// </summary>
            /// <param name="slot">Slot to generate markup from.</param>
            /// <param name="max">Maximum markups to capture.</param>
            /// <param name="savelocation">Location to save markups.</param>
            /// <param name="yincrement">Amount to skip on Y axis after every markup capture.</param>
            public void MenuOptionMarkup(int slot, int max, string savelocation, double yincrement = 11.5)
            {
                if (!cg.IsSlotValid(slot))
                {
                    throw new InvalidSlotException(string.Format("Slot argument '{0}' is out of range.", slot));
                }

                Point slotlocation = OpenSlotMenu(slot);

                // Get direction opened menu is going.
                Direction dir = Getmenudirection(slotlocation);

                int[] offset = OffsetViaDirection(dir);

                int xstart = slotlocation.X + 14, // X position to start scanning
                    xmax   = 79,                  // How far on the X axis to scan
                    ystart = 0,                   // Y position to start scanning
                    ymax   = 6;                   // How far on the Y axis to scan.

                if (dir == Direction.RightDown)
                {
                    ystart = slotlocation.Y + 12;
                }
                else if (dir == Direction.RightUp)
                {
                    ystart     = slotlocation.Y - 128;
                    yincrement = -yincrement;
                }

                cg.updateScreen();
                for (int mi = 0, yii = ystart; mi < max; mi++, yii = ystart + (int)(yincrement * (mi))) // Mi is the line to scan, yii is the Y coordinate of line mi.
                {
                    // Get bitmap of option
                    Bitmap work = cg.BmpClone(xstart, yii, xmax, ymax);

                    for (int xi = 0; xi < work.Width; xi++)
                    {
                        for (int yi = 0; yi < work.Height; yi++)
                        {
                            int   fade      = 80;
                            int[] textcolor = new int[] { 169, 169, 169 };
                            if (work.CompareColor(xi, yi, textcolor, fade))
                            {
                                work.SetPixel(xi, yi, Color.Black);
                            }
                            else
                            {
                                work.SetPixel(xi, yi, Color.White);
                            }
                        }
                    }
                    work.Save(savelocation + "markup-" + (mi).ToString() + ".png");
                    work.Dispose();
                }

                // Close the menu.
                cg.LeftClick(400, 500, 100);
                cg.LeftClick(500, 500, 100);
                cg.ResetMouse();
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Swap 2 slots with eachother.
            /// </summary>
            /// <param name="slot1">Target 1</param>
            /// <param name="slot2">Target 2</param>
            /// <exception cref="InvalidSlotException">Thrown if the slot1 or slot2 argument is out of range of possible slots to move.</exception>
            // Swap slots
            public void Move(int slot1, int slot2)
            {
                if (!cg.IsSlotValid(slot1))
                {
                    throw new InvalidSlotException(string.Format("slot1 argument '{0}' is out of range.", slot1));
                }
                if (!cg.IsSlotValid(slot2))
                {
                    throw new InvalidSlotException(string.Format("slot2 argument '{0}' is out of range.", slot2));
                }

                cg.ResetMouse();

                cg.updateScreen();
                if (cg.DoesAddButtonExist())
                {
                    cg.LeftClick(661, 180, 25);
                }
                else
                {
                    cg.LeftClick(717, 180, 25);
                }

                Point slot1loc = FindSlotLocation(slot1); // Get the location of the target
                Point slot2loc = FindSlotLocation(slot2); // Get the location of the destination

                cg.LeftClick(slot1loc.X, slot1loc.Y, 25); // Click the target
                cg.LeftClick(slot2loc.X, slot2loc.Y, 25); // Click the destination

                Thread.Sleep(200);

                ExitMoveMenu();
            }
Ejemplo n.º 3
0
        /// <summary>
        /// Swap 2 slots with eachother.
        /// </summary>
        /// <param name="targetSlot">Target 1</param>
        /// <param name="destinationSlot">Target 2</param>
        /// <exception cref="InvalidSlotException">Thrown if the <paramref name="targetSlot"/> or <paramref name="destinationSlot"/> argument is out of range of possible slots to move.</exception>
        public void Move(int targetSlot, int destinationSlot)
        {
            if (!CustomGame.IsSlotValid(targetSlot))
            {
                throw new InvalidSlotException(string.Format("targetSlot argument '{0}' is out of range.", targetSlot));
            }
            if (!CustomGame.IsSlotValid(destinationSlot))
            {
                throw new InvalidSlotException(string.Format("destinationSlot argument '{0}' is out of range.", destinationSlot));
            }

            cg.ResetMouse();

            cg.updateScreen();
            if (cg.DoesAddButtonExist())
            {
                cg.LeftClick(Points.LOBBY_MOVE_IF_ADD_BUTTON_PRESENT, 25);
            }
            else
            {
                cg.LeftClick(Points.LOBBY_MOVE_IF_ADD_BUTTON_NOT_PRESENT, 25);
            }

            Point targetSlotLoc      = FindSlotLocation(targetSlot);
            Point destinationSlotLoc = FindSlotLocation(destinationSlot);

            cg.LeftClick(targetSlotLoc, 25);
            cg.LeftClick(destinationSlotLoc, 25);

            Thread.Sleep(200);

            ExitMoveMenu();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Scans a player menu for an option.
        /// </summary>
        /// <param name="slot">Slot's menu to scan.</param>
        /// <param name="markup">Bitmap markup of option to scan for.</param>
        /// <param name="minimumPercent">Minimum percent the markup has to match an option in the menu.</param>
        /// <param name="max">Maximum options to scan.</param>
        /// <param name="yincrement">Amount to skip on Y axis after every markup scan.</param>
        /// <returns>Returns true if the option in the markup has been found, else returns false.</returns>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        public bool MenuOptionScan(int slot, Bitmap markup, int minimumPercent, int max, double yincrement = 11.5)
        {
            if (!CustomGame.IsSlotValid(slot))
            {
                throw new InvalidSlotException(slot);
            }

            Point slotlocation = OpenSlotMenu(slot);

            if (slotlocation.IsEmpty)
            {
                return(false);
            }

            Point optionLocation = MenuOptionScan(slotlocation, markup, minimumPercent, max, yincrement);

            if (optionLocation.IsEmpty)
            {
                cg.CloseOptionMenu();
                return(false);
            }
            else
            {
                SelectMenuOption(optionLocation);
                return(true);
            }
        }
        /// <summary>
        /// Swap 2 slots with eachother.
        /// </summary>
        /// <param name="targetSlot">Target 1</param>
        /// <param name="destinationSlot">Target 2</param>
        /// <exception cref="InvalidSlotException">Thrown if the <paramref name="targetSlot"/> or <paramref name="destinationSlot"/> argument is out of range of possible slots to move.</exception>
        public void Move(int targetSlot, int destinationSlot)
        {
            using (cg.LockHandler.Interactive)
            {
                if (!CustomGame.IsSlotValid(targetSlot))
                {
                    throw new InvalidSlotException($"{nameof(targetSlot)} '{targetSlot}' is out of range.");
                }
                if (!CustomGame.IsSlotValid(destinationSlot))
                {
                    throw new InvalidSlotException($"{nameof(destinationSlot)} '{destinationSlot}' is out of range.");
                }

                //cg.//ResetMouse();

                cg.UpdateScreen();
                if (cg.DoesAddButtonExist())
                {
                    cg.LeftClick(Points.LOBBY_MOVE_IF_ADD_BUTTON_PRESENT, 250);
                }
                else
                {
                    cg.LeftClick(Points.LOBBY_MOVE_IF_ADD_BUTTON_NOT_PRESENT, 250);
                }

                Point targetSlotLoc      = FindSlotLocation(targetSlot);
                Point destinationSlotLoc = FindSlotLocation(destinationSlot);
                cg.LeftClick(targetSlotLoc, 250);
                cg.LeftClick(destinationSlotLoc, 250);

                ExitMoveMenu();
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Safely removes a slot from the game if they are an AI.
        /// </summary>
        /// <param name="slot">Slot to remove from game.</param>
        /// <returns>Returns true if the slot is an AI and removing them from the game was successful.</returns>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        /// <seealso cref="RemoveAllBotsAuto"/>
        /// <seealso cref="Interact.RemoveFromGame(int)"/>
        public bool RemoveFromGameIfAI(int slot)
        {
            if (!CustomGame.IsSlotValid(slot))
            {
                throw new InvalidSlotException(slot);
            }

            Point slotLocation = cg.Interact.OpenSlotMenu(slot);

            if (slotLocation.IsEmpty)
            {
                return(false);
            }

            if (cg.Interact.MenuOptionScan(slotLocation, Interact.RemoveAllBotsMarkup, 80, 6).IsEmpty)
            {
                cg.CloseOptionMenu();
                return(false);
            }

            Point removeFromGameOptionLocation = cg.Interact.MenuOptionScan(slotLocation, Interact.RemoveFromGameMarkup, 80, 6);

            if (removeFromGameOptionLocation.IsEmpty)
            {
                cg.CloseOptionMenu();
                return(false);
            }

            return(cg.Interact.SelectMenuOption(removeFromGameOptionLocation));
        }
        internal Point FindSlotLocation(int slot, bool noUpdate = false)
        {
            if (!CustomGame.IsSlotValid(slot))
            {
                throw new InvalidSlotException(slot);
            }

            if (!noUpdate)
            {
                cg.UpdateScreen();
            }

            int yoffset = 0;
            int xoffset = 0;

            /*
             * if (cg.IsDeathmatch(true))
             * {
             *  if (CustomGame.IsSlotBlue(slot))
             *  {
             *      xoffset += Distances.LOBBY_SLOT_DM_BLUE_X_OFFSET;
             *      yoffset += Distances.LOBBY_SLOT_DM_Y_OFFSET;
             *  }
             *  else if (CustomGame.IsSlotRed(slot))
             *  {
             *      xoffset += Distances.LOBBY_SLOT_DM_RED_X_OFFSET;
             *      yoffset += Distances.LOBBY_SLOT_DM_Y_OFFSET;
             *  }
             * }
             */

            if (CustomGame.IsSlotInQueue(slot) && !cg.CheckRange(CustomGame.QueueMin, CustomGame.QueueMax, 0, true).Contains(slot))
            {
                return(Point.Empty);                                                                                                                    // If a queue slot is selected and there is no one in that queue slot, return empty.
            }
            if (CustomGame.IsSlotSpectator(slot))
            {
                yoffset = cg.FindSpectatorOffset(true);                                   // If there is players in the queue, the spectator slots move down. Find the offset in pixels to spectator.
            }
            if (CustomGame.IsSlotSpectatorOrQueue(slot))
            {
                xoffset = -150;                                          // Prevents the player context menu from orientating left for slots in the spectator and queue.
            }
            if (CustomGame.IsSlotInQueue(slot))
            {
                slot = slot - 6;                                                                                 // selecting a person in the queue where spectator slots are normally at.
            }
            return(new Point(Points.SLOT_LOCATIONS[slot].X + xoffset, Points.SLOT_LOCATIONS[slot].Y + yoffset)); // Blue, Red, Spectators, and all of queue except for the first slot.
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Safely removes a slot from the game if they are an AI.
        /// </summary>
        /// <param name="slot">Slot to remove from game.</param>
        /// <returns>Returns true if the slot is an AI and removing them from the game was successful.</returns>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        /// <seealso cref="RemoveAllBotsAuto"/>
        /// <seealso cref="Interact.RemoveFromGame(int)"/>
        public bool RemoveFromGameIfAI(int slot)
        {
            using (cg.LockHandler.SemiInteractive)
            {
                if (!CustomGame.IsSlotValid(slot))
                {
                    throw new InvalidSlotException(slot);
                }

                bool optionFound = (bool)cg.Interact.MenuOptionScan(slot, OptionScanFlags.OpenMenu | OptionScanFlags.CloseIfNotFound | OptionScanFlags.ReturnFound, null, Markups.REMOVE_ALL_BOTS);

                if (!optionFound)
                {
                    return(false);
                }

                return((bool)cg.Interact.MenuOptionScan(slot, OptionScanFlags.Click | OptionScanFlags.CloseIfNotFound | OptionScanFlags.ReturnFound, null, Markups.REMOVE_FROM_GAME));
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Checks if the input slot is an AI.
        /// </summary>
        /// <remarks>
        /// IsAI() is faster but requires calling CalibrateAIChecking() beforehand. However this is more accurate and does not require calling CalibrateAIChecking().
        /// </remarks>
        /// <param name="slot">Slot to check.</param>
        /// <returns>Returns true if slot is AI.</returns>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        /// <seealso cref="IsAI(int, bool)"/>
        public bool AccurateIsAI(int slot)
        {
            if (!CustomGame.IsSlotValid(slot))
            {
                throw new InvalidSlotException(slot);
            }

            Point slotLocation = cg.Interact.OpenSlotMenu(slot);

            if (slotLocation.IsEmpty)
            {
                return(false);
            }

            bool removeAllBotsFound = !cg.Interact.MenuOptionScan(slotLocation, Interact.RemoveAllBotsMarkup, 80, 6).IsEmpty;

            cg.CloseOptionMenu();

            return(removeAllBotsFound);
        }
Ejemplo n.º 10
0
            /// <summary>
            /// Gets the difficulty of the AI in the input slot.
            /// <para>If the input slot is not an AI, returns null.
            /// If checking an AI's difficulty in the queue, it will always return easy, or null if it is a player.</para>
            /// </summary>
            /// <param name="slot">Slot to check</param>
            /// <param name="noUpdate"></param>
            /// <returns>Returns a value in the Difficulty enum if the difficulty is found. Returns null if the input slot is not an AI.</returns>
            /// <exception cref="InvalidSlotException">Thrown when slot is out of range.</exception>
            public Difficulty?GetAIDifficulty(int slot, bool noUpdate = false)
            {
                if (!cg.IsSlotValid(slot))
                {
                    throw new InvalidSlotException(string.Format("Slot {0} is out of range of possible slots to check for AI.", slot));
                }

                if (slot == 5 && cg.OpenChatIsDefault)
                {
                    cg.Chat.CloseChat();
                }

                if (!noUpdate)
                {
                    cg.updateScreen();
                }

                if (cg.IsSlotBlue(slot) || cg.IsSlotRed(slot))
                {
                    bool draw = cg.debugmode;                       // For debug mode

                    List <int>        rl = new List <int>();        // Likelyhood in percent for difficulties.
                    List <Difficulty> dl = new List <Difficulty>(); // Difficulty

                    bool foundWhite      = false;
                    int  foundWhiteIndex = 0;
                    int  maxWhite        = 3;
                    // For each check length in IsAILocations
                    for (int xi = 0; xi < DifficultyLocations[slot, 2] && foundWhiteIndex < maxWhite; xi++)
                    {
                        if (foundWhite)
                        {
                            foundWhiteIndex++;
                        }

                        Color cc = cg.GetPixelAt(DifficultyLocations[slot, 0] + xi, DifficultyLocations[slot, 1]);
                        // Check for white color of text
                        if (cg.CompareColor(DifficultyLocations[slot, 0] + xi, DifficultyLocations[slot, 1], CALData.WhiteColor, 110) &&
                            (slot > 5 || cc.B - cc.R < 20))
                        {
                            foundWhite = true;

                            // For each difficulty markup
                            for (int b = 0; b < DifficultyMarkups.Length; b++)
                            {
                                Bitmap tmp = null;
                                if (draw)
                                {
                                    tmp = cg.BmpClone(0, 0, cg.bmp.Width, cg.bmp.Height);
                                }

                                // Check if bitmap matches checking area
                                double success = 0;
                                double total   = 0;
                                for (int x = 0; x < DifficultyMarkups[b].Width; x++)
                                {
                                    for (int y = DifficultyMarkups[b].Height - 1; y >= 0; y--)
                                    {
                                        // If the color pixel of the markup is not white, check if valid.
                                        Color pc = DifficultyMarkups[b].GetPixel(x, y);
                                        if (pc != Color.FromArgb(255, 255, 255, 255))
                                        {
                                            // tc is true if the pixel is black, false if it is red.
                                            bool tc = pc == Color.FromArgb(255, 0, 0, 0);

                                            total++; // Indent the total
                                                     // If the checking color in the bmp bitmap is equal to the pc color, add to success.
                                            if (cg.CompareColor(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), CALData.WhiteColor, 50) == tc)
                                            {
                                                success++;

                                                if (draw)
                                                {
                                                    if (tc)
                                                    {
                                                        tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), Color.Blue);
                                                    }
                                                    else
                                                    {
                                                        tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), Color.Lime);
                                                    }
                                                }
                                            }
                                            else if (draw)
                                            {
                                                if (tc)
                                                {
                                                    tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), Color.Red);
                                                }
                                                else
                                                {
                                                    tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - Extensions.InvertNumber(y, DifficultyMarkups[b].Height - 1), Color.Orange);
                                                }
                                            }

                                            if (draw)
                                            {
                                                tmp.SetPixel(DifficultyLocations[slot, 0] + xi + x, DifficultyLocations[slot, 1] - DifficultyMarkups[b].Height * 2 + y, DifficultyMarkups[b].GetPixel(x, y));
                                                cg.g.DrawImage(tmp, new Rectangle(0, -750, tmp.Width * 3, tmp.Height * 3));
                                                Thread.Sleep(1);
                                            }
                                        }
                                    }
                                }
                                // Get the result
                                double result = (success / total) * 100;

                                rl.Add((int)result);
                                dl.Add((Difficulty)b);

                                if (draw)
                                {
                                    tmp.SetPixel(DifficultyLocations[slot, 0] + xi, DifficultyLocations[slot, 1], Color.MediumPurple);
                                    cg.g.DrawImage(tmp, new Rectangle(0, -750, tmp.Width * 3, tmp.Height * 3));
                                    Console.WriteLine((Difficulty)b + " " + result);
                                    Thread.Sleep(1000);
                                }
                            }
                        }
                    }

                    if (slot == 5 && cg.OpenChatIsDefault)
                    {
                        cg.Chat.OpenChat();
                    }

                    // Return the difficulty that is most possible.
                    if (rl.Count > 0)
                    {
                        int max = rl.Max();
                        if (max >= 75)
                        {
                            return(dl[rl.IndexOf(max)]);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }

                else if (cg.QueueCount > 0)
                {
                    int y = DifficultyLocationsQueue[slot - Queueid];
                    for (int x = DifficultyLocationQueueX; x < 150 + DifficultyLocationQueueX; x++)
                    {
                        if (cg.CompareColor(x, y, new int[] { 180, 186, 191 }, 10))
                        {
                            return(null);
                        }
                    }
                    return(Difficulty.Easy);
                }

                else
                {
                    return(null);
                }
            }
Ejemplo n.º 11
0
        private bool EditAI(int slot, AIHero?setToHero, Difficulty?setToDifficulty)
        {
            using (cg.LockHandler.Interactive)
            {
                if (!CustomGame.IsSlotValid(slot))
                {
                    throw new InvalidSlotException(slot);
                }

                // Make sure there is a player or AI in selected slot, or if they are a valid slot to select in queue.
                if (cg.PlayerSlots.Contains(slot))
                {
                    if (cg.OpenChatIsDefault)
                    {
                        cg.Chat.CloseChat();
                    }

                    // Click the slot of the selected slot.
                    var slotlocation = cg.Interact.FindSlotLocation(slot);
                    cg.LeftClick(slotlocation.X, slotlocation.Y);
                    // Check if Edit AI window has opened by checking if the confirm button exists.
                    cg.UpdateScreen();
                    if (Capture.CompareColor(Points.EDIT_AI_CONFIRM, Colors.CONFIRM, 20))
                    {
                        var sim = new List <Keys>();
                        // Set hero if setToHero does not equal null.
                        if (setToHero != null)
                        {
                            // Open hero menu
                            sim.Add(Keys.Space);
                            // <image url="$(ProjectDir)\ImageComments\AI.cs\EditAIHero.png" scale="0.5" />
                            // Select the topmost hero option
                            for (int i = 0; i < Enum.GetNames(typeof(AIHero)).Length; i++)
                            {
                                sim.Add(Keys.Up);
                            }
                            // Select the hero in selectHero.
                            for (int i = 0; i < (int)setToHero; i++)
                            {
                                sim.Add(Keys.Down);
                            }
                            sim.Add(Keys.Space);
                        }
                        sim.Add(Keys.Down); // Select difficulty option
                                            // Set difficulty if setToDifficulty does not equal null.
                        if (setToDifficulty != null)
                        {
                            // Open difficulty menu
                            sim.Add(Keys.Space);
                            // <image url="$(ProjectDir)\ImageComments\AI.cs\EditAIDifficulty.png" scale="0.6" />
                            // Select the topmost difficulty
                            for (int i = 0; i < Enum.GetNames(typeof(Difficulty)).Length; i++)
                            {
                                sim.Add(Keys.Up);
                            }
                            // Select the difficulty in selectDifficulty.
                            for (int i = 0; i < (int)setToDifficulty; i++)
                            {
                                sim.Add(Keys.Down);
                            }
                            sim.Add(Keys.Space);
                        }
                        // Confirm the changes
                        sim.Add(Keys.Return);

                        // Send the keypresses.
                        cg.KeyPress(sim.ToArray());

                        //cg.//ResetMouse();

                        if (cg.OpenChatIsDefault)
                        {
                            cg.Chat.OpenChat();
                        }

                        return(true);
                    }
                    else
                    {
                        //cg.//ResetMouse();

                        if (cg.OpenChatIsDefault)
                        {
                            cg.Chat.OpenChat();
                        }

                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Checks if the input slot is an AI.
        /// </summary>
        /// <param name="slot">Slot to check.</param>
        /// <param name="noUpdate">Determines if the captured screen should be updated before scanning.</param>
        /// <returns>Returns true if slot is AI.</returns>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        public bool IsAI(int slot, bool noUpdate = false)
        {
            using (cg.LockHandler.Passive)
            {
                // Look for the commendation icon for the slot chosen.

                // If the slot is not valid, throw an exception.
                if (!CustomGame.IsSlotValid(slot))
                {
                    throw new InvalidSlotException(slot);
                }

                if (CustomGame.IsSlotSpectator(slot) || // Since AI cannot join spectator, return false if the slot is a spectator slot.
                    !cg.GetSlots(SlotFlags.All, true).Contains(slot))    // Return false if the slot is empty.
                {
                    return(false);
                }

                // The chat covers blue slot 5. Close the chat so the scanning will work accurately.
                if (slot == 5 && cg.OpenChatIsDefault)
                {
                    cg.Chat.CloseChat();
                }

                if (!noUpdate || (slot == 5 && cg.OpenChatIsDefault))
                {
                    cg.UpdateScreen();
                }

                int checkY       = 0; // The potential Y locations of the commendation icon
                int checkX       = 0; // Where to start scanning on the X axis for the commendation icon
                int checkXLength = 0; // How many pixels to scan on the X axis for the commendation icon

                if (CustomGame.IsSlotBlue(slot) || CustomGame.IsSlotRed(slot))
                {
                    int checkslot = slot;
                    if (CustomGame.IsSlotRed(checkslot))
                    {
                        checkslot -= 6;
                    }

                    // Find the potential Y locations of the commendation icon.
                    // 248 is the Y location of the first commendation icon of the player in the first slot of red and blue. 28 is how many pixels it is to the next commendation icon on the next slot.
                    checkY = 257 + (checkslot * Distances.LOBBY_SLOT_DISTANCE);

                    if (CustomGame.IsSlotBlue(slot))
                    {
                        checkX = 74; // The start of the blue slots on the X axis
                    }
                    else if (CustomGame.IsSlotRed(slot))
                    {
                        checkX = 399; // The start of the red slots on the X axis
                    }
                    if (cg.IsDeathmatch(true))
                    {
                        checkY += Distances.LOBBY_SLOT_DM_Y_OFFSET - 9;
                        if (CustomGame.IsSlotBlue(slot))
                        {
                            checkX += Distances.LOBBY_SLOT_DM_BLUE_X_OFFSET;
                        }
                        else if (CustomGame.IsSlotRed(slot))
                        {
                            checkX += Distances.LOBBY_SLOT_DM_RED_X_OFFSET;
                        }
                    }

                    checkXLength = 195; // The length of the slots.
                }
                else if (CustomGame.IsSlotInQueue(slot))
                {
                    int checkslot = slot - CustomGame.QueueID;

                    // 245 is the Y location of the first commendation icon of the player in the first slot in queue. 14 is how many pixels it is to the next commendation icon on the next slot.
                    checkY = 245 + (checkslot * 14); // - Distances.LOBBY_QUEUE_OFFSET;

                    checkX       = 707;              // The start of the queue slots on this X axis
                    checkXLength = 163;              // The length of the queue slots.
                }

                bool isAi = true;

                for (int x = checkX; x < checkX + checkXLength && isAi; x += 1)
                {
                    // Check for the commendation icon.
                    isAi = !Capture.CompareColor(Convert.ToInt32(x), checkY, new int[] { 75, 130, 130 }, new int[] { 115, 175, 175 });
                }

                if (slot == 5 && cg.OpenChatIsDefault)
                {
                    cg.Chat.OpenChat();
                }

                return(isAi);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets the difficulty of the AI in the input slot.
        /// </summary>
        /// <remarks>
        /// If the input slot is not an AI, returns null.
        /// If checking an AI's difficulty in the queue, it will always return easy, or null if it is a player.
        /// </remarks>
        /// <param name="slot">Slot to check</param>
        /// <param name="noUpdate"></param>
        /// <returns>Returns the if the difficulty is found. Returns null if the input slot is not an AI.</returns>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        public Difficulty?GetAIDifficulty(int slot, bool noUpdate = false)
        {
            using (cg.LockHandler.Passive)
            {
                if (!CustomGame.IsSlotValid(slot))
                {
                    throw new InvalidSlotException(slot);
                }

                if (slot == 5 && cg.OpenChatIsDefault)
                {
                    cg.Chat.CloseChat();
                }

                if (!noUpdate)
                {
                    cg.UpdateScreen();
                }

                if (CustomGame.IsSlotBlue(slot) || CustomGame.IsSlotRed(slot))
                {
                    List <int>        rl = new List <int>();        // Likelyhood in percent for difficulties.
                    List <Difficulty> dl = new List <Difficulty>(); // Difficulty

                    int checkDistance = CustomGame.IsSlotBlue(slot) ? 100 : 25;

                    bool foundWhite      = false;
                    int  foundWhiteIndex = 0;
                    int  maxWhite        = 3;
                    // For each check length in IsAILocations
                    for (int xi = Points.DIFFICULTY_LOCATIONS[slot].X; xi < Points.DIFFICULTY_LOCATIONS[slot].X + checkDistance && foundWhiteIndex < maxWhite; xi++)
                    {
                        if (foundWhite)
                        {
                            foundWhiteIndex++;
                        }

                        Color cc = Capture.GetPixel(xi, Points.DIFFICULTY_LOCATIONS[slot].Y);
                        // Check for white color of text
                        if (Capture.CompareColor(xi, Points.DIFFICULTY_LOCATIONS[slot].Y, Colors.WHITE, 110) &&
                            (slot > 5 || cc.B - cc.R < 20))
                        {
                            foundWhite = true;

                            // For each difficulty markup
                            for (int b = 0; b < Markups.DIFFICULTY_MARKUPS.Length; b++)
                            {
                                // Check if bitmap matches checking area
                                double success = 0;
                                double total   = 0;
                                for (int x = 0; x < Markups.DIFFICULTY_MARKUPS[b].Width; x++)
                                {
                                    for (int y = Markups.DIFFICULTY_MARKUPS[b].Height - 1; y >= 0; y--)
                                    {
                                        // If the color pixel of the markup is not white, check if valid.
                                        Color pc = Markups.DIFFICULTY_MARKUPS[b].GetPixel(x, y);
                                        if (pc != Color.FromArgb(255, 255, 255, 255))
                                        {
                                            // tc is true if the pixel is black, false if it is red.
                                            bool tc = pc == Color.FromArgb(255, 0, 0, 0);

                                            total++; // Indent the total
                                                     // If the checking color in the bmp bitmap is equal to the pc color, add to success.
                                            if (Capture.CompareColor(xi + x, Points.DIFFICULTY_LOCATIONS[slot].Y - Extensions.InvertNumber(y, Markups.DIFFICULTY_MARKUPS[b].Height - 1), Colors.WHITE, 50) == tc)
                                            {
                                                success++;
                                            }
                                        }
                                    }
                                }
                                // Get the result
                                double result = (success / total) * 100;

                                rl.Add((int)result);
                                dl.Add((Difficulty)b);
                            }
                        }
                    }

                    if (slot == 5 && cg.OpenChatIsDefault)
                    {
                        cg.Chat.OpenChat();
                    }

                    // Return the difficulty that is most possible.
                    if (rl.Count > 0)
                    {
                        int max = rl.Max();
                        if (max >= 75)
                        {
                            return(dl[rl.IndexOf(max)]);
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }

                else if (cg.QueueCount > 0)
                {
                    int y = Points.DIFFICULTY_QUEUE_LOCATIONS[slot - CustomGame.QueueID];
                    for (int x = Points.DIFFICULTY_QUEUE_X; x < 150 + Points.DIFFICULTY_QUEUE_X; x++)
                    {
                        if (Capture.CompareColor(x, y, new int[] { 180, 186, 191 }, 10))
                        {
                            return(null);
                        }
                    }
                    return(Difficulty.Easy);
                }

                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Checks if the input slot is an AI.
        /// </summary>
        /// <param name="slot">Slot to check.</param>
        /// <param name="noUpdate">Determines if the captured screen should be updated before scanning.</param>
        /// <returns>Returns true if slot is AI.</returns>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        public bool IsAI(int slot, bool noUpdate = false)
        {
            // Look for the commendation icon for the slot chosen.

            // If the slot is not valid, throw an exception.
            if (!CustomGame.IsSlotValid(slot))
            {
                throw new InvalidSlotException(slot);
            }

            if (CustomGame.IsSlotSpectator(slot) || // Since AI cannot join spectator, return false if the slot is a spectator slot.
                !cg.TotalPlayerSlots.Contains(slot))    // Return false if the slot is empty.
            {
                return(false);
            }

            // The chat covers blue slot 5. Close the chat so the scanning will work accurately.
            if (slot == 5)
            {
                cg.Chat.CloseChat();
            }

            if (!noUpdate)
            {
                cg.updateScreen();
            }

            int[] checkY       = new int[0]; // The potential Y locations of the commendation icon
            int   checkX       = 0;          // Where to start scanning on the X axis for the commendation icon
            int   checkXLength = 0;          // How many pixels to scan on the X axis for the commendation icon

            if (CustomGame.IsSlotBlue(slot) || CustomGame.IsSlotRed(slot))
            {
                int checkslot = slot;
                if (CustomGame.IsSlotRed(checkslot))
                {
                    checkslot -= 6;
                }

                // Find the potential Y locations of the commendation icon.
                // 248 is the Y location of the first commendation icon of the player in the first slot of red and blue. 28 is how many pixels it is to the next commendation icon on the next slot.
                int y1 = 248 + (checkslot * 28),
                    y2 = y1 + 9; // The second potential Y location is 9 pixels under the first potential spot.
                checkY = new int[] { y1, y2 };

                if (CustomGame.IsSlotBlue(slot))
                {
                    checkX = 74; // The start of the blue slots on the X axis
                }
                else if (CustomGame.IsSlotRed(slot))
                {
                    checkX = 399;   // The start of the red slots on the X axis
                }
                checkXLength = 195; // The length of the slots.
            }
            else if (CustomGame.IsSlotInQueue(slot))
            {
                int checkslot = slot - CustomGame.Queueid;

                // 245 is the Y location of the first commendation icon of the player in the first slot in queue. 14 is how many pixels it is to the next commendation icon on the next slot.
                int y = 245 + (checkslot * 14);
                checkY = new int[] { y };

                checkX       = 707; // The start of the queue slots on this X axis
                checkXLength = 163; // The length of the queue slots.
            }

            bool isAi = true;

            for (int x = checkX; x < checkX + checkXLength; x++)
            {
                for (int yi = 0; yi < checkY.Length; yi++)
                {
                    int y = checkY[yi];
                    // Check for the commendation icon.
                    if (cg.CompareColor(x, y, new int[] { 85, 140, 140 }, new int[] { 115, 175, 175 }))
                    {
                        isAi = false;
                        break;
                    }
                }
            }

            if (slot == 5 && cg.OpenChatIsDefault)
            {
                cg.Chat.OpenChat();
            }

            return(isAi);
        }