Ejemplo n.º 1
0
        public LogicBunkerComponent(LogicGameObject gameObject, int capacity) : base(gameObject, capacity)
        {
            this.m_team = 1;

            this.m_filter = new LogicGameObjectFilter();
            this.m_filter.AddGameObjectType(LogicGameObjectType.CHARACTER);
            this.m_filter.PassEnemyOnly(gameObject);
        }
Ejemplo n.º 2
0
        public override int Execute(LogicLevel level)
        {
            if (this.m_layoutId != 6)
            {
                if (this.m_layoutId != 7)
                {
                    if (this.m_state == 0)
                    {
                        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++)
                        {
                            gameObjects[i].SetPositionLayoutXY(-1, -1, this.m_layoutId, true);
                        }

                        filter.Destruct();
                    }

                    level.SetLayoutState(this.m_layoutId, level.GetVillageType(), this.m_state);

                    if (this.m_updateListener)
                    {
                    }

                    return(0);
                }

                return(-11);
            }

            return(-10);
        }
Ejemplo n.º 3
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);
        }
        public override int Execute(LogicLevel level)
        {
            if (this.m_layoutId == 7)
            {
                return(-21);
            }

            if (this.m_village2)
            {
                if (this.m_layoutId != 0 && this.m_layoutId != 2 && this.m_layoutId != 3)
                {
                    return(-22);
                }
            }

            if (LogicDataTables.GetGlobals().UseVersusBattle())
            {
                int villageType = this.m_village2 ? 1 : 0;

                if (level.GetTownHallLevel(villageType) < level.GetRequiredTownHallLevelForLayout(this.m_layoutId, villageType))
                {
                    return(-3);
                }

                if (level.GetPlayerAvatar() == null)
                {
                    return(-10);
                }

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

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

                level.GetGameObjectManagerAt(this.m_village2 ? 1 : 0).GetGameObjects(gameObjects, filter);

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

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

                gameObjects.Destruct();
                filter.Destruct();

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

                    if (homeOwnerAvatar == null || homeOwnerAvatar.IsChallengeStarted())
                    {
                        if (level.GetLayoutCooldown(this.m_layoutId) > 0)
                        {
                            return(-7);
                        }
                    }
                }

                LogicBuilding allianceCastle = level.GetGameObjectManagerAt(0).GetAllianceCastle();

                if (allianceCastle != null)
                {
                    LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent();

                    if (bunkerComponent == null || bunkerComponent.GetChallengeCooldownTime() != 0)
                    {
                        return(-6);
                    }

                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                    if (!this.m_challenge)
                    {
                        if (playerAvatar.GetChallengeId() != null)
                        {
                            int challengeState = playerAvatar.GetChallengeState();

                            if (challengeState != 2 && challengeState != 4)
                            {
                                Debugger.Warning("chal state: " + challengeState);
                                return(-8);
                            }
                        }
                    }

                    int friendlyCost = LogicDataTables.GetGlobals().GetFriendlyBattleCost(playerAvatar.GetTownHallLevel());

                    if (friendlyCost != 0)
                    {
                        if (!playerAvatar.HasEnoughResources(LogicDataTables.GetGoldData(), friendlyCost, true, this, false))
                        {
                            return(0);
                        }

                        if (friendlyCost > 0)
                        {
                            playerAvatar.CommodityCountChangeHelper(0, LogicDataTables.GetGoldData(), friendlyCost);
                        }
                    }

                    bunkerComponent.StartChallengeCooldownTime();

                    bool warLayout = this.m_layoutId == 1 || this.m_layoutId == 4 || this.m_layoutId == 5;

                    if (this.m_village2)
                    {
                        if (this.m_challenge)
                        {
                            playerAvatar.GetChangeListener().SendChallengeRequest(this.m_message, this.m_layoutId, warLayout, villageType);
                        }
                        else
                        {
                            playerAvatar.GetChangeListener().SendFriendlyBattleRequest(this.m_message, this.m_battleId, this.m_layoutId, warLayout, villageType);
                        }
                    }
                    else
                    {
                        this.SaveChallengeLayout(level, warLayout);

                        if (this.m_challenge)
                        {
                            playerAvatar.GetChangeListener().SendChallengeRequest(this.m_message, this.m_layoutId, warLayout, villageType);
                        }
                        else
                        {
                            playerAvatar.GetChangeListener().SendFriendlyBattleRequest(this.m_message, this.m_battleId, this.m_layoutId, warLayout, villageType);
                        }

                        playerAvatar.SetVariableByName("ChallengeStarted", 1);
                    }

                    return(0);
                }

                return(-3);
            }

            return(2);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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)
        {
            if (this.m_inputLayoutId != 6)
            {
                if (this.m_outputLayoutId != 6)
                {
                    if (this.m_inputLayoutId != 7)
                    {
                        if (this.m_outputLayoutId != 7)
                        {
                            int townHallLevel = level.GetTownHallLevel(level.GetVillageType());

                            if (townHallLevel >= level.GetRequiredTownHallLevelForLayout(this.m_inputLayoutId, -1) &&
                                townHallLevel >= level.GetRequiredTownHallLevelForLayout(this.m_outputLayoutId, -1))
                            {
                                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);

                                if (this.m_outputLayoutId == level.GetActiveLayout())
                                {
                                    LogicMoveMultipleBuildingsCommand moveMultipleBuildingsCommand = new LogicMoveMultipleBuildingsCommand();

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

                                        moveMultipleBuildingsCommand.AddNewMove(gameObject.GetGlobalID(), position.m_x, position.m_y);
                                    }

                                    int result = moveMultipleBuildingsCommand.Execute(level);

                                    moveMultipleBuildingsCommand.Destruct();

                                    if (result != 0)
                                    {
                                        filter.Destruct();
                                        return(-2);
                                    }
                                }

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

                                    gameObject.SetPositionLayoutXY(layoutPosition.m_x, layoutPosition.m_y, this.m_outputLayoutId, false);
                                    gameObject.SetPositionLayoutXY(editModePosition.m_x, editModePosition.m_y, this.m_outputLayoutId, true);

                                    if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                    {
                                        LogicCombatComponent combatComponent = gameObject.GetCombatComponent(false);

                                        if (combatComponent != null)
                                        {
                                            if (combatComponent.HasAltAttackMode())
                                            {
                                                if (combatComponent.UseAltAttackMode(this.m_inputLayoutId, false) ^ combatComponent.UseAltAttackMode(this.m_outputLayoutId, false))
                                                {
                                                    combatComponent.ToggleAttackMode(this.m_outputLayoutId, false);
                                                }

                                                if (combatComponent.UseAltAttackMode(this.m_inputLayoutId, true) ^ combatComponent.UseAltAttackMode(this.m_outputLayoutId, true))
                                                {
                                                    combatComponent.ToggleAttackMode(this.m_outputLayoutId, true);
                                                }
                                            }

                                            if (combatComponent.GetAttackerItemData().GetTargetingConeAngle() != 0)
                                            {
                                                int aimAngle1 = combatComponent.GetAimAngle(this.m_inputLayoutId, false);
                                                int aimAngle2 = combatComponent.GetAimAngle(this.m_outputLayoutId, false);

                                                if (aimAngle1 != aimAngle2)
                                                {
                                                    combatComponent.ToggleAimAngle(aimAngle1 - aimAngle2, this.m_outputLayoutId, false);
                                                }
                                            }
                                        }
                                    }
                                    else if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP)
                                    {
                                        LogicTrap trap = (LogicTrap)gameObject;

                                        if (trap.HasAirMode())
                                        {
                                            if (trap.IsAirMode(this.m_inputLayoutId, false) ^ trap.IsAirMode(this.m_outputLayoutId, false))
                                            {
                                                trap.ToggleAirMode(this.m_outputLayoutId, false);
                                            }

                                            if (trap.IsAirMode(this.m_inputLayoutId, true) ^ trap.IsAirMode(this.m_outputLayoutId, true))
                                            {
                                                trap.ToggleAirMode(this.m_outputLayoutId, true);
                                            }
                                        }
                                    }
                                }

                                filter.Destruct();
                                level.SetLayoutState(this.m_outputLayoutId, level.GetVillageType(), level.GetLayoutState(this.m_inputLayoutId, level.GetVillageType()));

                                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                                if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetChallengeBaseCooldownEnabledTownHall())
                                {
                                    level.SetLayoutCooldownSecs(this.m_outputLayoutId, level.GetLayoutCooldown(this.m_inputLayoutId) / 15);
                                }

                                return(0);
                            }

                            return(-1);
                        }

                        return(-8);
                    }

                    return(-7);
                }

                return(-6);
            }

            return(-5);
        }