Пример #1
0
        /// <summary>
        /// Tries to level a given hero to a desired level, if there is enough money.
        /// </summary>
        /// <param name="heroIndex">The hero to level</param>
        /// <param name="desiredLevel">The level desired</param>
        /// <param name="currentMoney">The current amount of money</param>
        /// <returns>True if and only if the hero is currently already at that level</returns>
        public static bool TryLevelHero(ParsedHeroes ph, int heroIndex, int desiredLevel, double currentMoney, bool wait)
        {
            if (ph.FirstHeroIndex > heroIndex)
            {
                AddAction(new Action(GameEngine.GetScrollbarUpPoint(), 0), 3);
                return(false);
            }
            else if (ph.LastHeroIndex < heroIndex)
            {
                AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3);
                return(false);
            }

            int       adjustedIndex = heroIndex - ph.FirstHeroIndex;
            HeroStats hs            = ph.HeroStats[adjustedIndex];

            if (hs.Level == -1)
            {
                AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3);
                return(false);
            }

            int heroLevel = hs.Level;

            if (heroLevel >= desiredLevel)
            {
                return(true);
            }

            if (wait && hs.Hero.GetCostToLevel(desiredLevel, heroLevel) > currentMoney)
            {
                return(false);
            }

            Point pt;

            if (hs.GetBuyButton(out pt))
            {
                while (hs.Hero.GetCostToLevel(heroLevel + 1, heroLevel) < currentMoney && desiredLevel > heroLevel)
                {
                    if (desiredLevel - heroLevel >= 100 && hs.Hero.GetCostToLevel(heroLevel + 100, heroLevel) < currentMoney)
                    {
                        AddAction(new Action(pt, Modifiers.CTRL));
                        currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 100, heroLevel);
                        heroLevel    += 100;
                    }
                    else if (desiredLevel - heroLevel >= 25 && hs.Hero.GetCostToLevel(heroLevel + 25, heroLevel) < currentMoney)
                    {
                        AddAction(new Action(pt, Modifiers.Z));
                        currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 25, heroLevel);
                        heroLevel    += 25;
                    }
                    else if (desiredLevel - heroLevel >= 10 && hs.Hero.GetCostToLevel(heroLevel + 10, heroLevel) < currentMoney)
                    {
                        AddAction(new Action(pt, Modifiers.SHIFT));
                        currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 10, heroLevel);
                        heroLevel    += 10;
                    }
                    else
                    {
                        AddAction(new Action(pt, 0));
                        currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 1, heroLevel);
                        heroLevel++;
                    }
                }

                return(false);
            }
            else
            {
                AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3);
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Tries to level a given hero to a desired level, if there is enough money.
        /// </summary>
        /// <param name="heroIndex">The hero to level</param>
        /// <param name="desiredLevel">The level desired</param>
        /// <param name="currentMoney">The current amount of money</param>
        /// <returns>True if and only if the hero is currently already at that level</returns>
        public static bool TryLevelHero(ParsedHeroes ph, int heroIndex, int desiredLevel, double currentMoney, bool wait)
        {
            if (GameEngine.GetCachedLevel(heroIndex) >= desiredLevel)
            {
                return(true);
            }

            if (ph.FirstHeroIndex > heroIndex)
            {
                AddAction(new Action(GameEngine.GetScrollbarUpPoint(), 0), 3);
                return(false);
            }
            else if (ph.LastHeroIndex < heroIndex)
            {
                AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3);
                return(false);
            }

            // Check for stepping out of bounds (happens when part of the view is blocked while attempting to do certain actions)
            int adjustedIndex = heroIndex - ph.FirstHeroIndex;

            if (adjustedIndex >= ph.HeroStats.Count)
            {
                return(false);
            }
            HeroStats hs = ph.HeroStats[adjustedIndex];

            if (hs.Level == -1)
            {
                AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3);
                return(false);
            }

            int heroLevel = hs.Level;

            if (heroLevel >= desiredLevel)
            {
                return(true);
            }

            if (wait && hs.Hero.GetCostToLevel(desiredLevel, heroLevel) > currentMoney)
            {
                return(false);
            }

            Point pt;

            if (hs.GetBuyButton(out pt))
            {
                while (hs.Hero.GetCostToLevel(heroLevel + 1, heroLevel) < currentMoney && desiredLevel > heroLevel)
                {
                    if (desiredLevel - heroLevel >= 100 && hs.Hero.GetCostToLevel(heroLevel + 100, heroLevel) < currentMoney)
                    {
                        AddAction(new Action(pt, Modifiers.CTRL));
                        currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 100, heroLevel);
                        heroLevel    += 100;
                    }
                    else if (desiredLevel - heroLevel >= 25 && hs.Hero.GetCostToLevel(heroLevel + 25, heroLevel) < currentMoney)
                    {
                        AddAction(new Action(pt, Modifiers.Z));
                        currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 25, heroLevel);
                        heroLevel    += 25;
                    }
                    else if (desiredLevel - heroLevel >= 10 && hs.Hero.GetCostToLevel(heroLevel + 10, heroLevel) < currentMoney)
                    {
                        AddAction(new Action(pt, Modifiers.SHIFT));
                        currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 10, heroLevel);
                        heroLevel    += 10;
                    }
                    else
                    {
                        AddAction(new Action(pt, 0));
                        currentMoney -= hs.Hero.GetCostToLevel(heroLevel + 1, heroLevel);
                        heroLevel++;
                    }
                }

                return(false);
            }
            else
            {
                AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3);
                return(false);
            }
        }