コード例 #1
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));
        }
コード例 #2
0
        private void BuyFreeGenerators(UpgradeData vm, int id)
        {
            ITransportUnitsService transportService = GameServices.Instance.TransportService;

            if (transportService.HasUnits(id))
            {
                transportService.AddLiveUnits(id, (int)vm.Value);
                GlobalRefs.LevelManager.AddXP(XPSources.BuyUpgrade);
            }
            else
            {
                transportService.AddLiveUnits(id, (int)vm.Value);
                GlobalRefs.LevelManager.AddXP(XPSources.BuyGenerator * 10);
            }


            //PlayerData.Investors -= vm.Price;
            GameServices.Instance.PlayerService.RemoveSecurities(vm.Price(() => {
                return(BosUtils.GetUpgradePriceMult(ResourceService.Planets.GetPlanet(Planets.CurrentPlanet.Id), vm));
            }));
            GlobalRefs.LevelManager.AddXP(XPSources.BuyUpgrade);
        }