示例#1
0
        public override int Execute(LogicLevel level)
        {
            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId);

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

                    if (!LogicDataTables.GetGlobals().AllowCancelBuildingConstruction() &&
                        building.GetUpgradeLevel() == 0 &&
                        building.IsConstructing())
                    {
                        if (!building.IsUpgrading())
                        {
                            return(-2);
                        }
                    }

                    if (building.IsConstructing())
                    {
                        building.GetListener().CancelNotification();
                        building.CancelConstruction();

                        return(0);
                    }
                }
                else if (gameObject.GetGameObjectType() == LogicGameObjectType.OBSTACLE)
                {
                    LogicObstacle obstacle = (LogicObstacle)gameObject;

                    if (obstacle.IsClearingOnGoing())
                    {
                        LogicObstacleData data         = obstacle.GetObstacleData();
                        LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                        playerAvatar.CommodityCountChangeHelper(0, data.GetClearResourceData(), data.GetClearCost());
                        obstacle.CancelClearing();

                        return(0);
                    }
                }
                else if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP)
                {
                    LogicTrap trap = (LogicTrap)gameObject;

                    if (trap.IsConstructing())
                    {
                        trap.GetListener().CancelNotification();
                        trap.CancelConstruction();

                        return(0);
                    }
                }
            }

            return(-1);
        }
示例#2
0
        public override int Execute(LogicLevel level)
        {
            if (this.m_decoData != null)
            {
                if (this.m_decoData.GetVillageType() == level.GetVillageType())
                {
                    if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, this.m_decoData.GetWidth(), this.m_decoData.GetHeight(), null))
                    {
                        LogicClientAvatar playerAvatar      = level.GetPlayerAvatar();
                        LogicResourceData buildResourceData = this.m_decoData.GetBuildResource();

                        int buildCost = this.m_decoData.GetBuildCost();

                        if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false) && !level.IsDecoCapReached(this.m_decoData, true))
                        {
                            if (buildResourceData.IsPremiumCurrency())
                            {
                                playerAvatar.UseDiamonds(buildCost);
                                playerAvatar.GetChangeListener().DiamondPurchaseMade(1, this.m_decoData.GetGlobalID(), 0, buildCost, level.GetVillageType());
                            }
                            else
                            {
                                playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                            }

                            LogicDeco deco = (LogicDeco)LogicGameObjectFactory.CreateGameObject(this.m_decoData, level, level.GetVillageType());

                            deco.SetInitialPosition(this.m_x << 9, this.m_y << 9);
                            level.GetGameObjectManager().AddGameObject(deco, -1);

                            int width  = deco.GetWidthInTiles();
                            int height = deco.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);
                                    }
                                }
                            }

                            return(0);
                        }
                    }

                    return(-1);
                }

                return(-32);
            }

            return(-1);
        }
示例#3
0
        public bool FinishTaskOfOneWorker()
        {
            LogicGameObject gameObject = this.GetShortestTaskGO();

            if (gameObject != null)
            {
                switch (gameObject.GetGameObjectType())
                {
                case LogicGameObjectType.BUILDING:
                    LogicBuilding building = (LogicBuilding)gameObject;

                    if (building.IsConstructing())
                    {
                        return(building.SpeedUpConstruction());
                    }

                    if (building.GetHeroBaseComponent() != null)
                    {
                        return(building.GetHeroBaseComponent().SpeedUp());
                    }

                    break;

                case LogicGameObjectType.OBSTACLE:
                    LogicObstacle obstacle = (LogicObstacle)gameObject;

                    if (obstacle.IsClearingOnGoing())
                    {
                        return(obstacle.SpeedUpClearing());
                    }

                    break;

                case LogicGameObjectType.TRAP:
                    LogicTrap trap = (LogicTrap)gameObject;

                    if (trap.IsConstructing())
                    {
                        return(trap.SpeedUpConstruction());
                    }

                    break;

                case LogicGameObjectType.VILLAGE_OBJECT:
                    LogicVillageObject villageObject = (LogicVillageObject)gameObject;

                    if (villageObject.IsConstructing())
                    {
                        return(villageObject.SpeedUpCostruction());
                    }

                    break;
                }
            }

            return(false);
        }
