/// <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}");
                    }
                }
            }
        }
        /// <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;
                            }
                        }
                    }
                }
            }
        }