public override int Execute(LogicLevel level) { if (this.m_villageType <= 1 && level.GetGameObjectManagerAt(this.m_villageType) != null) { LogicGameObject gameObject = level.GetGameObjectManagerAt(this.m_villageType).GetGameObjectByID(this.m_gameObjectId); if (gameObject != null) { LogicGameObjectType gameObjectType = gameObject.GetGameObjectType(); if (gameObjectType == LogicGameObjectType.BUILDING) { return(((LogicBuilding)gameObject).SpeedUpConstruction() ? 0 : -1); } if (gameObjectType == LogicGameObjectType.TRAP) { return(((LogicTrap)gameObject).SpeedUpConstruction() ? 0 : -2); } if (gameObjectType == LogicGameObjectType.VILLAGE_OBJECT) { return(((LogicVillageObject)gameObject).SpeedUpCostruction() ? 0 : -1); } } } return(-3); }
public void AddGameObjectType(LogicGameObjectType type) { if (this.m_gameObjectTypes == null) { this.m_gameObjectTypes = new bool[LogicGameObject.GAMEOBJECT_TYPE_COUNT]; } this.m_gameObjectTypes[(int)type] = true; }
public bool TileOkForSpawn(LogicTile tile) { if (tile != null && !tile.IsFullyNotPassable()) { for (int i = 0; i < tile.GetGameObjectCount(); i++) { LogicGameObjectType gameObjectType = tile.GetGameObject(i).GetGameObjectType(); if (gameObjectType == LogicGameObjectType.BUILDING || gameObjectType == LogicGameObjectType.OBSTACLE || gameObjectType == LogicGameObjectType.TRAP || gameObjectType == LogicGameObjectType.DECO) { return(false); } } return(true); } return(false); }
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); }
public override int Execute(LogicLevel level) { if (LogicDataTables.GetGlobals().UseSwapBuildings()) { if (this.m_gameObject1 != this.m_gameObject2) { LogicGameObject gameObject1 = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObject1); LogicGameObject gameObject2 = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObject2); if (gameObject1 != null) { if (gameObject2 != null) { LogicGameObjectType gameObjectType1 = gameObject1.GetGameObjectType(); if (gameObjectType1 == LogicGameObjectType.BUILDING || gameObjectType1 == LogicGameObjectType.TRAP || gameObjectType1 == LogicGameObjectType.DECO) { LogicGameObjectType gameObjectType2 = gameObject2.GetGameObjectType(); if (gameObjectType2 == LogicGameObjectType.BUILDING || gameObjectType2 == LogicGameObjectType.TRAP || gameObjectType2 == LogicGameObjectType.DECO) { int width1 = gameObject1.GetWidthInTiles(); int width2 = gameObject2.GetWidthInTiles(); int height1 = gameObject1.GetHeightInTiles(); int height2 = gameObject2.GetHeightInTiles(); if (width1 == width2 && height1 == height2) { if (gameObject1.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject1; if (building.IsLocked()) { return(-6); } if (building.IsWall()) { return(-7); } } if (gameObject2.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject2; if (building.IsLocked()) { return(-8); } if (building.IsWall()) { return(-9); } } int x1 = gameObject1.GetX(); int y1 = gameObject1.GetY(); int x2 = gameObject2.GetX(); int y2 = gameObject2.GetY(); gameObject1.SetPositionXY(x2, y2); gameObject2.SetPositionXY(x1, y1); return(0); } return(-5); } return(-4); } return(-3); } return(-2); } return(-1); } return(-98); } return(-99); }
public override int Execute(LogicLevel level) { if (this.m_layoutId != 6) { if (this.m_layoutId != 7) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null) { LogicGameObjectType gameObjectType = gameObject.GetGameObjectType(); if (gameObjectType == LogicGameObjectType.BUILDING || gameObjectType == LogicGameObjectType.TRAP || gameObjectType == LogicGameObjectType.DECO) { LogicRect playArea = level.GetPlayArea(); if (playArea.IsInside(this.m_x, this.m_y) && playArea.IsInside(this.m_x + gameObject.GetWidthInTiles(), this.m_y + gameObject.GetHeightInTiles()) || this.m_x == -1 || this.m_y == -1) { if (gameObjectType == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (building.GetWallIndex() != 0) { return(-23); } } gameObject.SetPositionLayoutXY(this.m_x, this.m_y, this.m_layoutId, true); LogicGlobals globals = LogicDataTables.GetGlobals(); if (!globals.NoCooldownFromMoveEditModeActive()) { if (level.GetActiveLayout(level.GetVillageType()) == this.m_layoutId) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar.GetExpLevel() >= globals.GetChallengeBaseCooldownEnabledTownHall()) { level.SetLayoutCooldownSecs(this.m_layoutId, globals.GetChallengeBaseSaveCooldown()); } } } return(0); } return(-2); // EditModeOutsideMap } return(-1); } return(-3); } return(-6); } return(-5); }
public override int Execute(LogicLevel level) { int count = this.m_gameObjectIds.Size(); if (count > 0) { bool validGameObjects = true; if (this.m_xPositions.Size() == count && this.m_xPositions.Size() == count && count <= 500) { LogicGameObject[] gameObjects = new LogicGameObject[count]; for (int i = 0; i < count; i++) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[i]); if (gameObject != null) { LogicGameObjectType gameObjectType = gameObject.GetGameObjectType(); if (gameObjectType != LogicGameObjectType.BUILDING && gameObjectType != LogicGameObjectType.TRAP && gameObjectType != LogicGameObjectType.DECO) { validGameObjects = false; } gameObjects[i] = gameObject; } else { validGameObjects = false; } } if (validGameObjects) { for (int i = 0; i < count; i++) { LogicGameObject gameObject = gameObjects[i]; if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING && validGameObjects) { LogicBuilding baseWallBlock = (LogicBuilding)gameObject; if (baseWallBlock.GetWallIndex() != 0) { int x = this.m_xPositions[i]; int y = this.m_yPositions[i]; int minX = 0; int minY = 0; int maxX = 0; int maxY = 0; int minWallBlockX = 0; int minWallBlockY = 0; int maxWallBlockX = 0; int maxWallBlockY = 0; int wallBlockCnt = 0; bool success = true; for (int j = 0; j < count; j++) { LogicGameObject obj = gameObjects[j]; if (obj.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding wallBlock = (LogicBuilding)obj; if (wallBlock.GetWallIndex() == baseWallBlock.GetWallIndex()) { int tmp1 = x - this.m_xPositions[j]; int tmp2 = y - this.m_yPositions[j]; if ((x & this.m_xPositions[j]) != -1) { success = false; } minX = LogicMath.Min(minX, tmp1); minY = LogicMath.Min(minY, tmp2); maxX = LogicMath.Max(maxX, tmp1); maxY = LogicMath.Max(maxY, tmp2); int wallBlockX = wallBlock.GetBuildingData().GetWallBlockX(wallBlockCnt); int wallBlockY = wallBlock.GetBuildingData().GetWallBlockY(wallBlockCnt); minWallBlockX = LogicMath.Min(minWallBlockX, wallBlockX); minWallBlockY = LogicMath.Min(minWallBlockY, wallBlockY); maxWallBlockX = LogicMath.Max(maxWallBlockX, wallBlockX); maxWallBlockY = LogicMath.Max(maxWallBlockY, wallBlockY); ++wallBlockCnt; } } } if (baseWallBlock.GetBuildingData().GetWallBlockCount() == wallBlockCnt) { int wallBlockSizeX = maxWallBlockX - minWallBlockX; int wallBlockSizeY = maxWallBlockY - minWallBlockY; int lengthX = maxX - minX; int lengthY = maxY - minY; if (wallBlockSizeX != lengthX || wallBlockSizeY != lengthY) { if (!success && wallBlockSizeX != lengthX != (wallBlockSizeY != lengthY)) { validGameObjects = false; } } } } } } } if (validGameObjects) { for (int i = 0; i < count; i++) { int x = this.m_xPositions[i]; int y = this.m_yPositions[i]; LogicGameObject gameObject = gameObjects[i]; int width = gameObject.GetWidthInTiles(); int height = gameObject.GetHeightInTiles(); int tmp1 = x + width; int tmp2 = y + height; for (int j = 0; j < count; j++) { LogicGameObject gameObject2 = gameObjects[j]; if (gameObject2 != gameObject) { int x2 = this.m_xPositions[j]; int y2 = this.m_yPositions[j]; if (x2 != -1 && y2 != -1) { int width2 = gameObject2.GetWidthInTiles(); int height2 = gameObject2.GetHeightInTiles(); int tmp3 = x2 + width2; int tmp4 = y2 + height2; if (tmp1 > x2 && tmp2 > y2 && x < tmp3 && y < tmp4) { return(0); } } } } } bool moved = false; for (int i = 0; i < count; i++) { int x = this.m_xPositions[i]; int y = this.m_yPositions[i]; LogicGameObject gameObject = gameObjects[i]; LogicVector2 position = gameObject.GetPositionLayout(this.m_layoutId, true); if (position.m_x != -1 && position.m_y != -1) { if (x != position.m_x && y != position.m_y) { moved = true; } } gameObject.SetPositionLayoutXY(x, y, this.m_layoutId, true); LogicGlobals globals = LogicDataTables.GetGlobals(); if (!globals.NoCooldownFromMoveEditModeActive()) { if (level.GetActiveLayout(level.GetVillageType()) == this.m_layoutId) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar.GetExpLevel() >= globals.GetChallengeBaseCooldownEnabledTownHall()) { level.SetLayoutCooldownSecs(this.m_layoutId, globals.GetChallengeBaseSaveCooldown()); } } } } if (moved) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar.GetExpLevel() >= LogicDataTables.GetGlobals().GetChallengeBaseCooldownEnabledTownHall()) { level.SetLayoutCooldownSecs(this.m_layoutId, LogicDataTables.GetGlobals().GetChallengeBaseSaveCooldown()); } } return(0); } } } return(-1); }
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 static void LoadDebugJSONArray(LogicLevel level, LogicJSONArray jsonArray, LogicGameObjectType gameObjectType, int villageType) { if (jsonArray != null) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(villageType); LogicArrayList <LogicGameObject> prevGameObjects = new LogicArrayList <LogicGameObject>(); prevGameObjects.AddAll(gameObjectManager.GetGameObjects(gameObjectType)); for (int i = 0; i < prevGameObjects.Size(); i++) { gameObjectManager.RemoveGameObject(prevGameObjects[i]); } for (int i = 0; i < jsonArray.Size(); i++) { LogicJSONObject jsonObject = jsonArray.GetJSONObject(i); LogicJSONNumber dataNumber = jsonObject.GetJSONNumber("data"); LogicJSONNumber lvlNumber = jsonObject.GetJSONNumber("lvl"); LogicJSONBoolean lockedBoolean = jsonObject.GetJSONBoolean("locked"); LogicJSONNumber xNumber = jsonObject.GetJSONNumber("x"); LogicJSONNumber yNumber = jsonObject.GetJSONNumber("y"); if (dataNumber != null && xNumber != null && yNumber != null) { LogicGameObjectData data = (LogicGameObjectData)LogicDataTables.GetDataById(dataNumber.GetIntValue()); if (data != null) { LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, level, villageType); if (gameObjectType == LogicGameObjectType.BUILDING) { ((LogicBuilding)gameObject).StartConstructing(true); } if (lockedBoolean != null && lockedBoolean.IsTrue()) { ((LogicBuilding)gameObject).Lock(); } gameObject.Load(jsonObject); gameObjectManager.AddGameObject(gameObject, -1); if (lvlNumber != null) { LogicDebugUtil.SetBuildingUpgradeLevel(level, gameObject.GetGlobalID(), lvlNumber.GetIntValue(), villageType); } } } } } }