Example #1
0
        public void UpgradeSkill(Upgrade upgrade)
        {
            UpgradeViewModel upgradeViewModel;
            int unlockedLevel;

            switch (upgrade)
            {
            case Upgrade.ManaAmount:
                upgradeViewModel = manaAmount;
                unlockedLevel    = CloudVariables.UnlockedManaAmountLevel;
                break;

            case Upgrade.VerticalSpeed:
                upgradeViewModel = verticalSpeed;
                unlockedLevel    = CloudVariables.UnlockedVerticalSpeedLevel;
                break;

            case Upgrade.BoostSpeed:
                upgradeViewModel = boostSpeed;
                unlockedLevel    = CloudVariables.UnlockedBoostSpeedLevel;
                break;

            case Upgrade.ManaRegenRate:
                upgradeViewModel = manaRegen;
                unlockedLevel    = CloudVariables.UnlockedManaRegenLevel;
                break;

            default:
                throw new ArgumentOutOfRangeException("upgrade", upgrade, null);
            }

            if (upgradeViewModel.CurrentLevel == UpgradeInfo.MaxUpgradeLevel)
            {
                AudioClipPlayer.PlayIncorrect();
                return;
            }

            if (upgradeViewModel.CurrentLevel < unlockedLevel)
            {
                upgradeViewModel.SetCurrentLevel(upgradeViewModel.CurrentLevel + 1);
                AudioClipPlayer.Instance.PlayClick();
                UpdateGUI(upgrade);
                return;
            }

            var price = UpgradeInfo.GetUpgradePrice(unlockedLevel + 1);

            if (Player.State.Coins < price)
            {
                AudioClipPlayer.PlayIncorrect();
                return;
            }

            Player.State.Coins -= price;
            upgradeViewModel.SetCurrentLevel(upgradeViewModel.CurrentLevel + 1);
            switch (upgrade)
            {
            case Upgrade.ManaAmount:
                CloudVariables.UnlockedManaAmountLevel++;
                break;

            case Upgrade.VerticalSpeed:
                CloudVariables.UnlockedVerticalSpeedLevel++;
                break;

            case Upgrade.BoostSpeed:
                CloudVariables.UnlockedBoostSpeedLevel++;
                break;

            case Upgrade.ManaRegenRate:
                CloudVariables.UnlockedManaRegenLevel++;
                break;

            default:
                throw new ArgumentOutOfRangeException("upgrade", upgrade, null);
            }

            Cloud.Storage.Save();
            AudioClipPlayer.PlayUpgrade();
            UpdateGUI(upgrade);
        }