/// <summary>
 /// Swaps the team of a player.
 /// </summary>
 /// <param name="slot">Slot to swap team.</param>
 /// <returns>Returns true if swapping team is successful.</returns>
 /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
 public bool SwapTeam(int slot)
 {
     // If the player is in blue, use the swap to red option.
     if (CustomGame.IsSlotBlue(slot))
     {
         return(ClickOption(slot, Markups.SWAP_TO_RED)); // Swap blue player to red
     }
     // If the player is in red, use the swap to blue option.
     else if (CustomGame.IsSlotRed(slot))
     {
         return(ClickOption(slot, Markups.SWAP_TO_BLUE)); // Swap red player to blue
     }
     else if (CustomGame.IsSlotInQueue(slot))
     {
         QueueTeam team = cg.PlayerInfo.GetQueueTeam(slot);
         if (team == QueueTeam.Blue)
         {
             return(ClickOption(slot, Markups.SWAP_TO_RED));
         }
         else if (team == QueueTeam.Red)
         {
             return(ClickOption(slot, Markups.SWAP_TO_BLUE));
         }
     }
     return(false);
 }
Exemple #2
0
            /// <summary>
            /// Test if input slot has chosen a hero.
            /// </summary>
            /// <param name="slot">Slot to check</param>
            /// <returns>True if hero is chosen</returns>
            /// <exception cref="InvalidSlotException">Thrown if slot argument is out of range.</exception>
            public bool IsHeroChosen(int slot)
            {
                if (!(cg.IsSlotBlue(slot) || cg.IsSlotRed(slot)))
                {
                    throw new InvalidSlotException(string.Format("Slot argument '{0}' is out of range.", slot));
                }
                if (cg.PlayerSlots.Contains(slot) == false)
                {
                    return(false);
                }

                cg.updateScreen();

                if (PlayersDead(true).Contains(slot))
                {
                    return(true);
                }

                return(_HeroChosen(slot));
            }
Exemple #3
0
 bool _HeroChosen(int slot)
 {
     if (CustomGame.IsSlotBlue(slot))
     {
         return(!Capture.CompareColor(Points.HERO_LOCATIONS[slot] + 6, Points.HERO_Y + 3, Colors.HERO_CHOSEN_BLUE, Fades.HEROES_CHOSEN));
     }
     else
     {
         //return !cg.CompareColor(CALData.HeroChosenLocations[slot], CALData.HeroChosenY, CALData.HeroChosenRed, CALData.HeroChosenFade);
         return(!Capture.CompareColor(Points.HERO_LOCATIONS[slot] + 6, Points.HERO_Y + 3, Colors.HERO_CHOSEN_RED, Fades.HEROES_CHOSEN));
     }
 }
Exemple #4
0
        /// <summary>
        /// Obtains the markup of a hero icon.
        /// </summary>
        /// <param name="slot">Slot to get hero icon from.</param>
        /// <param name="saveTo">Location on the file system to save it to.</param>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        public void GetHeroMarkup(int slot, string saveTo)
        {
            if (!(CustomGame.IsSlotBlue(slot) || CustomGame.IsSlotRed(slot)))
            {
                throw new InvalidSlotException(slot);
            }

            cg.updateScreen();

            Bitmap save = cg.BmpClone(HeroCheckLocations[slot], HeroCheckY, 20, 9);

            save.Save(saveTo);
        }
Exemple #5
0
 /// <summary>
 /// Checks if the input slot has their ultimate.
 /// </summary>
 /// <param name="slot">Slot to check.</param>
 /// <param name="noUpdate"></param>
 /// <returns>Returns true if player as ultimate.</returns>
 /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
 public bool IsUltimateReady(int slot, bool noUpdate = false)
 {
     using (cg.LockHandler.Passive)
     {
         if (!(CustomGame.IsSlotBlue(slot) || CustomGame.IsSlotRed(slot)))
         {
             throw new InvalidSlotException(slot);
         }
         if (!noUpdate)
         {
             cg.UpdateScreen();
         }
         return(Capture.CompareColor(Points.ULTIMATE_LOCATIONS[slot], new int[] { 134, 134, 134 }, 5));
     }
 }
Exemple #6
0
        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.
        }
