Пример #1
0
        public override int Execute(LogicLevel level)
        {
            if (this.m_layoutId != -1)
            {
                if (level.GetTownHallLevel(level.GetVillageType()) >= level.GetRequiredTownHallLevelForLayout(this.m_layoutId, -1))
                {
                    if ((this.m_layoutId & 0xFFFFFFFE) != 6)
                    {
                        if (this.m_layoutType != 0)
                        {
                            if (this.m_layoutId != 1 && this.m_layoutId != 4 && this.m_layoutId != 5)
                            {
                                return(-5);
                            }
                        }
                        else
                        {
                            if (this.m_layoutId != 0 && this.m_layoutId != 2 && this.m_layoutId != 3)
                            {
                                return(-4);
                            }
                        }
                    }

                    LogicGameObjectFilter            filter      = new LogicGameObjectFilter();
                    LogicArrayList <LogicGameObject> gameObjects = new LogicArrayList <LogicGameObject>(500);

                    filter.AddGameObjectType(LogicGameObjectType.BUILDING);
                    filter.AddGameObjectType(LogicGameObjectType.TRAP);
                    filter.AddGameObjectType(LogicGameObjectType.DECO);

                    level.GetGameObjectManager().GetGameObjects(gameObjects, filter);

                    for (int i = 0; i < gameObjects.Size(); i++)
                    {
                        LogicGameObject gameObject = gameObjects[i];
                        LogicVector2    position   = gameObject.GetPositionLayout(this.m_layoutId, false);

                        if ((this.m_layoutId & 0xFFFFFFFE) != 6 && (position.m_x == -1 || position.m_y == -1))
                        {
                            return(-2);
                        }
                    }

                    LogicGameObjectManager           gameObjectManager = level.GetGameObjectManager();
                    LogicArrayList <LogicGameObject> buildings         = gameObjectManager.GetGameObjects(LogicGameObjectType.BUILDING);
                    LogicArrayList <LogicGameObject> obstacles         = gameObjectManager.GetGameObjects(LogicGameObjectType.OBSTACLE);

                    for (int i = 0; i < gameObjects.Size(); i++)
                    {
                        LogicGameObject gameObject = gameObjects[i];
                        LogicVector2    position   = gameObject.GetPositionLayout(this.m_layoutId, false);

                        int minX = position.m_x;
                        int minY = position.m_y;
                        int maxX = minX + gameObject.GetWidthInTiles();
                        int maxY = minY + gameObject.GetHeightInTiles();

                        for (int j = 0; j < obstacles.Size(); j++)
                        {
                            LogicObstacle obstacle = (LogicObstacle)obstacles[j];

                            int minX2 = obstacle.GetTileX();
                            int minY2 = obstacle.GetTileY();
                            int maxX2 = minX2 + obstacle.GetWidthInTiles();
                            int maxY2 = minY2 + obstacle.GetHeightInTiles();

                            if (maxX > minX2 && maxY > minY2 && minX < maxX2 && minY < maxY2)
                            {
                                if ((this.m_layoutId & 0xFFFFFFFE) != 6)
                                {
                                    return(-2);
                                }

                                gameObjectManager.RemoveGameObject(obstacle);
                                j -= 1;
                            }
                        }
                    }

                    for (int i = 0; i < buildings.Size(); i++)
                    {
                        LogicBuilding baseWallBlock = (LogicBuilding)buildings[i];

                        if (baseWallBlock.GetWallIndex() != 0)
                        {
                            int x             = baseWallBlock.GetTileX();
                            int y             = baseWallBlock.GetTileY();
                            int minX          = 0;
                            int minY          = 0;
                            int maxX          = 0;
                            int maxY          = 0;
                            int minWallBlockX = 0;
                            int minWallBlockY = 0;
                            int maxWallBlockX = 0;
                            int maxWallBlockY = 0;
                            int wallBlockCnt  = 0;

                            for (int j = 0; j < buildings.Size(); j++)
                            {
                                LogicBuilding wallBlock = (LogicBuilding)buildings[j];

                                if (wallBlock.GetWallIndex() == baseWallBlock.GetWallIndex())
                                {
                                    int tmp1 = x - wallBlock.GetTileX();
                                    int tmp2 = y - wallBlock.GetTileY();

                                    minX = LogicMath.Min(minX, tmp1);
                                    minY = LogicMath.Min(minY, tmp2);
                                    maxX = LogicMath.Max(maxX, tmp1);
                                    maxY = LogicMath.Max(maxY, tmp2);

                                    int wallBlockX = wallBlock.GetBuildingData().GetWallBlockX(wallBlockCnt);
                                    int wallBlockY = wallBlock.GetBuildingData().GetWallBlockY(wallBlockCnt);

                                    minWallBlockX = LogicMath.Min(minWallBlockX, wallBlockX);
                                    minWallBlockY = LogicMath.Min(minWallBlockY, wallBlockY);
                                    maxWallBlockX = LogicMath.Max(maxWallBlockX, wallBlockX);
                                    maxWallBlockY = LogicMath.Max(maxWallBlockY, wallBlockY);

                                    ++wallBlockCnt;
                                }
                            }

                            if (baseWallBlock.GetBuildingData().GetWallBlockCount() != wallBlockCnt)
                            {
                                return(-24);
                            }

                            int wallBlockSizeX = maxWallBlockX - minWallBlockX;
                            int wallBlockSizeY = maxWallBlockY - minWallBlockY;
                            int lengthX        = maxX - minX;
                            int lengthY        = maxY - minY;

                            if (wallBlockSizeX != lengthX || wallBlockSizeY != lengthY)
                            {
                                if (wallBlockSizeX != lengthX != (wallBlockSizeY != lengthY))
                                {
                                    return(-25);
                                }
                            }
                        }
                    }

                    if (this.m_layoutType != 0)
                    {
                        if (level.IsWarBase())
                        {
                            level.SetWarBase(true);
                        }

                        level.SetActiveWarLayout(this.m_layoutId);
                    }
                    else
                    {
                        level.SetActiveLayout(this.m_layoutId, level.GetVillageType());

                        for (int i = 0; i < gameObjects.Size(); i++)
                        {
                            LogicGameObject gameObject = gameObjects[i];
                            LogicVector2    position   = gameObject.GetPositionLayout(this.m_layoutId, false);

                            gameObject.SetPositionXY(position.m_x << 9, position.m_y << 9);
                        }
                    }

                    return(0);
                }
            }

            return(-10);
        }
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            int count = this._gameObjectIds.Count;

            if (count > 0)
            {
                bool validSize        = true;
                bool validGameObjects = true;

                if (this._xPositions.Count != count || this._xPositions.Count != count || count > 500)
                {
                    validSize = false;
                }

                if (validSize)
                {
                    LogicGameObject[] gameObjects = new LogicGameObject[count];

                    for (int i = 0; i < count; i++)
                    {
                        LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectIds[i]);

                        if (gameObject != null)
                        {
                            int gameObjectType = gameObject.GetGameObjectType();

                            if (gameObjectType > 6 || gameObjectType == 3)
                            {
                                validGameObjects = false;
                            }

                            gameObjects[i] = gameObject;
                        }
                        else
                        {
                            validGameObjects = false;
                        }
                    }

                    if (validGameObjects)
                    {
                        bool validWallBlock = true;

                        for (int i = 0; i < count; i++)
                        {
                            LogicGameObject gameObject = gameObjects[i];

                            if (gameObject.GetGameObjectType() == 0 && ((LogicBuilding)gameObject).GetWallIndex() != 0 && validWallBlock)
                            {
                                LogicBuilding baseWallBlock = (LogicBuilding)gameObject;

                                int x             = this._xPositions[i];
                                int y             = this._yPositions[i];
                                int minX          = 0;
                                int minY          = 0;
                                int maxX          = 0;
                                int maxY          = 0;
                                int minWallBlockX = 0;
                                int minWallBlockY = 0;
                                int maxWallBlockX = 0;
                                int maxWallBlockY = 0;

                                bool success = true;

                                int wallBlockCnt = -1;

                                for (int j = 0; j < count; j++)
                                {
                                    LogicGameObject obj = gameObjects[j];

                                    if (obj.GetGameObjectType() == 0 && ((LogicBuilding)obj).GetWallIndex() == baseWallBlock.GetWallIndex())
                                    {
                                        LogicBuilding wallBlock = (LogicBuilding)obj;

                                        int tmp1 = x - this._xPositions[j];
                                        int tmp2 = y - this._yPositions[j];

                                        if ((x & this._xPositions[j]) != -1)
                                        {
                                            success = false;
                                        }

                                        minX = LogicMath.Min(minX, tmp1);
                                        minY = LogicMath.Min(minY, tmp2);
                                        maxX = LogicMath.Max(maxX, tmp1);
                                        maxY = LogicMath.Max(maxY, tmp2);

                                        int wallBlockX = wallBlock.GetBuildingData().GetWallBlockX(j);
                                        int wallBlockY = wallBlock.GetBuildingData().GetWallBlockY(j);

                                        minWallBlockX = LogicMath.Min(minWallBlockX, wallBlockX);
                                        minWallBlockY = LogicMath.Min(minWallBlockY, wallBlockY);
                                        maxWallBlockX = LogicMath.Min(maxWallBlockX, wallBlockX);
                                        maxWallBlockY = LogicMath.Min(maxWallBlockY, wallBlockY);

                                        ++wallBlockCnt;
                                    }
                                }

                                if (baseWallBlock.GetBuildingData().GetWallBlockCount() == wallBlockCnt)
                                {
                                    int wallBlockSizeX = maxWallBlockX - minWallBlockX;
                                    int wallBlockSizeY = maxWallBlockY - minWallBlockY;
                                    int lengthX        = maxX - minX;
                                    int lengthY        = maxY - minY;

                                    if (wallBlockSizeX != lengthX || wallBlockSizeY != lengthY)
                                    {
                                        if (!success && (wallBlockSizeX != lengthX) != (wallBlockSizeY != lengthY))
                                        {
                                            validGameObjects = false;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        // EditmodeInvalidGameObjectType.
                    }

                    bool objectsOverlap = false;

                    if (validGameObjects)
                    {
                        int idx = 0;

                        while (idx < count)
                        {
                            int x = this._xPositions[idx];
                            int y = this._yPositions[idx];

                            LogicGameObject gameObject = gameObjects[idx];

                            int width  = gameObject.GetWidthInTiles();
                            int height = gameObject.GetHeightInTiles();

                            int tmp1 = x + width;
                            int tmp2 = y + height;

                            for (int i = 0; i < count; i++)
                            {
                                LogicGameObject gameObject2 = gameObjects[idx];

                                if (gameObject2 != gameObject)
                                {
                                    int x2      = this._xPositions[i];
                                    int y2      = this._yPositions[i];
                                    int width2  = gameObject2.GetWidthInTiles();
                                    int height2 = gameObject2.GetHeightInTiles();
                                    int tmp3    = x + width2;
                                    int tmp4    = y + height2;

                                    if (tmp1 > x2 && tmp2 > y2 && x2 < tmp3 && y2 < tmp4)
                                    {
                                        objectsOverlap = true;
                                        return(0);
                                    }
                                }
                            }

                            ++idx;
                        }
                    }

                    if (validGameObjects)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            int x = this._xPositions[i];
                            int y = this._yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];

                            int width  = gameObject.GetWidthInTiles();
                            int height = gameObject.GetHeightInTiles();

                            if (!level.IsValidPlaceForBuildingWithIgnoreList(x, y, width, height, gameObjects, count))
                            {
                                if (validGameObjects)
                                {
                                    // EditmodeInvalidPosition.
                                }

                                validGameObjects = false;
                            }
                        }
                    }

                    if (validGameObjects)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            int x = this._xPositions[i];
                            int y = this._yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];

                            gameObject.SetPositionXY(x << 9, y << 9);
                        }

                        for (int i = 0; i < count; i++)
                        {
                            int x = this._xPositions[i];
                            int y = this._yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];

                            int width  = gameObject.GetWidthInTiles();
                            int height = gameObject.GetHeightInTiles();

                            for (int j = 0; j < width; j++)
                            {
                                for (int k = 0; k < height; k++)
                                {
                                    LogicObstacle tallGrass = level.GetTileMap().GetTile(x + j, y + k).GetTallGrass();

                                    if (tallGrass != null)
                                    {
                                        level.GetGameObjectManager().RemoveGameObject(tallGrass);
                                    }
                                }
                            }
                        }

                        if (validGameObjects)
                        {
                            if (level.GetHomeOwnerAvatar() != null)
                            {
                                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                                if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetChallengeBaseCooldownTownHall())
                                {
                                    level.SetLayoutCooldownSecs(level.GetActiveLayout(level.GetVillageType()), LogicDataTables.GetGlobals().GetChallengeBaseSaveCooldown());
                                }
                            }
                        }

                        return(0);
                    }
                }
            }

            return(-1);
        }
        public override int Execute(LogicLevel level)
        {
            int count = this.m_gameObjectIds.Size();

            if (count > 0)
            {
                bool validGameObjectType = true;

                if (this.m_xPositions.Size() == count && this.m_xPositions.Size() == count && count <= 500)
                {
                    LogicGameObject[] gameObjects = new LogicGameObject[count];

                    for (int i = 0; i < count; i++)
                    {
                        LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[i]);

                        if (gameObject != null)
                        {
                            LogicGameObjectType gameObjectType = gameObject.GetGameObjectType();

                            if (gameObjectType != LogicGameObjectType.BUILDING &&
                                gameObjectType != LogicGameObjectType.TRAP &&
                                gameObjectType != LogicGameObjectType.DECO)
                            {
                                validGameObjectType = false;
                            }

                            gameObjects[i] = gameObject;
                        }
                        else
                        {
                            validGameObjectType = false;
                        }
                    }

                    if (validGameObjectType)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            LogicGameObject gameObject = gameObjects[i];

                            if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING && validGameObjectType)
                            {
                                LogicBuilding baseWallBlock = (LogicBuilding)gameObject;

                                if (baseWallBlock.GetWallIndex() != 0)
                                {
                                    int x             = this.m_xPositions[i];
                                    int y             = this.m_yPositions[i];
                                    int minX          = 0;
                                    int minY          = 0;
                                    int maxX          = 0;
                                    int maxY          = 0;
                                    int minWallBlockX = 0;
                                    int minWallBlockY = 0;
                                    int maxWallBlockX = 0;
                                    int maxWallBlockY = 0;
                                    int wallBlockCnt  = 0;

                                    bool success = true;

                                    for (int j = 0; j < count; j++)
                                    {
                                        LogicGameObject obj = gameObjects[j];

                                        if (obj.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                        {
                                            LogicBuilding wallBlock = (LogicBuilding)obj;

                                            if (wallBlock.GetWallIndex() == baseWallBlock.GetWallIndex())
                                            {
                                                int tmp1 = x - this.m_xPositions[j];
                                                int tmp2 = y - this.m_yPositions[j];

                                                if ((x & this.m_xPositions[j]) != -1)
                                                {
                                                    success = false;
                                                }

                                                minX = LogicMath.Min(minX, tmp1);
                                                minY = LogicMath.Min(minY, tmp2);
                                                maxX = LogicMath.Max(maxX, tmp1);
                                                maxY = LogicMath.Max(maxY, tmp2);

                                                int wallBlockX = wallBlock.GetBuildingData().GetWallBlockX(wallBlockCnt);
                                                int wallBlockY = wallBlock.GetBuildingData().GetWallBlockY(wallBlockCnt);

                                                minWallBlockX = LogicMath.Min(minWallBlockX, wallBlockX);
                                                minWallBlockY = LogicMath.Min(minWallBlockY, wallBlockY);
                                                maxWallBlockX = LogicMath.Max(maxWallBlockX, wallBlockX);
                                                maxWallBlockY = LogicMath.Max(maxWallBlockY, wallBlockY);

                                                ++wallBlockCnt;
                                            }
                                        }
                                    }

                                    if (baseWallBlock.GetBuildingData().GetWallBlockCount() == wallBlockCnt)
                                    {
                                        int wallBlockSizeX = maxWallBlockX - minWallBlockX;
                                        int wallBlockSizeY = maxWallBlockY - minWallBlockY;
                                        int lengthX        = maxX - minX;
                                        int lengthY        = maxY - minY;

                                        if (wallBlockSizeX != lengthX || wallBlockSizeY != lengthY)
                                        {
                                            if (!success && wallBlockSizeX != lengthX != (wallBlockSizeY != lengthY))
                                            {
                                                validGameObjectType = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Debugger.Warning("EditModeInvalidGameObjectType");
                        return(-1);
                    }

                    if (validGameObjectType)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            int x = this.m_xPositions[i];
                            int y = this.m_yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];

                            int maxX = x + gameObject.GetWidthInTiles();
                            int maxY = y + gameObject.GetHeightInTiles();

                            for (int j = 0; j < count; j++)
                            {
                                LogicGameObject gameObject2 = gameObjects[j];

                                if (gameObject2 != gameObject)
                                {
                                    int x2    = this.m_xPositions[j];
                                    int y2    = this.m_yPositions[j];
                                    int maxX2 = x2 + gameObject2.GetWidthInTiles();
                                    int maxY2 = y2 + gameObject2.GetHeightInTiles();

                                    if (maxX > x2 && maxY > y2 && x < maxX2 && y < maxY2)
                                    {
                                        Debugger.Warning("EditModeObjectsOverlap");
                                        return(-1);
                                    }
                                }
                            }
                        }
                    }

                    if (validGameObjectType)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            int x = this.m_xPositions[i];
                            int y = this.m_yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];

                            int width  = gameObject.GetWidthInTiles();
                            int height = gameObject.GetHeightInTiles();

                            if (!level.IsValidPlaceForBuildingWithIgnoreList(x, y, width, height, gameObjects, count))
                            {
                                Debugger.Warning("EditModeInvalidPosition");
                                return(-1);
                            }
                        }
                    }

                    if (validGameObjectType)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            int x = this.m_xPositions[i];
                            int y = this.m_yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];

                            gameObject.SetPositionXY(x << 9, y << 9);
                        }

                        for (int i = 0; i < count; i++)
                        {
                            int x = this.m_xPositions[i];
                            int y = this.m_yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];

                            int width  = gameObject.GetWidthInTiles();
                            int height = gameObject.GetHeightInTiles();

                            for (int j = 0; j < width; j++)
                            {
                                for (int k = 0; k < height; k++)
                                {
                                    LogicObstacle tallGrass = level.GetTileMap().GetTile(x + j, y + k).GetTallGrass();

                                    if (tallGrass != null)
                                    {
                                        level.GetGameObjectManager().RemoveGameObject(tallGrass);
                                    }
                                }
                            }
                        }

                        if (level.GetHomeOwnerAvatar() != null)
                        {
                            LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                            if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetChallengeBaseCooldownEnabledTownHall())
                            {
                                level.SetLayoutCooldownSecs(level.GetActiveLayout(level.GetVillageType()), LogicDataTables.GetGlobals().GetChallengeBaseSaveCooldown());
                            }
                        }

                        return(0);
                    }
                }
                else
                {
                    Debugger.Warning("EditModeSizeMismatch");
                }

                return(-1);
            }

            return(-92);
        }
