Example #1
0
        public void FinishConstruction(bool ignoreState, bool ignoreListener)
        {
            int state = this.m_level.GetState();

            if (state == 1 || !LogicDataTables.GetGlobals().CompleteConstructionOnlyHome() && ignoreState)
            {
                if (this.m_level.GetHomeOwnerAvatar() != null &&
                    this.m_level.GetHomeOwnerAvatar().IsClientAvatar())
                {
                    if (this.m_constructionTimer != null)
                    {
                        this.m_constructionTimer.Destruct();
                        this.m_constructionTimer = null;
                    }

                    LogicAvatar            homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
                    LogicVillageObjectData data            = this.GetVillageObjectData();

                    if (data.IsRequiresBuilder())
                    {
                        this.m_level.GetWorkerManagerAt(data.GetVillageType()).DeallocateWorker(this);
                    }

                    this.m_locked = false;

                    if (this.m_upgLevel != 0 || this.m_upgrading)
                    {
                        int nextUpgLevel = this.m_upgLevel + 1;

                        if (this.m_upgLevel >= data.GetUpgradeLevelCount() - 1)
                        {
                            Debugger.Warning("LogicVillageObject - Trying to upgrade to level that doesn't exist! - " + data.GetName());
                            nextUpgLevel = data.GetUpgradeLevelCount() - 1;
                        }

                        int constructionTime = data.GetBuildTime(nextUpgLevel);
                        int xpGain           = LogicMath.Sqrt(constructionTime);

                        this.m_upgLevel = nextUpgLevel;

                        this.XpGainHelper(xpGain, homeOwnerAvatar, ignoreState);
                    }
                    else
                    {
                        int constructionTime = data.GetBuildTime(0);
                        int xpGain           = LogicMath.Sqrt(constructionTime);

                        this.XpGainHelper(xpGain, homeOwnerAvatar, ignoreState);
                    }

                    this.m_upgrading = false;

                    if (this.m_listener != null)
                    {
                        this.m_listener.RefreshState();
                    }

                    if (state == 1)
                    {
                        this.m_level.GetAchievementManager().RefreshStatus();
                    }
                }
                else
                {
                    Debugger.Error("LogicVillageObject::finishCostruction failed - Avatar is null or not client avatar");
                }
            }
        }