示例#4
0
        /// <summary>
        ///     Finishes the task of one worker.
        /// </summary>
        public bool FinishTaskOfOneWorker()
        {
            LogicGameObject gameObject = this.GetShortestTaskGO();

            if (gameObject != null)
            {
                switch (gameObject.GetGameObjectType())
                {
                case 0:
                    LogicBuilding building = (LogicBuilding)gameObject;

                    if (building.IsConstructing())
                    {
                        return(building.SpeedUpConstruction());
                    }

                    if (building.GetHeroBaseComponent() != null)
                    {
                        // TODO: Implement LogicHeroBaseComponent::speedUpUpgrade.
                    }

                    break;

                case 3:
                    LogicObstacle obstacle = (LogicObstacle)gameObject;

                    if (obstacle.IsClearingOnGoing())
                    {
                        return(obstacle.SpeedUpClearing());
                    }

                    break;

                case 4:
                    LogicTrap trap = (LogicTrap)gameObject;

                    if (trap.IsConstructing())
                    {
                        return(trap.SpeedUpConstruction());
                    }

                    break;

                case 8:
                    LogicVillageObject villageObject = (LogicVillageObject)gameObject;

                    break;
                }
            }

            return(false);
        }
        public LogicObstacle GetTallGrass()
        {
            for (int i = 0; i < this.m_gameObjects.Size(); i++)
            {
                LogicGameObject gameObject = this.m_gameObjects[i];

                if (gameObject.GetGameObjectType() == LogicGameObjectType.OBSTACLE)
                {
                    LogicObstacle obstacle = (LogicObstacle)this.m_gameObjects[i];

                    if (obstacle.GetObstacleData().IsTallGrass())
                    {
                        return(obstacle);
                    }
                }
            }

            return(null);
        }
示例#6
0
        /// <summary>
        ///     Gets the tall grass object.
        /// </summary>
        public LogicObstacle GetTallGrass()
        {
            for (int i = 0; i < this._gameObjects.Count; i++)
            {
                LogicGameObject gameObject = this._gameObjects[i];

                if (gameObject.GetGameObjectType() == 3)
                {
                    LogicObstacle obstacle = (LogicObstacle)this._gameObjects[i];

                    if (obstacle.GetObstacleData().TallGrass)
                    {
                        return(obstacle);
                    }
                }
            }

            return(null);
        }
        /// <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);
        }
示例#8
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);
        }
