示例#1
0
        /// <summary>
        /// Begins the clearing of the <see cref="Obstacle"/> if <see cref="IsClearing"/> is <c>false</c>
        /// and <see cref="VillageObject{ObstacleData}.Data"/> is not null; otherwise
        /// it throws an <see cref="InvalidOperationException"/>.
        /// </summary>
        /// <exception cref="InvalidOperationException"><see cref="IsClearing"/> is <c>true</c>.</exception>
        /// <exception cref="InvalidOperationException"><see cref="VillageObject{ObstacleData}.Data"/> is <c>null</c>.</exception>
        public void BeginClearing(int ctick)
        {
            if (IsClearing)
            {
                throw new InvalidOperationException("Obstacle object is already clearing.");
            }

            Debug.Assert(_data != null, "Obstacle Data was null.");
            var clearTime = _data.ClearTime;
            var seconds   = (int)clearTime.TotalSeconds;

            Village.WorkerManager.AllocateWorker(this);
            _timer.Start(Village.LastTickTime, ctick, seconds);
        }
        /// <summary>
        /// Begins the construction of the <see cref="Buildable{TCsvData}"/> and increases its level by 1
        /// when done.
        /// </summary>
        public void BeginConstruction(int ctick)
        {
            if (IsConstructing)
            {
                throw new InvalidOperationException("Buildable object is already in construction.");
            }

            if (NextUpgrade == null)
            {
                Debug.WriteLine("BeginConstruction: NextUpgrade was null, calling UpdateIsUpgradable to set NextUpgrade.");
            }

            UpdateIsUpgradable();
            if (!IsUpgradeable)
            {
                throw new InvalidOperationException("Buildable object is maxed or Town Hall level too low to perform construction.");
            }

            var buildTime = GetBuildTime(NextUpgrade);

            // No need to start up a TickTimer if the construction is instant.
            if (buildTime == InstantConstructionTime)
            {
                FinishConstruction(ctick);
            }
            else
            {
                Village.WorkerManager.AllocateWorker(this);
                _timer.Start(Village.LastTickTime, ctick, (int)buildTime.TotalSeconds);
            }
        }