Exemple #1
0
        /// <summary>
        /// Obtains the markup of a hero icon.
        /// </summary>
        /// <param name="slot">Slot to get hero icon from.</param>
        /// <include file='docs.xml' path='doc/exceptions/invalidslot/exception'/>
        public Bitmap GetHeroMarkup(int slot)
        {
            using (cg.LockHandler.Passive)
            {
                if (!CustomGame.IsSlotBlueOrRed(slot))
                {
                    throw new InvalidSlotException(slot);
                }

                cg.UpdateScreen();

                return(cg.Capture.CloneAsBitmap(Points.HERO_LOCATIONS[slot], Points.HERO_Y, 20, 9));
            }
        }
Exemple #2
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)
        {
            using (cg.LockHandler.Passive)
            {
                if (!CustomGame.IsSlotBlueOrRed(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 (GetDeadSlots(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 < Markups.HERO_MARKUPS.Length; m++)
                {
                    if (Markups.HERO_MARKUPS[m] != null)
                    {
                        double total   = 0;
                        double success = 0;

                        for (int x = 0; x < Markups.HERO_MARKUPS[m].Width; x++)
                        {
                            for (int y = 0; y < Markups.HERO_MARKUPS[m].Height; y++)
                            {
                                int bmpX = Points.HERO_LOCATIONS[slot] + x;
                                int bmpY = Points.HERO_Y + y;

                                int[] markupColor = Markups.HERO_MARKUPS[m].GetPixel(x, y).ToInt();

                                if (markupColor[0] != 0 && markupColor[1] != 0 && markupColor[2] != 0)
                                {
                                    total++;
                                    if (Capture.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);
                }
            }
        }