Exemplo n.º 1
0
        /// <summary>
        ///     Starts the upgrading of the trap.
        /// </summary>
        public void StartUpgrading()
        {
            if (this._constructionTimer != null)
            {
                this._constructionTimer.Destruct();
                this._constructionTimer = null;
            }

            LogicTrapData data = this.GetTrapData();

            this._upgrading = true;
            int buildTime = data.GetBuildTime(this._upgLevel + 1);

            if (buildTime <= 0)
            {
                this.FinishConstruction(false);
            }
            else
            {
                this._level.GetWorkerManagerAt(data.GetVillageType()).AllocateWorker(this);

                this._constructionTimer = new LogicTimer();
                this._constructionTimer.StartTimer(buildTime, this._level.GetLogicTime(), true, this._level.GetGameMode().GetCurrentTimestamp());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectId);

            if (gameObject != null)
            {
                if (gameObject.GetGameObjectType() == 0)
                {
                    LogicBuilding     building     = (LogicBuilding)gameObject;
                    LogicBuildingData buildingData = building.GetBuildingData();

                    if (buildingData.IsTownHallVillage2())
                    {
                        if (!this.UnlockVillage2())
                        {
                            return(-76);
                        }
                    }

                    if (buildingData.GetVillageType() == level.GetVillageType())
                    {
                        if (building.GetWallIndex() == 0)
                        {
                            if (building.CanUpgrade(true))
                            {
                                int nextUpgradeLevel = building.GetUpgradeLevel() + 1;
                                int buildCost        = buildingData.GetBuildCost(nextUpgradeLevel, level);

                                LogicResourceData buildResourceData = this._useAltResources ? buildingData.GetAltBuildResource(nextUpgradeLevel) : buildingData.GetBuildResource(nextUpgradeLevel);

                                if (buildResourceData != null)
                                {
                                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                                    if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false))
                                    {
                                        int constructionTime = buildingData.GetConstructionTime(nextUpgradeLevel, level, 0);

                                        if (constructionTime != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime())
                                        {
                                            if (!level.HasFreeWorkers(this, -1))
                                            {
                                                return(-1);
                                            }
                                        }

                                        playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                                        building.StartUpgrading(true, false);

                                        return(0);
                                    }
                                }
                            }

                            return(-1);
                        }

                        return(-35);
                    }

                    return(-32);
                }
                else if (gameObject.GetGameObjectType() == 4)
                {
                    LogicTrap trap = (LogicTrap)gameObject;

                    if (trap.CanUpgrade(true))
                    {
                        LogicTrapData     data = trap.GetTrapData();
                        LogicResourceData buildResourceData = data.GetBuildResource();
                        LogicClientAvatar playerAvatar      = level.GetPlayerAvatar();

                        int buildCost = data.GetBuildCost(trap.GetUpgradeLevel() + 1);

                        if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false))
                        {
                            int constructionTime = data.GetBuildTime(trap.GetUpgradeLevel() + 1);

                            if (constructionTime != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime())
                            {
                                if (!level.HasFreeWorkers(this, -1))
                                {
                                    return(-1);
                                }

                                playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                                trap.StartUpgrading();

                                return(0);
                            }
                        }
                    }
                }
                else if (gameObject.GetGameObjectType() == 8)
                {
                    if (!this._useAltResources)
                    {
                        LogicVillageObject villageObject = (LogicVillageObject)gameObject;
                        // TODO: Implement upgrade vObjs.
                    }

                    return(-31);
                }
            }

            return(-1);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Finishes the construction of the <see cref="LogicBuilding"/>.
        /// </summary>
        public void FinishConstruction(bool ignoreState)
        {
            int state = this._level.GetState();

            if (state == 1 || !LogicDataTables.GetGlobals().CompleteConstructionOnlyHome() && ignoreState)
            {
                LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar())
                {
                    LogicTrapData data = this.GetTrapData();

                    if (this._constructionTimer != null)
                    {
                        this._constructionTimer.Destruct();
                        this._constructionTimer = null;
                    }

                    this._level.GetWorkerManagerAt(this._data.GetVillageType()).DeallocateWorker(this);

                    if (this._upgLevel != 0 || this._upgrading)
                    {
                        if (this._upgLevel >= data.GetUpgradeLevelCount() - 1)
                        {
                            Debugger.Warning("LogicTrap - Trying to upgrade to level that doesn't exist! - " + data.GetName());
                            this._upgLevel = data.GetUpgradeLevelCount() - 1;
                        }
                        else
                        {
                            this._upgLevel += 1;
                        }
                    }

                    if (!ignoreState && !this._disarmed)
                    {
                        if (this.GetListener() != null)
                        {
                            // Listener.
                        }
                    }

                    this.XpGainHelper(LogicGamePlayUtil.TimeToExp(data.GetBuildTime(this._upgLevel)), homeOwnerAvatar, ignoreState);

                    if (this._disarmed)
                    {
                        // Listener.
                    }

                    this._fadeTime  = 0;
                    this._disarmed  = false;
                    this._upgrading = false;

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

                    if (state == 1)
                    {
                        this._level.GetAchievementManager().RefreshStatus();
                    }
                }
                else
                {
                    Debugger.Warning("LogicTrap::finishCostruction failed - Avatar is null or not client avatar");
                }
            }
        }
