Example #1
0
        public void Setup(object data = null)
        {
            StartCoroutine(FirstUpdatePlanetGeneratorStatesImpl());
            planetGeneratorStatesTimer.Setup(0.5f, (delta) => {
                if (IsLoaded && Services.GameModeService.IsGame)
                {
                    UpdatePlanetStateGenerators();
                }
            });

            if (false == IsInitialized)
            {
                Observable.Interval(TimeSpan.FromSeconds(2)).Subscribe(val => {
                    if (IsLoaded && IsResumed && GameMode.GameModeName == GameModeName.Game)
                    {
                        Generators.ClearExpiredBoosts(TimeService.UnixTimeInt);
                        //UDebug.Log($"clear expired boosts : {val}");
                    }
                }).AddTo(gameObject);
                IsInitialized = true;
            }
        }
Example #2
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;
        }