コード例 #1
0
        public void RefreshPassable(LogicGameObject gameObject)
        {
            if (gameObject.IsStaticObject())
            {
                int tileX = gameObject.GetTileX();
                int tileY = gameObject.GetTileY();

                if (tileX >= 0 && tileY >= 0)
                {
                    int sizeX = gameObject.GetWidthInTiles();
                    int sizeY = gameObject.GetHeightInTiles();

                    for (int i = 0; i < sizeY; i++)
                    {
                        for (int j = 0; j < sizeX; j++)
                        {
                            LogicTile tile = this.GetTile(tileX + j, tileY + i);
                            Debugger.DoAssert(tile != null, "illegal tile index");
                            tile.RefreshPassableFlag();
                        }
                    }

                    this.UpdateRoomIndices();
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///     Refreshes passable of the specified <see cref="LogicGameObject"/> instance..
        /// </summary>
        public void RefreshPassable(LogicGameObject gameObject)
        {
            if (gameObject.IsStaticObject())
            {
                int tileX = gameObject.GetTileX();
                int tileY = gameObject.GetTileY();

                if (tileX >= 0)
                {
                    if (tileY >= 0)
                    {
                        int sizeX = gameObject.GetWidthInTiles();
                        int sizeY = gameObject.GetHeightInTiles();

                        for (int i = 0; i < sizeY; i++)
                        {
                            for (int j = 0; j < sizeX; j++)
                            {
                                this.GetTile(tileX + j, tileY + i).RefreshPassableFlag();
                            }
                        }

                        if (!gameObject.IsPassable())
                        {
                            this.UpdateRoomIndices();
                        }
                    }
                }
            }
        }
コード例 #3
0
        public void RemoveGameObject(LogicGameObject gameObject)
        {
            if (gameObject.IsStaticObject())
            {
                int tileX = gameObject.GetTileX();
                int tileY = gameObject.GetTileY();

                if (tileX >= 0 && tileY >= 0)
                {
                    int sizeX = gameObject.GetWidthInTiles();
                    int sizeY = gameObject.GetHeightInTiles();

                    for (int i = 0; i < sizeY; i++)
                    {
                        for (int j = 0; j < sizeX; j++)
                        {
                            this.m_tiles[(tileX + j) + this.m_sizeX * (tileY + i)].RemoveGameObject(gameObject);
                        }
                    }

                    if (!gameObject.IsPassable())
                    {
                        this.UpdateRoomIndices();
                    }
                }
            }
        }
コード例 #4
0
        /// <summary>
        ///     Called when the specified gameobject has been moved.
        /// </summary>
        public void GameObjectMoved(LogicGameObject gameObject, int oldTileX, int oldTileY)
        {
            if (gameObject.IsStaticObject())
            {
                int tileX = gameObject.GetTileX();
                int tileY = gameObject.GetTileY();

                if (tileX >= 0)
                {
                    if (tileY >= 0)
                    {
                        int sizeX = gameObject.GetWidthInTiles();
                        int sizeY = gameObject.GetHeightInTiles();

                        for (int i = 0; i < sizeY; i++)
                        {
                            for (int j = 0; j < sizeX; j++)
                            {
                                this.GetTile(oldTileX + j, oldTileY + i).RemoveGameObject(gameObject);
                                this.GetTile(tileX + j, tileY + i).AddGameObject(gameObject);
                            }
                        }

                        if (!gameObject.IsPassable())
                        {
                            this.UpdateRoomIndices();
                        }
                    }
                }
            }
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
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);
        }
コード例 #7
0
        public override int Execute(LogicLevel level)
        {
            if (this.m_layoutId != 6)
            {
                if (this.m_layoutId != 7)
                {
                    LogicGameObjectFilter            filter      = new LogicGameObjectFilter();
                    LogicArrayList <LogicGameObject> gameObjects = new LogicArrayList <LogicGameObject>(500);

                    int moved = 0;

                    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   = gameObjects[i].GetPositionLayout(this.m_layoutId, true);

                        int x = position.m_x;
                        int y = position.m_y;

                        if (x != -1 && y != -1)
                        {
                            int tmp1 = x + gameObject.GetWidthInTiles();
                            int tmp2 = y + gameObject.GetHeightInTiles();

                            for (int j = 0; j < gameObjects.Size(); j++)
                            {
                                LogicGameObject tmp = gameObjects[j];

                                if (tmp != gameObject)
                                {
                                    LogicVector2 position2 = tmp.GetPositionLayout(this.m_layoutId, true);

                                    int x2 = position2.m_x;
                                    int y2 = position2.m_y;

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

                                        if (tmp1 > x2 && tmp2 > y2 && x < tmp3 && y < tmp4)
                                        {
                                            Debugger.Warning("LogicSaveBaseLayoutCommand: overlap");
                                            return(-1);
                                        }
                                    }
                                }
                            }
                        }
                    }

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

                        if (gameObject.GetGameObjectType() != LogicGameObjectType.DECO)
                        {
                            if (layoutPosition.m_x != editModePosition.m_x || layoutPosition.m_y != editModePosition.m_y)
                            {
                                ++moved;
                            }
                        }

                        gameObject.SetPositionLayoutXY(editModePosition.m_x, editModePosition.m_y, this.m_layoutId, false);
                    }

                    filter.Destruct();

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

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

                    return(0);
                }

                return(-11);
            }

            return(10);
        }