Exemple #7
0
        /// <summary>
        /// Test if input slot has chosen a hero.
        /// </summary>
        /// <param name="slot">Slot to check</param>
        /// <returns>Returns true if a hero is chosen.</returns>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        public bool IsHeroChosen(int slot)
        {
            if (!(CustomGame.IsSlotBlue(slot) || CustomGame.IsSlotRed(slot)))
            {
                throw new InvalidSlotException(slot);
            }
            if (cg.PlayerSlots.Contains(slot) == false)
            {
                return(false);
            }

            cg.updateScreen();

            if (PlayersDead(true).Contains(slot))
            {
                return(true);
            }

            return(_HeroChosen(slot));
        }
Exemple #8
0
        /// <summary>
        /// Test if input slot has chosen a hero.
        /// </summary>
        /// <param name="slot">Slot to check</param>
        /// <returns>Returns true if a hero is chosen.</returns>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        public bool IsHeroChosen(int slot)
        {
            using (cg.LockHandler.Passive)
            {
                if (!(CustomGame.IsSlotBlue(slot) || CustomGame.IsSlotRed(slot)))
                {
                    throw new InvalidSlotException(slot);
                }
                if (cg.PlayerSlots.Contains(slot) == false)
                {
                    return(false);
                }

                cg.UpdateScreen();

                if (GetDeadSlots(true).Contains(slot))
                {
                    return(true);
                }

                return(_HeroChosen(slot));
            }
        }
Exemple #9
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);
                }
            }
        /// <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);
            }
        }
        /// <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);
                }
            }
        }
Exemple #12
0
        /// <summary>
        /// Gets the hero a player is playing.
        /// </summary>
        /// <param name="slot">Slot to check.</param>
        /// <param name="resultInfo">Info about the returned value.</param>
        /// <returns>Returns the hero the slot is playing.</returns>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        public Hero?GetHero(int slot, out HeroResultInfo resultInfo)
        {
            if (!(CustomGame.IsSlotBlue(slot) || CustomGame.IsSlotRed(slot)))
            {
                throw new InvalidSlotException(string.Format("Slot {0} is out of range. Slot must be a player on blue or red team.", slot));
            }

            if (!cg.PlayerSlots.Contains(slot))
            {
                resultInfo = HeroResultInfo.SlotEmpty;
                return(null);
            }

            if (PlayersDead(true).Contains(slot))
            {
                resultInfo = HeroResultInfo.PlayerWasDead;
                return(null);
            }

            if (!_HeroChosen(slot))
            {
                resultInfo = HeroResultInfo.NoHeroChosen;
                return(null);
            }

            List <Tuple <Hero, double> > results = new List <Tuple <Hero, double> >();

            for (int m = 0; m < HeroMarkups.Length; m++)
            {
                if (HeroMarkups[m] != null)
                {
                    double total   = 0;
                    double success = 0;

                    for (int x = 0; x < HeroMarkups[m].Width; x++)
                    {
                        for (int y = 0; y < HeroMarkups[m].Height; y++)
                        {
                            int bmpX = HeroCheckLocations[slot] + x;
                            int bmpY = HeroCheckY + y;

                            int[] markupColor = HeroMarkups[m].GetPixelAt(x, y).ToInt();

                            if (markupColor[0] != 0 && markupColor[1] != 0 && markupColor[2] != 0)
                            {
                                total++;
                                if (cg.CompareColor(bmpX, bmpY, markupColor, 20))
                                {
                                    success++;
                                }
                            }
                        }
                    }

                    double probability = (success / total) * 100;

                    if (probability >= 80)
                    {
                        results.Add(new Tuple <Hero, double>((Hero)m, probability));
                    }
                }
            }

            if (results.Count == 0)
            {
                resultInfo = HeroResultInfo.NoCompatibleHeroFound;
                return(null);
            }
            else
            {
                int    highestIndex = -1;
                double highest      = 0;

                for (int i = 0; i < results.Count; i++)
                {
                    if (results[i].Item2 > highest)
                    {
                        highestIndex = i;
                        highest      = results[i].Item2;
                    }
                }

                resultInfo = HeroResultInfo.Success;
                return(results[highestIndex].Item1);
            }
        }
Exemple #13
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);
        }