コード例 #1
0
        /// <summary>
        /// Adds the production completed in storage and starts the next production if possible.
        /// </summary>
        internal void ProductionCompleted()
        {
            if (this.Parent.Home.Player.Level.State == State.Home || this.Parent.Home.Player.Level.State == State.Defend)
            {
                if (this.UnitCount > 0)
                {
                    UnitStorageComponent UnitStorageComponent = (UnitStorageComponent)this.Parent.GetComponent(0);

                    if (UnitStorageComponent.CanAddUnit(this.UnitData, 1))
                    {
                        UnitStorageComponent.AddUnit(this.UnitData, 1);
                        this.Parent.Home.Player.Units.Add(this.UnitData, 1);
                    }
                    else
                    {
                        CharacterData UnitData  = this.UnitData;
                        int           UnitCount = this.UnitCount;

                        this.UnitData  = null;
                        this.UnitCount = 0;

                        this.ProductionTimer = null;

                        throw new Exception($"Bug in production completed: unit still in training!!! avatarId: {this.Parent.Home.Player.HighID}-{this.Parent.Home.Player.LowID}, count: {UnitCount} troop: {UnitData.GlobalID} gamemode: {(int) this.Parent.Home.Level.State}");
                    }
                }
            }
        }
コード例 #2
0
ファイル: Building.cs プロジェクト: nextgenhacker/GL.Servers
        /// <summary>
        /// Sets the building upgrade level. Check before if the level is valid.
        /// </summary>
        /// <param name="Level">The level.</param>
        internal void SetUpgradeLevel(int Level)
        {
            this.UpgradeLevel = Level;

            if (this.BuildingData.IsTownHallOrCommandCenter())
            {
                this.Home.Player.TownHallLevel = Level;
            }

            HitpointComponent HitpointComponent = this.HitpointComponent;

            if (HitpointComponent != null)
            {
                HitpointComponent.SetHitpoints(this.BuildingData.Hitpoints[Level]);
                HitpointComponent.SetMaxHitpoints(this.BuildingData.Hitpoints[Level]);
            }

            UnitStorageComponent UnitStorageComponent = (UnitStorageComponent)this.GetComponent(0);

            if (UnitStorageComponent != null)
            {
                UnitStorageComponent.MaxCapacity = this.BuildingData.GetUnitProduction(Level);
            }

            // TODO Implement LogicBuilding Component Update.
        }
コード例 #3
0
        /// <summary>
        /// Gets a value indicating whether can add unit to queue.
        /// </summary>
        /// <param name="Data"></param>
        internal bool CanAddUnitToQueue(CharacterData Data, int Count)
        {
            if (Data != null)
            {
                Building Building = (Building)this.Parent;

                if (!Building.IsConstructing)
                {
                    UnitStorageComponent UnitStorageComponent = (UnitStorageComponent)this.Parent.GetComponent(0);

                    if (UnitStorageComponent.MaxCapacity >= UnitStorageComponent.UsedCapacity + Data.HousingSpace * Count)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #4
0
        /// <inheritdoc />
        internal override void Tick()
        {
            if (this.UnitCount > 0)
            {
                if (this.Parent.Home.Level.State == State.Home)
                {
                    bool IsTutorialOngoing = this.Parent.Home.Level.IsTutorialOngoing;
                    UnitStorageComponent UnitStorageComponent = (UnitStorageComponent)this.Parent.GetComponent(0);

                    while (this.ProductionTimer.GetRemainingSeconds(this.Parent.Home.Time) <= 0)
                    {
                        if (UnitStorageComponent.CanAddUnit(this.UnitData, 1))
                        {
                            UnitStorageComponent.AddUnit(this.UnitData, 1);

                            if (--this.UnitCount > 0)
                            {
                                if (IsTutorialOngoing)
                                {
                                    this.ProductionTimer.IncreaseTimer(1);
                                }
                                else if (false) // LogicUnitProductionComponent::isInstantTraining()
                                {
                                    this.ProductionTimer.IncreaseTimer(0);
                                }
                                else
                                {
                                    this.ProductionTimer.IncreaseTimer(this.UnitData.TrainingTime);
                                }
                            }
                            else
                            {
                                this.ProductionTimer = null;
                                this.UnitData        = null;
                                this.UnitCount       = 0;

                                break;
                            }
                        }
                    }
                }
            }
        }