Ejemplo n.º 1
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar      playerAvatar       = level.GetPlayerAvatar();
            LogicGameObjectManager gameObjectManager  = level.GetGameObjectManager();
            LogicResourceData      repairResourceData = null;

            int repairCost = 0;

            for (int i = 0; i < this.m_gameObjectIds.Size(); i++)
            {
                LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectIds[i]);

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

                    if (trap.IsDisarmed() && !trap.IsConstructing())
                    {
                        LogicTrapData data = trap.GetTrapData();

                        repairResourceData = data.GetBuildResource();
                        repairCost        += data.GetRearmCost(trap.GetUpgradeLevel());
                    }
                }
            }

            if (repairResourceData != null && repairCost != 0)
            {
                if (playerAvatar.HasEnoughResources(repairResourceData, repairCost, true, this, false))
                {
                    playerAvatar.CommodityCountChangeHelper(0, repairResourceData, -repairCost);

                    for (int i = 0; i < this.m_gameObjectIds.Size(); i++)
                    {
                        LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectIds[i]);

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

                            if (trap.IsDisarmed() && !trap.IsConstructing())
                            {
                                trap.RepairTrap();
                            }
                        }
                    }

                    return(0);
                }

                return(-2);
            }

            return(-1);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Cancels the construction of trap.
        /// </summary>
        public void CancelConstruction()
        {
            LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar();

            if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar())
            {
                if (this._constructionTimer != null)
                {
                    this._constructionTimer.Destruct();
                    this._constructionTimer = null;

                    int upgLevel = this._upgLevel;

                    if (this._upgrading)
                    {
                        this.SetUpgradeLevel(this._upgLevel);
                        upgLevel += 1;
                    }

                    LogicTrapData     data = this.GetTrapData();
                    LogicResourceData buildResourceData = data.GetBuildResource();
                    Int32             buildCost         = data.GetBuildCost(upgLevel);
                    Int32             refundedCount     = LogicMath.Max(LogicDataTables.GetGlobals().GetBuildCancelMultiplier() * buildCost / 100, 0);
                    Debugger.Print("LogicTrap::cancelConstruction refunds: " + refundedCount);

                    homeOwnerAvatar.CommodityCountChangeHelper(0, buildResourceData, refundedCount);

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

                    if (upgLevel != 0)
                    {
                        if (this._listener != null)
                        {
                            this._listener.RefreshState();
                        }
                    }
                    else
                    {
                        this.GetGameObjectManager().RemoveGameObject(this);
                    }
                }
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo 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);
        }