示例#9
0
        /// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (this._trapData != null)
            {
                if (this._trapData.GetVillageType() == level.GetVillageType())
                {
                    if (level.IsValidPlaceForBuilding(this._x, this._y, this._trapData.GetWidth(), this._trapData.GetHeight(), null))
                    {
                        LogicClientAvatar playerAvatar      = level.GetPlayerAvatar();
                        LogicResourceData buildResourceData = this._trapData.GetBuildResource();

                        int buildCost = this._trapData.GetBuildCost(0);

                        if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false) && !level.IsTrapCapReached(this._trapData, true))
                        {
                            if (buildResourceData.PremiumCurrency)
                            {
                                playerAvatar.UseDiamonds(buildCost);
                            }
                            else
                            {
                                playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost);
                            }

                            LogicTrap trap = (LogicTrap)LogicGameObjectFactory.CreateGameObject(this._trapData, level, level.GetVillageType());

                            if (this._trapData.GetBuildTime(0) == 0)
                            {
                                trap.FinishConstruction(false);
                            }

                            trap.SetInitialPosition(this._x << 9, this._y << 9);
                            level.GetGameObjectManager().AddGameObject(trap, -1);

                            if (level.IsTrapCapReached(this._trapData, false))
                            {
                                level.GetGameListener().TrapCapReached(this._trapData);
                            }

                            if (trap.GetVillageType() != 0)
                            {
                                int x      = trap.GetTileX();
                                int y      = trap.GetTileY();
                                int width  = trap.GetWidthInTiles();
                                int height = trap.GetHeightInTiles();

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

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

                            return(0);
                        }
                    }

                    return(-1);
                }

                return(-32);
            }

            return(-1);
        }
        public override int Execute(LogicLevel level)
        {
            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId);

            if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.OBSTACLE)
            {
                LogicObstacle obstacle = (LogicObstacle)gameObject;

                if (obstacle.GetObstacleData().GetVillageType() == level.GetVillageType())
                {
                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                    if (obstacle.CanStartClearing())
                    {
                        LogicObstacleData obstacleData = obstacle.GetObstacleData();

                        if (obstacle.GetVillageType() == 1)
                        {
                            int village2TownHallLevel = playerAvatar.GetVillage2TownHallLevel();

                            if (village2TownHallLevel < LogicDataTables.GetGlobals().GetMinVillage2TownHallLevelForDestructObstacle() &&
                                obstacleData.GetClearCost() > 0)
                            {
                                return(0);
                            }
                        }

                        LogicResourceData clearResourceData = obstacleData.GetClearResourceData();
                        int clearCost = obstacleData.GetClearCost();

                        if (playerAvatar.HasEnoughResources(clearResourceData, clearCost, true, this, false))
                        {
                            if (obstacleData.GetClearTime() == 0 || level.HasFreeWorkers(this, -1))
                            {
                                playerAvatar.CommodityCountChangeHelper(0, clearResourceData, -clearCost);
                                obstacle.StartClearing();

                                if (obstacle.IsTombstone())
                                {
                                    int tombGroup = obstacle.GetTombGroup();

                                    if (tombGroup != 2)
                                    {
                                        LogicArrayList <LogicGameObject> gameObjects = level.GetGameObjectManager().GetGameObjects(LogicGameObjectType.OBSTACLE);

                                        for (int i = 0; i < gameObjects.Size(); i++)
                                        {
                                            LogicObstacle go = (LogicObstacle)gameObjects[i];

                                            if (go.IsTombstone() && go.GetTombGroup() == tombGroup)
                                            {
                                                go.StartClearing();
                                            }
                                        }
                                    }
                                }
                            }

                            return(0);
                        }
                    }

                    return(-1);
                }

                return(-32);
            }

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

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

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

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

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

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

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

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

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

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

                                    bool success = true;

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

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

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

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

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

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

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

                                                ++wallBlockCnt;
                                            }
                                        }
                                    }

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

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

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

                            LogicGameObject gameObject = gameObjects[i];

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

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

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

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

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

                            LogicGameObject gameObject = gameObjects[i];

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

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

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

                            LogicGameObject gameObject = gameObjects[i];

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

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

                            LogicGameObject gameObject = gameObjects[i];

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

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

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

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

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

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

                return(-1);
            }

            return(-92);
        }
示例#12
0
        /// <summary>
        ///     Gets the shortest task.
        /// </summary>
        public LogicGameObject GetShortestTaskGO()
        {
            LogicGameObject gameObject = null;

            for (int i = 0, minRemaining = -1, tmpRemaining = 0; i < this._constructions.Count; i++, tmpRemaining = 0)
            {
                LogicGameObject tmp = this._constructions[i];

                switch (this._constructions[i].GetGameObjectType())
                {
                case 0:
                    LogicBuilding building = (LogicBuilding)tmp;

                    if (building.IsConstructing())
                    {
                        tmpRemaining = building.GetRemainingConstructionTime();
                    }
                    else
                    {
                        LogicHeroBaseComponent heroBaseComponent = building.GetHeroBaseComponent();

                        if (heroBaseComponent == null)
                        {
                            Debugger.Warning("LogicWorkerManager - Worker allocated to altar/herobase without hero upgrading");
                        }
                        else
                        {
                            if (heroBaseComponent.IsUpgrading())
                            {
                                tmpRemaining = heroBaseComponent.GetRemainingUpgradeSeconds();
                            }
                            else
                            {
                                Debugger.Warning("LogicWorkerManager - Worker allocated to building with remaining construction time 0");
                            }
                        }
                    }

                    break;

                case 3:
                    LogicObstacle obstacle = (LogicObstacle)tmp;

                    if (obstacle.IsClearingOnGoing())
                    {
                        tmpRemaining = obstacle.GetRemainingClearingTime();
                    }
                    else
                    {
                        Debugger.Warning("LogicWorkerManager - Worker allocated to obstacle with remaining clearing time 0");
                    }

                    break;

                case 4:
                    LogicTrap trap = (LogicTrap)tmp;

                    if (trap.IsConstructing())
                    {
                        tmpRemaining = trap.GetRemainingConstructionTime();
                    }
                    else
                    {
                        Debugger.Warning("LogicWorkerManager - Worker allocated to trap with remaining construction time 0");
                    }
                    break;

                case 8:

                    break;
                }

                if (gameObject == null || minRemaining > tmpRemaining)
                {
                    gameObject   = tmp;
                    minRemaining = tmpRemaining;
                }
            }

            return(gameObject);
        }