コード例 #8
0
        public override int Execute(LogicLevel level)
        {
            LogicRect playArea = level.GetPlayArea();
            LogicArrayList <LogicGameObject> gameObjects   = new LogicArrayList <LogicGameObject>();
            LogicArrayList <LogicGameObject> staticObjects = new LogicArrayList <LogicGameObject>();
            LogicGameObjectFilter            filter        = new LogicGameObjectFilter();

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

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

            staticObjects.AddAll(obstacles);

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

                if (building.IsLocked())
                {
                    filter.AddIgnoreObject(building);
                    staticObjects.Add(building);
                }
            }

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

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

                if (editModePosition.m_x != -1 && editModePosition.m_y != -1)
                {
                    int newX   = editModePosition.m_x + this.m_x;
                    int newY   = editModePosition.m_y + this.m_y;
                    int width  = gameObject.GetWidthInTiles();
                    int height = gameObject.GetHeightInTiles();

                    if (newX < playArea.GetStartX() ||
                        newY < playArea.GetStartY() ||
                        newX + width > playArea.GetEndX() ||
                        newY + height > playArea.GetEndY())
                    {
                        return(-1);
                    }

                    if (this.m_layoutId <= 3 && this.m_layoutId != 1)
                    {
                        for (int j = 0; j < staticObjects.Size(); j++)
                        {
                            LogicGameObject staticObject = staticObjects[j];

                            if (staticObject != gameObject)
                            {
                                int staticX      = staticObject.GetTileX();
                                int staticY      = staticObject.GetTileY();
                                int staticWidth  = staticObject.GetWidthInTiles();
                                int staticHeight = staticObject.GetHeightInTiles();

                                if (staticX != -1 && staticY != -1)
                                {
                                    if (newX + width > staticX &&
                                        newY + height > staticY &&
                                        newX < staticX + staticWidth &&
                                        newY < staticY + staticHeight)
                                    {
                                        return(-1);
                                    }
                                }
                            }
                        }
                    }
                }
            }

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

                if (editModePosition.m_x != -1 && editModePosition.m_y != -1)
                {
                    gameObject.SetPositionLayoutXY(editModePosition.m_x + this.m_x, editModePosition.m_y + this.m_y, this.m_layoutId, true);
                }
            }

            filter.Destruct();

            return(0);
        }
        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);
        }
