Esempio n. 1
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);
                }
            }
        }
Esempio n. 2
0
            /// <summary>
            /// Gets the hero a player is playing.
            /// </summary>
            /// <param name="slot">Slot to check.</param>
            /// <param name="resultInfo">Why the method returned what it did.</param>
            /// <returns>Returns the hero the slot is playing.</returns>
            public Hero?GetHero(int slot, out HeroResultInfo resultInfo)
            {
                if (!(cg.IsSlotBlue(slot) || cg.IsSlotRed(slot)))
                {
                    throw new InvalidSlotException("Slot is out of range. Slot must be a player on blue or red team.");
                }

                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);
                }
            }
            /// <summary>
            /// Gets the hero a player is playing.
            /// </summary>
            /// <param name="slot">Slot to check.</param>
            /// <returns>Returns the hero the slot is playing.</returns>
            public Hero?GetHero(int slot)
            {
                HeroResultInfo _ = new HeroResultInfo();

                return(GetHero(slot, out _));
            }