Example #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));
        }
Example #2
0
        private void UpdatePlanetStateGenerators()
        {
            var generatorCollection              = Services.ResourceService.Generators.Generators.Values;
            ITransportUnitsService unitService   = Services.TransportService;
            IPlayerService         playerService = Services.PlayerService;

            foreach (GeneratorData data in generatorCollection)
            {
                if (data.Type == GeneratorType.Planet || data.Type == GeneratorType.Normal)
                {
                    GeneratorInfo info = Generators.GetGeneratorInfo(data.Id);
                    if (!info.IsResearched)
                    {
                        Generators.SetState(info.GeneratorId, GeneratorState.Researchable);
                    }
                    else
                    {
                        bool hasAnyUnits            = unitService.HasUnits(info.GeneratorId);
                        bool playerHasCashForUnlock = playerService.IsEnoughCompanyCash(info.Cost);
                        bool noAnyUnits             = !hasAnyUnits;
                        if (noAnyUnits && playerHasCashForUnlock)
                        {
                            if (info.IsDependent)
                            {
                                GeneratorInfo dependentInfo = Generators.GetGeneratorInfo(info.RequiredGeneratorId);
                                if (dependentInfo.State == GeneratorState.Active)
                                {
                                    Generators.SetState(info.GeneratorId, GeneratorState.Unlockable);
                                }
                                else
                                {
                                    Generators.SetState(info.GeneratorId, GeneratorState.Locked);
                                }
                            }
                            else
                            {
                                Generators.SetState(info.GeneratorId, GeneratorState.Unlockable);
                            }
                        }
                        else if (noAnyUnits && !playerHasCashForUnlock)
                        {
                            Generators.SetState(info.GeneratorId, GeneratorState.Locked);
                        }
                        else if (hasAnyUnits)
                        {
                            Generators.SetState(info.GeneratorId, GeneratorState.Active);
                        }
                    }
                }
            }
        }
Example #3
0
        public double GetSecuritiesCountFromInvestors()
        {
            ITransportUnitsService unitService = Services.TransportService;
            double lifetimeEarnings            = Services.PlayerService.LifetimeEarningsInPlanet;
            double million = Math.Pow(10, 6);

            if (lifetimeEarnings < million)
            {
                return(0.0);
            }
            if (false == unitService.HasUnits(2))
            {
                return(0);
            }
            double koef = 150.0 * Math.Sqrt(lifetimeEarnings / million);
            double lifetimeSecurities = Services.PlayerService.LifeTimeSecurities.Value;
            var    result             = koef - lifetimeSecurities;

            return(result > 0 ? result : 0);
        }
Example #4
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);
        }
Example #5
0
    private void Reload(double balance)
    {
        NameView.text = _upgrade.Names.Length > UpgradeLevel ? _upgrade.Names[UpgradeLevel] : _upgrade.OverflowName;
        var cost             = _upgrade.CalculateCost(UpgradeLevel);
        var enabledCondition = false;

        ITransportUnitsService transportService = GameServices.Instance.TransportService;

        switch (_upgrade.CostType)
        {
        case CostType.Balance:
            if (_upgrade.GeneratorIdToUpgrade != -1)
            {
                enabledCondition = balance >= cost && transportService.HasUnits(_upgrade.GeneratorIdToUpgrade);
            }
            else
            {
                enabledCondition = balance >= cost;
            }

            PriceView.text = GameServices.Instance.Currency.CreatePriceString(cost, separateWithEndl: false, separator: " ", useDecimalFormat: true);
            break;

        case CostType.Investors:
            if (_upgrade.GeneratorIdToUpgrade != -1)
            {
                enabledCondition = GameServices.Instance.PlayerService.Securities.Value >= cost && transportService.HasUnits(_upgrade.GeneratorIdToUpgrade);
            }
            else
            {
                enabledCondition = GameServices.Instance.PlayerService.Securities.Value >= cost;
            }
            PriceView.text = string.Format("{0} investor(s)", cost);
            break;

        case CostType.Coins: {
            var playerService = GameServices.Instance.PlayerService;
            if (_upgrade.GeneratorIdToUpgrade != -1)
            {
                enabledCondition = playerService.Coins >= cost && transportService.HasUnits(_upgrade.GeneratorIdToUpgrade);
            }
            else
            {
                enabledCondition = playerService.Coins >= cost;
            }
            PriceView.text = string.Format("{0} coin(s)", cost);
        }
        break;
        }

        RealtimeCost = cost;

        if (enabledCondition)
        {
            BuyButton.interactable = true;
            PriceView.color        = Color.white;
            UpgradeTextView.color  = Color.white;
            CanBuy = true;
        }
        else
        {
            BuyButton.interactable = false;
            PriceView.color        = DisabledTextColor;
            UpgradeTextView.color  = DisabledTextColor;
            CanBuy = false;
        }
    }