コード例 #10
0
        public override int Execute(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseSwapBuildings())
            {
                if (this.m_gameObject1 != this.m_gameObject2)
                {
                    LogicGameObject gameObject1 = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObject1);
                    LogicGameObject gameObject2 = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObject2);

                    if (gameObject1 != null)
                    {
                        if (gameObject2 != null)
                        {
                            LogicGameObjectType gameObjectType1 = gameObject1.GetGameObjectType();

                            if (gameObjectType1 == LogicGameObjectType.BUILDING || gameObjectType1 == LogicGameObjectType.TRAP ||
                                gameObjectType1 == LogicGameObjectType.DECO)
                            {
                                LogicGameObjectType gameObjectType2 = gameObject2.GetGameObjectType();

                                if (gameObjectType2 == LogicGameObjectType.BUILDING || gameObjectType2 == LogicGameObjectType.TRAP ||
                                    gameObjectType2 == LogicGameObjectType.DECO)
                                {
                                    int width1  = gameObject1.GetWidthInTiles();
                                    int width2  = gameObject2.GetWidthInTiles();
                                    int height1 = gameObject1.GetHeightInTiles();
                                    int height2 = gameObject2.GetHeightInTiles();

                                    if (width1 == width2 && height1 == height2)
                                    {
                                        if (gameObject1.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                        {
                                            LogicBuilding building = (LogicBuilding)gameObject1;

                                            if (building.IsLocked())
                                            {
                                                return(-6);
                                            }

                                            if (building.IsWall())
                                            {
                                                return(-7);
                                            }
                                        }

                                        if (gameObject2.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                        {
                                            LogicBuilding building = (LogicBuilding)gameObject2;

                                            if (building.IsLocked())
                                            {
                                                return(-8);
                                            }

                                            if (building.IsWall())
                                            {
                                                return(-9);
                                            }
                                        }

                                        int x1 = gameObject1.GetX();
                                        int y1 = gameObject1.GetY();
                                        int x2 = gameObject2.GetX();
                                        int y2 = gameObject2.GetY();

                                        gameObject1.SetPositionXY(x2, y2);
                                        gameObject2.SetPositionXY(x1, y1);

                                        return(0);
                                    }

                                    return(-5);
                                }

                                return(-4);
                            }

                            return(-3);
                        }

                        return(-2);
                    }

                    return(-1);
                }

                return(-98);
            }

            return(-99);
        }
コード例 #11
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);
        }
コード例 #12
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);
        }
コード例 #13
0
        public override int Execute(LogicLevel level)
        {
            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)
                {
                    if (gameObjectType != LogicGameObjectType.BUILDING || ((LogicBuildingData)gameObject.GetData()).GetVillageType() == level.GetVillageType())
                    {
                        if (gameObjectType == LogicGameObjectType.BUILDING)
                        {
                            if (((LogicBuilding)gameObject).GetWallIndex() != 0)
                            {
                                return(-21);
                            }
                        }

                        int x      = gameObject.GetTileX();
                        int y      = gameObject.GetTileY();
                        int width  = gameObject.GetWidthInTiles();
                        int height = gameObject.GetHeightInTiles();

                        for (int i = 0; i < width; i++)
                        {
                            for (int j = 0; j < height; j++)
                            {
                                LogicObstacle tallGrass = level.GetTileMap().GetTile(this.m_x + i, this.m_y + j).GetTallGrass();

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

                        if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, width, height, gameObject))
                        {
                            gameObject.SetPositionXY(this.m_x << 9, this.m_y << 9);

                            if (this.m_x != x || this.m_y != y)
                            {
                                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                                if (homeOwnerAvatar != null)
                                {
                                    if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetChallengeBaseCooldownEnabledTownHall() &&
                                        gameObject.GetGameObjectType() != LogicGameObjectType.DECO)
                                    {
                                        level.SetLayoutCooldownSecs(level.GetActiveLayout(level.GetVillageType()), LogicDataTables.GetGlobals().GetChallengeBaseSaveCooldown());
                                    }
                                }
                            }

                            return(0);
                        }

                        return(-3);
                    }

                    return(-32);
                }

                return(-1);
            }

            return(-2);
        }
