Esempio n. 1
0
        /// <summary>
        /// Tries to buy a given hero upgrade, if there is enough money.
        /// </summary>
        /// <param name="heroIndex"></param>
        /// <param name="desiredUpgrade"></param>
        /// <param name="currentMoney"></param>
        /// <returns></returns>
        public static bool TryUpgradeHero(ParsedHeroes ph, int heroIndex, int desiredUpgrade, double currentMoney)
        {
            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];
            int       upgradeStatus = hs.HasUpgrade(desiredUpgrade);

            if (upgradeStatus == 1)
            {
                return(true);
            }
            else if (upgradeStatus == -1)
            {
                AddAction(new Action(GameEngine.GetScrollbarDownPoint(), 0), 3);
                return(false);
            }
            else
            {
                Point upgradeButton;
                if (hs.Hero.Upgrades[desiredUpgrade].Cost < currentMoney && hs.GetUpgradeButton(out upgradeButton, desiredUpgrade))
                {
                    AddAction(new Action(upgradeButton, 0));
                    return(false);
                }
            }

            return(false);
        }