Exemplo n.º 4
0
        public override int Execute(LogicLevel level)
        {
            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId);

            if (gameObject != null)
            {
                if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                {
                    LogicBuilding     building     = (LogicBuilding)gameObject;
                    LogicBuildingData buildingData = building.GetBuildingData();

                    if (buildingData.IsTownHallVillage2())
                    {
                        if (!LogicUpgradeBuildingCommand.CanUpgradeTHV2(level))
                        {
                            return(-76);
                        }
                    }

                    if (buildingData.GetVillageType() == level.GetVillageType())
                    {
                        if (level.GetGameObjectManager().GetAvailableBuildingUpgradeCount(building) <= 0)
                        {
                            return(-34);
                        }

                        if (building.GetWallIndex() == 0)
                        {
                            if (building.CanUpgrade(true))
                            {
                                int nextUpgradeLevel = building.GetUpgradeLevel() + 1;
                                int buildCost        = buildingData.GetBuildCost(nextUpgradeLevel, level);

                                LogicResourceData buildResourceData = this.m_useAltResource
                                    ? buildingData.GetAltBuildResource(nextUpgradeLevel)
                                    : buildingData.GetBuildResource(nextUpgradeLevel);

                                if (buildResourceData != null)
                                {
                                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                                    if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false))
                                    {
                                        if (buildingData.GetConstructionTime(nextUpgradeLevel, level, 0) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime())
                                        {
                                            if (!level.HasFreeWorkers(this, -1))
                                            {
                                                return(-1);
                                            }
                                        }

                                        playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                                        building.StartUpgrading(true, false);

                                        return(0);
                                    }
                                }
                            }

                            return(-1);
                        }

                        return(-35);
                    }

                    return(-32);
                }

                if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP)
                {
                    LogicTrap trap = (LogicTrap)gameObject;

                    if (trap.CanUpgrade(true))
                    {
                        LogicTrapData     data = trap.GetTrapData();
                        LogicResourceData buildResourceData = data.GetBuildResource();
                        LogicClientAvatar playerAvatar      = level.GetPlayerAvatar();

                        int buildCost = data.GetBuildCost(trap.GetUpgradeLevel() + 1);

                        if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false))
                        {
                            if (data.GetBuildTime(trap.GetUpgradeLevel() + 1) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime())
                            {
                                if (!level.HasFreeWorkers(this, -1))
                                {
                                    return(-1);
                                }
                            }

                            playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                            trap.StartUpgrading();

                            return(0);
                        }
                    }
                }
                else if (gameObject.GetGameObjectType() == LogicGameObjectType.VILLAGE_OBJECT)
                {
                    if (!this.m_useAltResource)
                    {
                        LogicVillageObject villageObject = (LogicVillageObject)gameObject;

                        if (villageObject.CanUpgrade(true))
                        {
                            LogicVillageObjectData data = villageObject.GetVillageObjectData();
                            LogicResourceData      buildResourceData = data.GetBuildResource();

                            int buildCost = data.GetBuildCost(villageObject.GetUpgradeLevel() + 1);

                            if (buildResourceData != null)
                            {
                                LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                                if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false))
                                {
                                    if (data.GetBuildTime(villageObject.GetUpgradeLevel() + 1) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime())
                                    {
                                        if (!level.HasFreeWorkers(this, -1))
                                        {
                                            return(-1);
                                        }
                                    }

                                    playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                                    villageObject.StartUpgrading(true);

                                    return(0);
                                }
                            }
                        }

                        return(-1);
                    }

                    return(-31);
                }
            }

            return(-1);
        }
        public override void Load(LogicJSONObject jsonObject)
        {
            this.LoadUpgradeLevel(jsonObject);

            LogicTrapData data = this.GetTrapData();

            if (data.HasAlternativeMode() || data.GetSpawnedCharAir() != null && data.GetSpawnedCharGround() != null)
            {
                LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT);

                if (layoutComponent != null)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        LogicJSONBoolean airModeObject = jsonObject.GetJSONBoolean(layoutComponent.GetLayoutVariableNameAirMode(i, false));

                        if (airModeObject != null)
                        {
                            this.m_useAirMode[i] = airModeObject.IsTrue();
                        }

                        LogicJSONBoolean draftAirModeObject = jsonObject.GetJSONBoolean(layoutComponent.GetLayoutVariableNameAirMode(i, true));

                        if (draftAirModeObject != null)
                        {
                            this.m_draftUseAirMode[i] = draftAirModeObject.IsTrue();
                        }
                    }
                }

                LogicTriggerComponent triggerComponent = this.GetTriggerComponent();

                int  layoutId = this.m_level.GetCurrentLayout();
                bool airMode  = this.m_useAirMode[layoutId];

                triggerComponent.SetAirTrigger(airMode);
                triggerComponent.SetGroundTrigger(!airMode);
            }

            if (data.GetDirectionCount() > 0)
            {
                LogicLayoutComponent layoutComponent = (LogicLayoutComponent)this.GetComponent(LogicComponentType.LAYOUT);

                if (layoutComponent != null)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        LogicJSONNumber trapDistanceObject = jsonObject.GetJSONNumber(layoutComponent.GetLayoutVariableNameTrapDirection(i, false));

                        if (trapDistanceObject != null)
                        {
                            this.m_direction[i] = trapDistanceObject.GetIntValue();
                        }

                        LogicJSONNumber draftTrapDistanceObject = jsonObject.GetJSONNumber(layoutComponent.GetLayoutVariableNameTrapDirection(i, true));

                        if (draftTrapDistanceObject != null)
                        {
                            this.m_draftDirection[i] = draftTrapDistanceObject.GetIntValue();
                        }
                    }
                }
            }

            this.m_level.GetWorkerManagerAt(this.m_villageType).DeallocateWorker(this);

            if (this.m_constructionTimer != null)
            {
                this.m_constructionTimer.Destruct();
                this.m_constructionTimer = null;
            }

            LogicJSONNumber constTimeObject = jsonObject.GetJSONNumber("const_t");

            if (constTimeObject != null)
            {
                int constTime = constTimeObject.GetIntValue();

                if (!LogicDataTables.GetGlobals().ClampBuildingTimes())
                {
                    if (this.m_upgLevel < data.GetUpgradeLevelCount() - 1)
                    {
                        constTime = LogicMath.Min(constTime, data.GetBuildTime(this.m_upgLevel + 1));
                    }
                }

                this.m_constructionTimer = new LogicTimer();
                this.m_constructionTimer.StartTimer(constTime, this.m_level.GetLogicTime(), false, -1);

                LogicJSONNumber constTimeEndObject = jsonObject.GetJSONNumber("const_t_end");

                if (constTimeEndObject != null)
                {
                    this.m_constructionTimer.SetEndTimestamp(constTimeEndObject.GetIntValue());
                }

                LogicJSONNumber conffObject = jsonObject.GetJSONNumber("con_ff");

                if (conffObject != null)
                {
                    this.m_constructionTimer.SetFastForward(conffObject.GetIntValue());
                }

                this.m_level.GetWorkerManagerAt(this.m_villageType).AllocateWorker(this);
                this.m_upgrading = this.m_upgLevel != -1;
            }

            LogicJSONBoolean disarmed = jsonObject.GetJSONBoolean("needs_repair");

            if (disarmed != null)
            {
                this.m_disarmed = disarmed.IsTrue();
            }

            this.SetUpgradeLevel(this.m_upgLevel);
            base.Load(jsonObject);
        }