示例#13
0
        public override int Execute(LogicLevel level)
        {
            int villageType = level.GetVillageType();

            if (this.m_buildingData.GetVillageType() == villageType)
            {
                if (this.m_buildingData.GetWallBlockCount() <= 1 && this.m_buildingData.GetBuildingClass().CanBuy())
                {
                    if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, this.m_buildingData.GetWidth(), this.m_buildingData.GetHeight(), null) &&
                        !level.IsBuildingCapReached(this.m_buildingData, true))
                    {
                        if (level.GetCalendar().IsEnabled(this.m_buildingData))
                        {
                            LogicClientAvatar playerAvatar      = level.GetPlayerAvatar();
                            LogicResourceData buildResourceData = this.m_buildingData.GetBuildResource(0);

                            int buildResourceCost = this.m_buildingData.GetBuildCost(0, level);

                            if (playerAvatar.HasEnoughResources(buildResourceData, buildResourceCost, true, this, false))
                            {
                                if (this.m_buildingData.IsWorkerBuilding() ||
                                    this.m_buildingData.GetConstructionTime(0, level, 0) <= 0 && !LogicDataTables.GetGlobals().WorkerForZeroBuilTime() ||
                                    level.HasFreeWorkers(this, -1))
                                {
                                    if (buildResourceData.IsPremiumCurrency())
                                    {
                                        playerAvatar.UseDiamonds(buildResourceCost);
                                        playerAvatar.GetChangeListener().DiamondPurchaseMade(1, this.m_buildingData.GetGlobalID(), 0, buildResourceCost, villageType);
                                    }
                                    else
                                    {
                                        playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildResourceCost);
                                    }

                                    LogicBuilding building = (LogicBuilding)LogicGameObjectFactory.CreateGameObject(this.m_buildingData, level, villageType);

                                    building.SetInitialPosition(this.m_x << 9, this.m_y << 9);
                                    level.GetGameObjectManager().AddGameObject(building, -1);
                                    building.StartConstructing(false);

                                    if (this.m_buildingData.IsWall() && level.IsBuildingCapReached(this.m_buildingData, false))
                                    {
                                        level.GetGameListener().BuildingCapReached(this.m_buildingData);
                                    }

                                    int width  = building.GetWidthInTiles();
                                    int height = building.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);
                                            }
                                        }
                                    }
                                }
                            }

                            return(0);
                        }
                    }
                }

                return(-33);
            }

            return(-32);
        }
示例#14
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);
        }