コード例 #14
0
        public void CreatePatrolArea(LogicGameObject patrolPost, LogicLevel level, bool unk, int idx)
        {
            LogicArrayList <LogicVector2> wayPoints = new LogicArrayList <LogicVector2>(8);

            if (this.m_patrolPost == null)
            {
                this.m_patrolPost = patrolPost;
            }

            int startX = 0;
            int startY = 0;
            int endX   = 0;
            int endY   = 0;
            int midX   = 0;
            int midY   = 0;

            int width  = 0;
            int height = 0;

            int radius = 0;

            if (patrolPost != null)
            {
                startX = patrolPost.GetX() - 128;
                startY = patrolPost.GetY() - 128;
                endX   = patrolPost.GetX() + (patrolPost.GetWidthInTiles() << 9) + 128;
                endY   = patrolPost.GetY() + (patrolPost.GetHeightInTiles() << 9) + 128;
                midX   = patrolPost.GetMidX();
                midY   = patrolPost.GetMidY();
                width  = patrolPost.GetWidthInTiles() << 8;
                height = patrolPost.GetHeightInTiles() << 8;
                radius = 1536;
            }

            if (radius * radius >= (uint)(width * width + height * height))
            {
                LogicVector2 tmp1 = new LogicVector2();
                LogicVector2 tmp2 = new LogicVector2();
                LogicVector2 tmp3 = new LogicVector2();
                LogicVector2 tmp4 = new LogicVector2();

                tmp2.Set(midX, midY);

                int rnd = patrolPost.GetLevel().GetLogicTime().GetTick() + idx;

                midX = midX + 127 * rnd % 1024 - 512;
                midY = midY + 271 * rnd % 1024 - 512;

                for (int i = 0, j = 45; i < 4; i++, j += 90)
                {
                    tmp1.Set(midX + LogicMath.Cos(j, radius), midY + LogicMath.Sin(j, radius));
                    LogicHeroBaseComponent.FindPoint(patrolPost.GetLevel().GetTileMap(), tmp3, tmp2, tmp1, tmp4);
                    wayPoints.Add(new LogicVector2(tmp4.m_x, tmp4.m_y));
                }

                tmp1.Destruct();
                tmp2.Destruct();
                tmp3.Destruct();
                tmp4.Destruct();
            }
            else
            {
                wayPoints.Add(new LogicVector2(endX, endY));
                wayPoints.Add(new LogicVector2(startX, endY));
                wayPoints.Add(new LogicVector2(startX, startY));
                wayPoints.Add(new LogicVector2(endX, startY));
            }

            this.ClearPatrolArea();

            this.m_wayPoints         = wayPoints;
            this.m_patrolAreaCounter = 0;

            if (this.m_wayPoints.Size() > 1)
            {
                int closestLength = 0x7FFFFFFF;

                for (int i = 1, size = this.m_wayPoints.Size(); i < size; i++)
                {
                    LogicVector2 wayPoint = this.m_wayPoints[i];

                    int length = (wayPoint.m_x - (this.m_position.m_x >> 16)) * (wayPoint.m_x - (this.m_position.m_x >> 16)) +
                                 (wayPoint.m_y - (this.m_position.m_y >> 16)) * (wayPoint.m_y - (this.m_position.m_y >> 16));

                    if (length < closestLength)
                    {
                        this.m_patrolAreaCounter = i;
                        closestLength            = length;
                    }
                }
            }

            this.MoveTo(this.m_wayPoints[this.m_patrolAreaCounter].m_x, this.m_wayPoints[this.m_patrolAreaCounter].m_y, level.GetTileMap(), true);
        }
