예제 #1
0
        private void BuyUpgradeViewModel_Cash(UpgradeData data, bool free)
        {
            IPlayerService playerService = GameServices.Instance.PlayerService;

            var id = data.GeneratorId;

            switch (data.UpgradeType)
            {
            case UpgradeType.Profit:
                BuyProfitUpgradeVM(data, free, id, false);
                break;

            case UpgradeType.Time:
                BuyTimeUpgradeVM(data, free, id, false);
                break;

            default:
                break;
            }

            if (!free)
            {
                playerService.CheckNonNegativeCompanyCash();
            }
            GlobalRefs.LevelManager.AddXP(XPSources.BuyUpgrade);
        }
예제 #2
0
        public int BuyGenerator(GeneratorInfo generator, int count, bool isFree = false)
        {
            ITransportUnitsService unitService   = Services.TransportService;
            IPlayerService         playerService = Services.PlayerService;

            if (unitService.HasUnits(generator.GeneratorId))
            {
                if (!isFree)
                {
                    double price = CalculatePrice(count, unitService.GetUnitTotalCount(generator.GeneratorId), generator);
                    if (playerService.IsEnoughCompanyCash(price))
                    {
                        playerService.RemoveCompanyCash(price);
                    }
                    else
                    {
                        return(0);
                    }
                }
                unitService.AddLiveUnits(generator.GeneratorId, count);
                AddBuyedGeneratorCount(generator, count);
                GlobalRefs.LevelManager.AddXP(XPSources.BuyGenerator * count);
            }
            else
            {
                if (!isFree)
                {
                    double price = CalculatePrice(count, 0, generator);
                    if (playerService.IsEnoughCompanyCash(price))
                    {
                        playerService.RemoveCompanyCash(price);
                    }
                    else
                    {
                        return(0);
                    }
                }
                unitService.AddLiveUnits(generator.GeneratorId, count);
                AddBuyedGeneratorCount(generator, 1);
                if (!Convert.ToBoolean(PlayerPrefs.GetInt("UnlockGenerator_" + generator.GeneratorId, 0)))
                {
                    FacebookEventUtils.LogApplyGeneratorEvent(generator.GeneratorId.ToString());
                    PlayerPrefs.SetInt("UnlockGenerator_" + generator.GeneratorId, 1);
                }
                GlobalRefs.LevelManager.AddXP(XPSources.UnlockGenerator * count);
            }
            playerService.CheckNonNegativeCompanyCash();
            StatsCollector.Instance[Stats.UNITS_BOUGHT] += count;
            Player.LegacyPlayerData.Save();
            StatsCollector.Instance.Save();
            return(unitService.GetUnitTotalCount(generator.GeneratorId));
        }