コード例 #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 double ProfitPerRound(IGenerationGlobalContext context, bool printDetails = false)
        {
            double realTime = RealTime(context);
            double result   = GeneratorUtils.CalculateProfitPerRound(this, context.GetUnitCount(GeneratorId), ProfitBoosts.Value * context.ProfitBoostValue) * TimeToProfit(realTime);

            if (printDetails)
            {
                //return generator.Data.BaseGeneration * count * profitBoost * Math.Pow(generator.Data.ProfitIncrementFactor, count);
                GeneratorInfoCollection collection = context as GeneratorInfoCollection;
                if (collection != null)
                {
                    Dictionary <string, double> profitFormulaComponents = new Dictionary <string, double>()
                    {
                        ["BASE GEN"]             = Data.BaseGeneration,
                        ["UNIT COUNT"]           = context.GetUnitCount(GeneratorId),
                        ["LOCAL BOOSTS"]         = ProfitBoosts.Value,
                        ["GLOBAL BOOST"]         = context.ProfitBoostValue,
                        ["LOCBOOST * GLOBBOOST"] = ProfitBoosts.Value * context.ProfitBoostValue,
                        ["PROFIT INCR FACTOR"]   = Data.ProfitIncrementFactor,
                    };

                    System.Text.StringBuilder sb = new System.Text.StringBuilder();
                    sb.AppendLine(collection.ProfitBoostComponents.AsString(k => k, v => v.ToString("F2")));
                    sb.AppendLine("**********************");
                    sb.AppendLine(profitFormulaComponents.AsString(k => k, v => v.ToString("F2")));
                    Services.GetService <IConsoleService>().AddOutput(sb.ToString(), ConsoleTextColor.yellow, true);
                }
            }
            return(result);
        }
コード例 #3
0
        public ProfitResult ConstructProfitResult(IGenerationGlobalContext context)
        {
            double profitPerRound = ProfitPerRound(context);
            double timeOfRound    = TimeOfRound(context);

            return(new ProfitResult(profitPerRound, profitPerRound / timeOfRound, timeOfRound));
        }
コード例 #4
0
        public double TimeOfRound(IGenerationGlobalContext context)
        {
            double value = RealTime(context);

            if (IsTimeToProfitEnabled(value))
            {
                return(0.8);
            }
            return(value);
        }
コード例 #5
0
        public double UpdateAutomaticAfterSleep(float sleepTime, IGenerationGlobalContext context)
        {
            if (IsAutomatic)
            {
                if (!IsGenerationStarted)
                {
                    SetGenerationStarted(true);
                }
            }
            double loopInterval = TimeOfRound(context);
            double profit       = ProfitPerRound(context);
            double profitPerSec = profit / loopInterval;
            int    loopsCount   = (int)(sleepTime / loopInterval);
            double val          = loopsCount * profit;

            Services.PlayerService.AddGenerationCompanyCash(val);
            Update((float)(sleepTime - loopsCount * loopInterval), context);
            // UnityEngine.Debug.Log($"gen: {GeneratorId}, accumulated cash: {accumulatedCash}");
            return(val);
        }
コード例 #6
0
 private double RealTime(IGenerationGlobalContext context)
 => GeneratorUtils.CalculateTime(this, TimeBoosts.Value * context.TimeBoostValue);
コード例 #7
0
 public double ProfitPerSec(IGenerationGlobalContext context)
 => ProfitPerRound(context) / TimeOfRound(context);