示例#1
0
        public void Tick(PlayerResources pr)
        {
            if (!Started)
            {
                var time = Queue.GetBuildTime(ai, bi);
                if (time > 0)
                {
                    RemainingTime = TotalTime = time;
                }

                Started = true;
            }

            if (Done)
            {
                if (OnComplete != null)
                {
                    OnComplete();
                }

                return;
            }

            if (Paused)
            {
                return;
            }

            if (pm != null && pm.PowerState != PowerState.Normal)
            {
                Slowdown -= 100;
                if (Slowdown < 0)
                {
                    Slowdown = Queue.Info.LowPowerModifier + Slowdown;
                }
                else
                {
                    return;
                }
            }

            var expectedRemainingCost = RemainingTime == 1 ? 0 : TotalCost * RemainingTime / Math.Max(1, TotalTime);
            var costThisFrame         = RemainingCost - expectedRemainingCost;

            if (costThisFrame != 0 && !pr.TakeCash(costThisFrame, true))
            {
                return;
            }

            RemainingCost -= costThisFrame;
            RemainingTime -= 1;
            if (RemainingTime > 0)
            {
                return;
            }

            Done = true;
        }
示例#2
0
        public void Tick(PlayerResources pr)
        {
            if (!Started)
            {
                var time = Queue.GetBuildTime(ai, bi);
                if (time > 0)
                {
                    RemainingTime = TotalTime = time;
                }

                Started = true;
            }

            if (Done)
            {
                if (OnComplete != null)
                {
                    OnComplete();
                }

                return;
            }

            if (Paused)
            {
                return;
            }

            if (pm.PowerState != PowerState.Normal)
            {
                if (--Slowdown <= 0)
                {
                    Slowdown = Queue.Info.LowPowerSlowdown;
                }
                else
                {
                    return;
                }
            }

            var costThisFrame = RemainingCost / RemainingTime;

            if (costThisFrame != 0 && !pr.TakeCash(costThisFrame, true))
            {
                return;
            }

            RemainingCost -= costThisFrame;
            RemainingTime -= 1;
            if (RemainingTime > 0)
            {
                return;
            }

            Done = true;
        }
示例#3
0
        void ModifyCash(Actor self, Player newOwner, int amount)
        {
            if (amount < 0)
            {
                // Check whether the amount of cash to be removed would exceed available player cash, in that case only remove all the player cash
                var drain = Math.Min(resources.Cash + resources.Resources, -amount);
                resources.TakeCash(drain);

                if (info.ShowTicks)
                {
                    AddCashTick(self, -drain);
                }
            }
            else
            {
                resources.GiveCash(amount);
                if (info.ShowTicks)
                {
                    AddCashTick(self, amount);
                }
            }
        }