コード例 #15
0
        public static LogicClientHome GenerateBase(LogicGameObjectData gameObjectData)
        {
            LogicClientHome        logicClientHome        = new LogicClientHome();
            LogicGameMode          logicGameMode          = new LogicGameMode();
            LogicLevel             logicLevel             = logicGameMode.GetLevel();
            LogicGameObjectManager logicGameObjectManager = logicLevel.GetGameObjectManagerAt(0);

            logicLevel.SetLoadingVillageType(-1);
            logicLevel.SetVillageType(0);
            logicLevel.SetExperienceVersion(1);
            logicLevel.SetHomeOwnerAvatar(GameBaseGenerator.HomeOwnerAvatar);

            LogicBuilding townHall = new LogicBuilding(LogicDataTables.GetTownHallData(), logicLevel, 0);

            townHall.SetInitialPosition((LogicLevel.TILEMAP_SIZE_X / 2 - townHall.GetWidthInTiles() / 2) << 9, (LogicLevel.TILEMAP_SIZE_Y / 2 - townHall.GetHeightInTiles() / 2) << 9);
            townHall.SetUpgradeLevel(townHall.GetBuildingData().GetUpgradeLevelCount() - 1);

            logicGameObjectManager.AddGameObject(townHall, -1);

            LogicTownhallLevelData townhallLevelData = LogicDataTables.GetTownHallLevel(townHall.GetUpgradeLevel());

            if (gameObjectData == null)
            {
                LogicArrayList <LogicGameObject> scrambler = new LogicArrayList <LogicGameObject>();

                for (int i = 0; i < GameBaseGenerator.m_defenseBuildingArray.Size(); i++)
                {
                    LogicBuildingData buildingData = GameBaseGenerator.m_defenseBuildingArray[i];

                    for (int j = townhallLevelData.GetUnlockedBuildingCount(buildingData); j > 0; j--)
                    {
                        LogicBuilding logicBuilding =
                            (LogicBuilding)GameBaseGenerator.CreateAndPlaceRandomlyGameObject(buildingData, logicLevel, buildingData.GetWidth(), buildingData.GetHeight(), 0);

                        if (logicBuilding != null)
                        {
                            logicBuilding.SetLocked(false);
                            logicBuilding.SetUpgradeLevel(buildingData.GetUpgradeLevelCount() - 1);
                            scrambler.Add(logicBuilding);

                            int upgradeLevel             = buildingData.GetUpgradeLevelCount() - 1;
                            int minUpgradeLevelForGearUp = buildingData.GetMinUpgradeLevelForGearUp();

                            if (minUpgradeLevelForGearUp > -1 && upgradeLevel >= minUpgradeLevelForGearUp)
                            {
                                if (GameBaseGenerator.m_random.Rand(100) >= 50)
                                {
                                    logicBuilding.SetGearLevel(1);
                                }
                            }

                            if (buildingData.GetAttackerItemData(upgradeLevel).GetTargetingConeAngle() != 0)
                            {
                                logicBuilding.GetCombatComponent().ToggleAimAngle(buildingData.GetAimRotateStep() * GameBaseGenerator.m_random.Rand(360 / buildingData.GetAimRotateStep()), 0, false);
                            }

                            if (buildingData.GetAttackerItemData(upgradeLevel).HasAlternativeAttackMode())
                            {
                                if (minUpgradeLevelForGearUp > -1 && logicBuilding.GetGearLevel() != 1)
                                {
                                    continue;
                                }
                                if (GameBaseGenerator.m_random.Rand(100) >= 50)
                                {
                                    logicBuilding.GetCombatComponent().ToggleAttackMode(0, false);
                                }
                            }
                        }
                    }
                }

                for (int i = 0; i < GameBaseGenerator.m_otherBuildingArray.Size(); i++)
                {
                    LogicBuildingData buildingData = GameBaseGenerator.m_otherBuildingArray[i];

                    for (int j = townhallLevelData.GetUnlockedBuildingCount(buildingData); j > 0; j--)
                    {
                        LogicBuilding logicBuilding =
                            (LogicBuilding)GameBaseGenerator.CreateAndPlaceRandomlyGameObject(buildingData, logicLevel, buildingData.GetWidth(), buildingData.GetHeight(), 0);

                        if (logicBuilding != null)
                        {
                            logicBuilding.SetLocked(false);
                            logicBuilding.SetUpgradeLevel(buildingData.GetUpgradeLevelCount() - 1);
                            scrambler.Add(logicBuilding);
                        }
                    }
                }

                for (int i = 0; i < GameBaseGenerator.m_trapArray.Size(); i++)
                {
                    LogicTrapData trapData = (LogicTrapData)GameBaseGenerator.m_trapArray[i];

                    for (int j = townhallLevelData.GetUnlockedTrapCount(trapData); j > 0; j--)
                    {
                        LogicTrap trap = (LogicTrap)GameBaseGenerator.CreateAndPlaceRandomlyGameObject(trapData, logicLevel, trapData.GetWidth(), trapData.GetHeight(), 0);

                        if (trap != null)
                        {
                            trap.SetUpgradeLevel(trapData.GetUpgradeLevelCount() - 1);
                            scrambler.Add(trap);
                        }
                    }
                }

                for (int i = 0; i < scrambler.Size(); i++)
                {
                    LogicGameObject gameObject = scrambler[i];
                    LogicData       data       = gameObject.GetData();

                    int width  = gameObject.GetWidthInTiles();
                    int height = gameObject.GetHeightInTiles();
                    int x      = gameObject.GetX();
                    int y      = gameObject.GetY();

                    LogicArrayList <LogicGameObject> available = new LogicArrayList <LogicGameObject>();

                    for (int j = i + 1; j < scrambler.Size(); j++)
                    {
                        if (data != scrambler[j].GetData())
                        {
                            if (scrambler[j].GetWidthInTiles() == width && scrambler[j].GetHeightInTiles() == height)
                            {
                                available.Add(scrambler[j]);
                            }
                        }
                    }

                    if (available.Size() != 0)
                    {
                        LogicGameObject swapObj = available[GameBaseGenerator.m_random.Rand(available.Size())];

                        gameObject.SetInitialPosition(swapObj.GetX(), swapObj.GetY());
                        swapObj.SetInitialPosition(x, y);
                    }
                }
            }
            else
            {
                int maxUpgradeLevel = 0;
                int width           = 1;
                int height          = 1;

                switch (gameObjectData.GetDataType())
                {
                case LogicDataType.BUILDING:
                {
                    LogicBuildingData logicBuildingData = (LogicBuildingData)gameObjectData;
                    maxUpgradeLevel = logicBuildingData.GetUpgradeLevelCount();
                    width           = logicBuildingData.GetWidth();
                    height          = logicBuildingData.GetHeight();
                    break;
                }

                case LogicDataType.TRAP:
                    LogicTrapData logicTrapData = (LogicTrapData)gameObjectData;
                    maxUpgradeLevel = logicTrapData.GetUpgradeLevelCount();
                    width           = logicTrapData.GetWidth();
                    height          = logicTrapData.GetHeight();
                    break;
                }

                int upgLevel = maxUpgradeLevel - 1;
                int x        = 0;
                int y        = 0;

                while (true)
                {
                    LogicBuilding building =
                        (LogicBuilding)GameBaseGenerator.CreateGameObjectIfAnyPlaceExist(gameObjectData, logicLevel, width, height, 0, x, y);

                    if (building == null)
                    {
                        break;
                    }

                    building.SetLocked(false);
                    building.SetUpgradeLevel(upgLevel != -1 ? upgLevel : GameBaseGenerator.m_random.Rand(building.GetUpgradeLevel()));
                    x = building.GetTileX();
                    y = building.GetTileY();
                }
            }

            for (int i = 0; i < 10; i++)
            {
                logicGameObjectManager.Village1CreateObstacle();
            }

            LogicJSONObject jsonObject = new LogicJSONObject();

            logicGameMode.SaveToJSON(jsonObject);
            logicGameMode.Destruct();

            logicClientHome.SetHomeJSON(LogicJSONParser.CreateJSONString(jsonObject, 2048));

            CompressibleStringHelper.Compress(logicClientHome.GetCompressibleHomeJSON());

            return(logicClientHome);
        }