Example #6
0
        private System.Collections.IEnumerator UpdateOnResumeImpl()
        {
            Services.GetService <IConsoleService>()?.AddOnScreenText("UpdateOnResumeImpl() generation service...");

            yield return(new WaitUntil(() => IsLoaded && Services.ResourceService.IsLoaded));

            yield return(new WaitUntil(() => Services.TransportService.IsLoaded && Services.PlayerService.IsLoaded && Services.TimeChangeService.IsLoaded));

            yield return(new WaitUntil(() => Services.InvestorService.IsLoaded));

            yield return(new WaitUntil(() => Services.GetService <ISleepService>().IsRunning));

            yield return(new WaitUntil(() => Player.LegacyPlayerData != null));

            ITransportUnitsService unitService     = Services.TransportService;
            IInvestorService       investorService = Services.InvestorService;
            ISleepService          sleepService    = Services.GetService <ISleepService>();
            IPlayerService         playerService   = Services.PlayerService;


            int interval = sleepService.SleepInterval;

            TotalOfflineBalance = 0.0;

            //clear expired timed boosts
            Generators.ClearExpiredBoosts(TimeService.UnixTimeInt);

            foreach (GeneratorInfo generator in Generators.PlanetGenerators)
            {
                if (generator.State == GeneratorState.Active)
                {
                    ProfitResult profitResult = generator.ConstructProfitResult(Generators);

                    if (generator.IsAutomatic)
                    {
                        TotalOfflineBalance += generator.UpdateAutomaticAfterSleep(interval, Generators);
                    }
                    else if (generator.IsManual && generator.IsGenerationStarted)
                    {
                        generator.AddGenerateTimer(interval);
                        if (generator.GenerateTimer >= profitResult.GenerationInterval)
                        {
                            generator.SetGenerateTimer(0);
                            generator.SetGenerationStarted(false);
                            playerService.AddGenerationCompanyCash(profitResult.ValuePerRound);
                            // UDebug.Log($"added to planet manual generator => {generator.GeneratorId} after sleep => {interval} seconds, value => {profitResult.ValuePerRound}".Colored(ConsoleTextColor.orange).Bold());
                            TotalOfflineBalance += profitResult.ValuePerRound;
                        }
                    }
                }
            }

            foreach (GeneratorInfo generator in Generators.NormalGenerators)
            {
                if (generator.State == GeneratorState.Active)
                {
                    ProfitResult profitResult = generator.ConstructProfitResult(Generators);

                    if (generator.IsAutomatic)
                    {
                        TotalOfflineBalance += generator.UpdateAutomaticAfterSleep(interval, Generators);
                        //UDebug.Log($"added to normal automatic generator => {generator.GeneratorId} after sleep => {interval} seconds, value => {value}".Colored(ConsoleTextColor.orange).Bold());
                    }
                    else if (generator.IsManual && generator.IsGenerationStarted)
                    {
                        UDebug.Log($"manul gen =>{generator.GeneratorId} sleep update".Colored(ConsoleTextColor.green).Bold());
                        generator.AddGenerateTimer(interval);
                        if (generator.GenerateTimer >= profitResult.GenerationInterval)
                        {
                            generator.SetGenerateTimer(0);
                            generator.SetGenerationStarted(false);
                            generator.SetAccumulatedCash(0);
                            playerService.AddGenerationCompanyCash(profitResult.ValuePerRound);
                            TotalOfflineBalance += profitResult.ValuePerRound;
                            generator.FireProgressEvent();
                            UDebug.Log($"added to normal manual generator => {generator.GeneratorId} after sleep => {interval} seconds, value => {profitResult.ValuePerRound}".Colored(ConsoleTextColor.orange).Bold());
                        }
                        //
                        //generator.Update(interval, Generators);
                    }
                }
            }
            //Services?.GetService<IConsoleService>()?.AddOnScreenText($"Added to company cash => {TotalOfflineBalance}");
            IsResumed = true;
        }