Пример #4
0
        public override int Execute(LogicLevel level)
        {
            if (this.m_layoutId != 6)
            {
                if (this.m_layoutId != 7)
                {
                    LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId);

                    if (gameObject != null)
                    {
                        LogicGameObjectType gameObjectType = gameObject.GetGameObjectType();

                        if (gameObjectType == LogicGameObjectType.BUILDING ||
                            gameObjectType == LogicGameObjectType.TRAP ||
                            gameObjectType == LogicGameObjectType.DECO)
                        {
                            LogicRect playArea = level.GetPlayArea();

                            if (playArea.IsInside(this.m_x, this.m_y) && playArea.IsInside(this.m_x + gameObject.GetWidthInTiles(), this.m_y + gameObject.GetHeightInTiles()) ||
                                this.m_x == -1 ||
                                this.m_y == -1)
                            {
                                if (gameObjectType == LogicGameObjectType.BUILDING)
                                {
                                    LogicBuilding building = (LogicBuilding)gameObject;

                                    if (building.GetWallIndex() != 0)
                                    {
                                        return(-23);
                                    }
                                }

                                gameObject.SetPositionLayoutXY(this.m_x, this.m_y, this.m_layoutId, true);

                                LogicGlobals globals = LogicDataTables.GetGlobals();

                                if (!globals.NoCooldownFromMoveEditModeActive())
                                {
                                    if (level.GetActiveLayout(level.GetVillageType()) == this.m_layoutId)
                                    {
                                        LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                                        if (homeOwnerAvatar.GetExpLevel() >= globals.GetChallengeBaseCooldownEnabledTownHall())
                                        {
                                            level.SetLayoutCooldownSecs(this.m_layoutId, globals.GetChallengeBaseSaveCooldown());
                                        }
                                    }
                                }

                                return(0);
                            }

                            return(-2); // EditModeOutsideMap
                        }

                        return(-1);
                    }

                    return(-3);
                }

                return(-6);
            }

            return(-5);
        }
