예제 #1
0
        public void Update(float deltaTime, IGenerationGlobalContext context)
        {
            double time         = TimeOfRound(context);
            double profit       = ProfitPerRound(context);
            double profitPerSec = profit / time;

            ProfitResult.UpdateFromOther(new ProfitResult(profit, profitPerSec, time));

            if (IsAutomatic)
            {
                if (!IsGenerationStarted)
                {
                    SetGenerationStarted(true);
                }
            }
            if (IsGenerationStarted)
            {
                AddGenerateTimer(deltaTime);
                double interval = AccumulateInterval;
                GameEvents.OnAccumulationProgressChanged(this, GenerateTimer, interval, ProfitResult);

                accumulatedCash += ProfitResult.ValuePerSecond * deltaTime;
                if (GenerateTimer >= interval)
                {
                    GameEvents.OnAccumulationCompleted(this, ProfitResult);
                    SetGenerateTimer(0f);
                    GameEvents.OnAccumulationProgressChanged(this, GenerateTimer, interval, ProfitResult);
                    accumulatedCash = 0.0;
                    if (IsManual)
                    {
                        SetGenerationStarted(false);
                    }
                }
            }
        }
예제 #2
0
 public static void OnAccumulationProgressChanged(GeneratorInfo generator, double timer, double interval, ProfitResult profit)
 {
     AccumulationProgressChanged?.Invoke(generator, timer, interval, profit);
 }
예제 #3
0
 public static void OnAccumulationCompleted(GeneratorInfo generator, ProfitResult profit)
 {
     AccumulationCompleted?.Invoke(generator, profit);
 }
예제 #4
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;
        }