示例#15
0
        public void SetBattleOver()
        {
            if (this.m_battleOver)
            {
                return;
            }

            this.m_level.GetBattleLog().SetBattleEnded(LogicDataTables.GetGlobals().GetAttackLengthSecs() - this.GetRemainingAttackSeconds());
            this.m_level.GetMissionManager().Tick();

            LogicArrayList <LogicComponent> components = this.m_level.GetComponentManager().GetComponents(LogicComponentType.COMBAT);

            for (int i = 0; i < components.Size(); i++)
            {
                ((LogicCombatComponent)components[i]).Boost(0, 0, 0);
            }

            bool duelMatch = (this.m_level.GetMatchType() & 0xFFFFFFFE) == 8;

            if (duelMatch)
            {
                LogicAvatar avatar = this.m_level.GetVisitorAvatar();

                if (avatar != null && avatar.IsClientAvatar())
                {
                    ((LogicClientAvatar)avatar).RemoveUnitsVillage2();
                }
            }

            if (this.m_state == 3)
            {
                this.EndDefendState();
            }
            else
            {
                LogicBattleLog battleLog = this.m_level.GetBattleLog();

                if (battleLog.GetBattleStarted())
                {
                    LogicAvatar visitorAvatar   = this.m_level.GetVisitorAvatar();
                    LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

                    int stars = battleLog.GetStars();

                    if (!this.m_level.GetVisitorAvatar().IsClientAvatar() || !this.m_level.GetHomeOwnerAvatar().IsClientAvatar())
                    {
                        if (visitorAvatar.IsClientAvatar() && homeOwnerAvatar.IsNpcAvatar())
                        {
                            LogicNpcAvatar npcAvatar = (LogicNpcAvatar)homeOwnerAvatar;
                            LogicNpcData   npcData   = npcAvatar.GetNpcData();

                            int npcStars = visitorAvatar.GetNpcStars(npcData);

                            if (stars > npcStars && npcData.IsSinglePlayer())
                            {
                                visitorAvatar.SetNpcStars(npcData, stars);
                                visitorAvatar.GetChangeListener().CommodityCountChanged(0, npcData, stars);
                            }

                            // TODO: LogicBattleLog::sendNpcAttackEndEvents.
                        }
                    }
                    else
                    {
                        LogicClientAvatar attacker = (LogicClientAvatar)visitorAvatar;
                        LogicClientAvatar defender = (LogicClientAvatar)homeOwnerAvatar;

                        int originalAttackerScore = attacker.GetScore();
                        int originalDefenderScore = defender.GetScore();
                        int matchType             = this.m_level.GetMatchType();

                        if (matchType == 1 || !LogicDataTables.GetGlobals().ScoringOnlyFromMatchedMode() && (matchType == 0 || matchType == 2 || matchType == 4 || matchType == 6))
                        {
                            LogicGamePlayUtil.CalculateCombatScore(attacker, defender, stars, false,
                                                                   matchType == 4, battleLog.GetDestructionPercentage(), this.m_calendar.GetStarBonusMultiplier(), duelMatch);

                            if (!duelMatch && homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetLootCartEnabledTownHall())
                            {
                                LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE);

                                if (resourceTable.GetItemCount() > 0)
                                {
                                    bool hasStolen = false;

                                    for (int i = 0; i < resourceTable.GetItemCount(); i++)
                                    {
                                        LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i);

                                        if (!data.IsPremiumCurrency())
                                        {
                                            if (battleLog.GetStolenResources(data) > 0)
                                            {
                                                hasStolen = true;
                                            }
                                        }
                                    }

                                    if (hasStolen)
                                    {
                                        LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0);
                                        LogicObstacle          lootCart          = gameObjectManager.GetLootCart();

                                        if (lootCart == null)
                                        {
                                            gameObjectManager.AddLootCart();
                                            lootCart = gameObjectManager.GetLootCart();
                                        }

                                        if (lootCart != null)
                                        {
                                            LogicLootCartComponent lootCartComponent = lootCart.GetLootCartComponent();

                                            if (lootCartComponent != null)
                                            {
                                                for (int i = 0; i < resourceTable.GetItemCount(); i++)
                                                {
                                                    LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i);

                                                    if (!data.IsPremiumCurrency() && data.GetWarResourceReferenceData() == null)
                                                    {
                                                        int lootPercentage = lootCart.GetObstacleData().GetLootDefensePercentage();
                                                        int lootCount      = battleLog.GetStolenResources(data) * lootPercentage / 100;

                                                        lootCartComponent.SetResourceCount(i,
                                                                                           LogicMath.Min(LogicMath.Max(lootCount, lootCartComponent.GetResourceCount(i)),
                                                                                                         lootCartComponent.GetCapacityCount(i)));
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            this.m_level.UpdateBattleShieldStatus(false);

                            if (stars > 0)
                            {
                                LogicArrayList <LogicDataSlot> castedUnits         = battleLog.GetCastedUnits();
                                LogicArrayList <LogicDataSlot> castedSpells        = battleLog.GetCastedSpells();
                                LogicArrayList <LogicUnitSlot> castedAllianceUnits = battleLog.GetCastedAllianceUnits();

                                LogicArrayList <LogicDataSlot> placedUnits = new LogicArrayList <LogicDataSlot>(castedUnits.Size());

                                for (int i = 0; i < castedUnits.Size(); i++)
                                {
                                    placedUnits.Add(new LogicDataSlot(castedUnits[i].GetData(), castedUnits[i].GetCount()));
                                }

                                for (int i = 0; i < castedSpells.Size(); i++)
                                {
                                    int idx = -1;

                                    for (int j = 0; j < placedUnits.Size(); j++)
                                    {
                                        if (placedUnits[j].GetData() == castedSpells[i].GetData())
                                        {
                                            idx = j;
                                            break;
                                        }
                                    }

                                    if (idx != -1)
                                    {
                                        placedUnits[idx].SetCount(placedUnits[idx].GetCount() + castedSpells[i].GetCount());
                                    }
                                    else
                                    {
                                        placedUnits.Add(new LogicDataSlot(castedSpells[i].GetData(), castedSpells[i].GetCount()));
                                    }
                                }

                                for (int i = 0; i < castedAllianceUnits.Size(); i++)
                                {
                                    placedUnits.Add(new LogicDataSlot(castedAllianceUnits[i].GetData(), castedAllianceUnits[i].GetCount()));
                                }

                                for (int i = 0; i < placedUnits.Size(); i++)
                                {
                                    LogicCombatItemData   data = (LogicCombatItemData)placedUnits[i].GetData();
                                    LogicCalendarUseTroop calendarUseTroopEvent = this.m_calendar.GetUseTroopEvents(data);

                                    if (calendarUseTroopEvent != null)
                                    {
                                        int count = attacker.GetEventUnitCounterCount(data);

                                        if (placedUnits[i].GetCount() >= count >> 16)
                                        {
                                            int progressCount = (short)count + 1;
                                            int eventCounter  = progressCount | (int)(count & 0xFFFF0000);

                                            attacker.SetCommodityCount(6, data, eventCounter);
                                            attacker.GetChangeListener().CommodityCountChanged(6, data, eventCounter);

                                            if (calendarUseTroopEvent.GetParameter(0) == progressCount)
                                            {
                                                int diamonds = calendarUseTroopEvent.GetParameter(2);
                                                int xp       = calendarUseTroopEvent.GetParameter(3);

                                                attacker.XpGainHelper(xp);
                                                attacker.SetDiamonds(attacker.GetDiamonds() + diamonds);
                                                attacker.SetFreeDiamonds(attacker.GetFreeDiamonds() + diamonds);
                                                attacker.GetChangeListener().FreeDiamondsAdded(diamonds, 9);

                                                Debugger.HudPrint(string.Format("USE TROOP Event: Awarding XP: {0} GEMS {1}", xp, diamonds));
                                            }
                                        }
                                    }
                                }

                                for (int i = 0; i < placedUnits.Size(); i++)
                                {
                                    placedUnits[i].Destruct();
                                }

                                placedUnits.Destruct();
                            }
                        }

                        if (this.m_state != 5 &&
                            this.m_level.GetDefenseShieldActivatedHours() == 0 &&
                            battleLog.GetDestructionPercentage() > 0)
                        {
                            int defenseVillageGuardCounter = defender.GetDefenseVillageGuardCounter() + 1;

                            defender.SetDefenseVillageGuardCounter(defenseVillageGuardCounter);
                            defender.GetChangeListener().DefenseVillageGuardCounterChanged(defenseVillageGuardCounter);

                            int villageGuardMins = (defenseVillageGuardCounter & 0xFFFFFF) == 3 * ((defenseVillageGuardCounter & 0xFFFFFF) / 3)
                                ? defender.GetLeagueTypeData().GetVillageGuardInMins()
                                : LogicDataTables.GetGlobals().GetDefaultDefenseVillageGuard();

                            this.m_level.GetHome().GetChangeListener().GuardActivated(60 * villageGuardMins);

                            Debugger.HudPrint(string.Format("Battle end. No Shield, Village Guard for defender: {0}", villageGuardMins));
                        }

                        battleLog.SetAttackerScore(attacker.GetScore() - originalAttackerScore);
                        battleLog.SetDefenderScore(defender.GetScore() - originalDefenderScore);
                        battleLog.SetOriginalAttackerScore(originalAttackerScore);
                        battleLog.SetOriginalDefenderScore(originalDefenderScore);

                        if (this.m_state != 5)
                        {
                            if (stars != 0)
                            {
                                if (matchType != 3 && matchType != 7 && matchType != 8 && matchType != 9)
                                {
                                    if (matchType == 5)
                                    {
                                        if (stars > this.m_level.GetPreviousAttackStars() && !this.m_level.GetIgnoreAttack())
                                        {
                                            this.m_level.GetAchievementManager().IncreaseWarStars(stars);
                                        }
                                    }
                                    else
                                    {
                                        this.m_level.GetAchievementManager().PvpAttackWon();
                                    }
                                }
                            }
                            else if (matchType > 9 || matchType == 3 || matchType == 5 || matchType == 7 || matchType == 8 || matchType == 9)
                            {
                                this.m_level.GetAchievementManager().PvpDefenseWon();
                            }
                        }
                    }
                }
            }

            this.m_battleOver = true;
        }
示例#16
0
        public override int Execute(LogicLevel level)
        {
            if (level.GetVillageType() == 1)
            {
                if (this.m_buildingData != null && this.m_buildingData.GetBuildingClass().CanBuy() && this.m_buildingData.IsWall())
                {
                    if (this.m_buildingData.GetWallBlockCount() != 0)
                    {
                        if (this.m_buildingData.GetWallBlockCount() == this.m_position.Size())
                        {
                            if (this.m_position.Size() <= 10)
                            {
                                for (int i = 0, nIdx = -1; i < this.m_position.Size(); i++)
                                {
                                    LogicVector2 firstPosition = this.m_position[0];
                                    LogicVector2 position      = this.m_position[i];

                                    if (i > 0)
                                    {
                                        int shapeIdx = this.m_buildingData.GetWallBlockIndex(position.m_x - firstPosition.m_x, position.m_y - firstPosition.m_y, i);

                                        if (nIdx == -1)
                                        {
                                            nIdx = shapeIdx;
                                        }

                                        if (shapeIdx == -1 || shapeIdx != nIdx)
                                        {
                                            Debugger.Error("LogicBuyWallBlockCommand shape incorrect");
                                            return(-4);
                                        }

                                        nIdx = shapeIdx;
                                    }

                                    if (!level.IsValidPlaceForBuilding(position.m_x, position.m_y, this.m_buildingData.GetWidth(), this.m_buildingData.GetHeight(), null))
                                    {
                                        Debugger.Error("LogicBuyWallBlockCommand invalid place.");
                                        return(-5);
                                    }
                                }

                                if (!level.IsBuildingCapReached(this.m_buildingData, true))
                                {
                                    LogicClientAvatar playerAvatar  = level.GetPlayerAvatar();
                                    LogicResourceData buildResource = this.m_buildingData.GetBuildResource(0);

                                    int buildCost = this.m_buildingData.GetBuildCost(0, level);

                                    if (playerAvatar.HasEnoughResources(buildResource, buildCost, true, this, false))
                                    {
                                        if (this.m_buildingData.IsWorkerBuilding() ||
                                            this.m_buildingData.GetConstructionTime(0, level, 0) <= 0 && !LogicDataTables.GetGlobals().WorkerForZeroBuilTime() ||
                                            level.HasFreeWorkers(this, -1))
                                        {
                                            if (buildResource.IsPremiumCurrency())
                                            {
                                                playerAvatar.UseDiamonds(buildCost);
                                                playerAvatar.GetChangeListener().DiamondPurchaseMade(1, this.m_buildingData.GetGlobalID(), 0, buildCost, level.GetVillageType());
                                            }
                                            else
                                            {
                                                playerAvatar.CommodityCountChangeHelper(0, buildResource, -buildCost);
                                            }

                                            LogicGameObjectManager gameObjectManager = level.GetGameObjectManager();
                                            int wallIndex = gameObjectManager.GetHighestWallIndex(this.m_buildingData);

                                            for (int i = 0; i < this.m_position.Size(); i++)
                                            {
                                                LogicVector2  position = this.m_position[i];
                                                LogicBuilding building =
                                                    (LogicBuilding)LogicGameObjectFactory.CreateGameObject(this.m_buildingData, level, level.GetVillageType());

                                                building.StartConstructing(false);
                                                building.SetInitialPosition(position.m_x << 9, position.m_y << 9);
                                                building.SetWallObjectId(wallIndex, i, i == 0);

                                                gameObjectManager.AddGameObject(building, -1);

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

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

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

                                return(0);
                            }

                            return(-3);
                        }

                        return(-2);
                    }

                    return(-1);
                }

                return(0);
            }

            return(-32);
        }