Пример #5
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);
        }
Пример #6
0
        public override int Execute(LogicLevel level)
        {
            int count = this.m_gameObjectIds.Size();

            if (count > 0)
            {
                bool validGameObjects = true;

                if (this.m_xPositions.Size() == count && this.m_xPositions.Size() == count && count <= 500)
                {
                    LogicGameObject[] gameObjects = new LogicGameObject[count];

                    for (int i = 0; i < count; i++)
                    {
                        LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[i]);

                        if (gameObject != null)
                        {
                            LogicGameObjectType gameObjectType = gameObject.GetGameObjectType();

                            if (gameObjectType != LogicGameObjectType.BUILDING &&
                                gameObjectType != LogicGameObjectType.TRAP &&
                                gameObjectType != LogicGameObjectType.DECO)
                            {
                                validGameObjects = false;
                            }

                            gameObjects[i] = gameObject;
                        }
                        else
                        {
                            validGameObjects = false;
                        }
                    }

                    if (validGameObjects)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            LogicGameObject gameObject = gameObjects[i];

                            if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING && validGameObjects)
                            {
                                LogicBuilding baseWallBlock = (LogicBuilding)gameObject;

                                if (baseWallBlock.GetWallIndex() != 0)
                                {
                                    int x             = this.m_xPositions[i];
                                    int y             = this.m_yPositions[i];
                                    int minX          = 0;
                                    int minY          = 0;
                                    int maxX          = 0;
                                    int maxY          = 0;
                                    int minWallBlockX = 0;
                                    int minWallBlockY = 0;
                                    int maxWallBlockX = 0;
                                    int maxWallBlockY = 0;
                                    int wallBlockCnt  = 0;

                                    bool success = true;

                                    for (int j = 0; j < count; j++)
                                    {
                                        LogicGameObject obj = gameObjects[j];

                                        if (obj.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                        {
                                            LogicBuilding wallBlock = (LogicBuilding)obj;

                                            if (wallBlock.GetWallIndex() == baseWallBlock.GetWallIndex())
                                            {
                                                int tmp1 = x - this.m_xPositions[j];
                                                int tmp2 = y - this.m_yPositions[j];

                                                if ((x & this.m_xPositions[j]) != -1)
                                                {
                                                    success = false;
                                                }

                                                minX = LogicMath.Min(minX, tmp1);
                                                minY = LogicMath.Min(minY, tmp2);
                                                maxX = LogicMath.Max(maxX, tmp1);
                                                maxY = LogicMath.Max(maxY, tmp2);

                                                int wallBlockX = wallBlock.GetBuildingData().GetWallBlockX(wallBlockCnt);
                                                int wallBlockY = wallBlock.GetBuildingData().GetWallBlockY(wallBlockCnt);

                                                minWallBlockX = LogicMath.Min(minWallBlockX, wallBlockX);
                                                minWallBlockY = LogicMath.Min(minWallBlockY, wallBlockY);
                                                maxWallBlockX = LogicMath.Max(maxWallBlockX, wallBlockX);
                                                maxWallBlockY = LogicMath.Max(maxWallBlockY, wallBlockY);

                                                ++wallBlockCnt;
                                            }
                                        }
                                    }

                                    if (baseWallBlock.GetBuildingData().GetWallBlockCount() == wallBlockCnt)
                                    {
                                        int wallBlockSizeX = maxWallBlockX - minWallBlockX;
                                        int wallBlockSizeY = maxWallBlockY - minWallBlockY;
                                        int lengthX        = maxX - minX;
                                        int lengthY        = maxY - minY;

                                        if (wallBlockSizeX != lengthX || wallBlockSizeY != lengthY)
                                        {
                                            if (!success && wallBlockSizeX != lengthX != (wallBlockSizeY != lengthY))
                                            {
                                                validGameObjects = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (validGameObjects)
                    {
                        for (int i = 0; i < count; i++)
                        {
                            int x = this.m_xPositions[i];
                            int y = this.m_yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];

                            int width  = gameObject.GetWidthInTiles();
                            int height = gameObject.GetHeightInTiles();

                            int tmp1 = x + width;
                            int tmp2 = y + height;

                            for (int j = 0; j < count; j++)
                            {
                                LogicGameObject gameObject2 = gameObjects[j];

                                if (gameObject2 != gameObject)
                                {
                                    int x2 = this.m_xPositions[j];
                                    int y2 = this.m_yPositions[j];

                                    if (x2 != -1 && y2 != -1)
                                    {
                                        int width2  = gameObject2.GetWidthInTiles();
                                        int height2 = gameObject2.GetHeightInTiles();
                                        int tmp3    = x2 + width2;
                                        int tmp4    = y2 + height2;

                                        if (tmp1 > x2 && tmp2 > y2 && x < tmp3 && y < tmp4)
                                        {
                                            return(0);
                                        }
                                    }
                                }
                            }
                        }

                        bool moved = false;

                        for (int i = 0; i < count; i++)
                        {
                            int x = this.m_xPositions[i];
                            int y = this.m_yPositions[i];

                            LogicGameObject gameObject = gameObjects[i];
                            LogicVector2    position   = gameObject.GetPositionLayout(this.m_layoutId, true);

                            if (position.m_x != -1 && position.m_y != -1)
                            {
                                if (x != position.m_x && y != position.m_y)
                                {
                                    moved = true;
                                }
                            }

                            gameObject.SetPositionLayoutXY(x, y, this.m_layoutId, true);

                            LogicGlobals globals = LogicDataTables.GetGlobals();

                            if (!globals.NoCooldownFromMoveEditModeActive())
                            {
                                if (level.GetActiveLayout(level.GetVillageType()) == this.m_layoutId)
                                {
                                    LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                                    if (homeOwnerAvatar.GetExpLevel() >= globals.GetChallengeBaseCooldownEnabledTownHall())
                                    {
                                        level.SetLayoutCooldownSecs(this.m_layoutId, globals.GetChallengeBaseSaveCooldown());
                                    }
                                }
                            }
                        }

                        if (moved)
                        {
                            LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                            if (homeOwnerAvatar.GetExpLevel() >= LogicDataTables.GetGlobals().GetChallengeBaseCooldownEnabledTownHall())
                            {
                                level.SetLayoutCooldownSecs(this.m_layoutId, LogicDataTables.GetGlobals().GetChallengeBaseSaveCooldown());
                            }
                        }

                        return(0);
                    }
                }
            }

            return(-1);
        }
Пример #7
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);
        }