private static LogicGameObject CreateGameObjectIfAnyPlaceExist(LogicGameObjectData data, LogicLevel level, int width, int height, int villageType, int x = 0, int y = 0) { int levelEndX = level.GetPlayArea().GetEndX(); int levelEndY = level.GetPlayArea().GetEndY(); if (x == 0 && y == 0) { x = level.GetPlayArea().GetStartX(); y = level.GetPlayArea().GetStartY(); } while (true) { if (level.IsValidPlaceForBuilding(x, y, width, height, null)) { LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, level, villageType); gameObject.SetInitialPosition(x << 9, y << 9); level.GetGameObjectManagerAt(villageType).AddGameObject(gameObject, -1); return(gameObject); } if (++x + width > levelEndX) { if (++y + height > levelEndY) { break; } x = level.GetPlayArea().GetStartX(); } } return(null); }
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); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { int villageType = level.GetVillageType(); if (this._buildingData.GetVillageType() == villageType) { if (this._buildingData.GetBuildingClass().CanBuy) { if (level.IsValidPlaceForBuilding(this._x, this._y, this._buildingData.GetWidth(), this._buildingData.GetHeight(), null)) { if (!level.IsBuildingCapReached(this._buildingData, true)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData buildResourceData = this._buildingData.GetBuildResource(0); int buildResourceCost = this._buildingData.GetBuildCost(0, level); if (playerAvatar.HasEnoughResources(buildResourceData, buildResourceCost, true, this, false)) { if (this._buildingData.IsWorkerBuilding() || this._buildingData.GetConstructionTime(0, level, 0) <= 0 && !LogicDataTables.GetGlobals().WorkerForZeroBuilTime() || level.HasFreeWorkers(this, -1)) { if (buildResourceData.PremiumCurrency) { playerAvatar.UseDiamonds(buildResourceCost); } else { playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildResourceCost); } LogicBuilding building = (LogicBuilding)LogicGameObjectFactory.CreateGameObject(this._buildingData, level, villageType); building.SetPositionXY(this._x << 9, this._y << 9); level.GetGameObjectManager().AddGameObject(building, -1); building.StartConstructing(false); if (this._buildingData.IsWall() && level.IsBuildingCapReached(this._buildingData, false)) { level.GetGameListener().BuildingCapReached(this._buildingData); } } } return(0); } } } return(-33); } return(-32); }
private static LogicGameObject CreateAndPlaceRandomlyGameObject(LogicGameObjectData data, LogicLevel level, int width, int height, int villageType) { int levelEndX = level.GetPlayArea().GetEndX(); int levelEndY = level.GetPlayArea().GetEndY(); int midX = levelEndX / 2; int midY = levelEndY / 2; int passCount = 1; while (true) { int startX = LogicMath.Max(midX - passCount, 0); int startY = LogicMath.Max(midY - passCount, 0); int endX = LogicMath.Min(midX + passCount, levelEndX); int endY = LogicMath.Min(midY + passCount, levelEndY); int possibility = LogicMath.Min((endX - startX) * (endY - startY), 20); for (int i = 0; i < possibility; i++) { int x = startX + GameBaseGenerator.m_random.Rand(endX - startX); int y = startY + GameBaseGenerator.m_random.Rand(endY - startY); if (level.IsValidPlaceForBuilding(x, y, width, height, null)) { LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, level, villageType); gameObject.SetInitialPosition(x << 9, y << 9); level.GetGameObjectManagerAt(villageType).AddGameObject(gameObject, -1); return(gameObject); } } if (startX == 0 && startY == 0) { return(null); } passCount += 2; } }
/// <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) { 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); }
public override int Execute(LogicLevel level) { if (this.m_gameObjectData != null && level.GetUnplacedObjectCount(this.m_gameObjectData) > 0) { if (level.GetVillageType() == this.m_gameObjectData.GetVillageType()) { LogicDataType dataType = this.m_gameObjectData.GetDataType(); if (dataType == LogicDataType.BUILDING) { LogicBuildingData buildingData = (LogicBuildingData)this.m_gameObjectData; if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, buildingData.GetWidth(), buildingData.GetHeight(), null)) { if (!level.RemoveUnplacedObject(this.m_gameObjectData, this.m_upgradeLevel)) { return(-63); } LogicBuilding building = (LogicBuilding)LogicGameObjectFactory.CreateGameObject(this.m_gameObjectData, level, level.GetVillageType()); building.SetPositionXY(this.m_x << 9, this.m_y << 9); level.GetGameObjectManager().AddGameObject(building, -1); building.FinishConstruction(false, true); building.SetUpgradeLevel(this.m_upgradeLevel); } return(0); } if (dataType == LogicDataType.TRAP) { LogicTrapData trapData = (LogicTrapData)this.m_gameObjectData; if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, trapData.GetWidth(), trapData.GetHeight(), null)) { if (!level.RemoveUnplacedObject(this.m_gameObjectData, this.m_upgradeLevel)) { return(-64); } LogicTrap trap = (LogicTrap)LogicGameObjectFactory.CreateGameObject(this.m_gameObjectData, level, level.GetVillageType()); trap.SetPositionXY(this.m_x << 9, this.m_y << 9); trap.FinishConstruction(false); trap.SetUpgradeLevel(this.m_upgradeLevel); level.GetGameObjectManager().AddGameObject(trap, -1); } return(0); } if (dataType == LogicDataType.DECO) { LogicDecoData decoData = (LogicDecoData)this.m_gameObjectData; if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, decoData.GetWidth(), decoData.GetHeight(), null)) { if (!level.RemoveUnplacedObject(this.m_gameObjectData, this.m_upgradeLevel)) { return(-65); } LogicDeco deco = (LogicDeco)LogicGameObjectFactory.CreateGameObject(this.m_gameObjectData, level, level.GetVillageType()); deco.SetPositionXY(this.m_x << 9, this.m_y << 9); level.RemoveUnplacedObject(this.m_gameObjectData, this.m_upgradeLevel); level.GetGameObjectManager().AddGameObject(deco, -1); } return(0); } return(-3); } return(-35); } return(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); }
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); }