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) { 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 (level.IsReadyForAttack()) { int tileX = this.m_x >> 9; int tileY = this.m_y >> 9; if (level.GetTileMap().GetTile(tileX, tileY) != null) { if (level.GetTileMap().IsPassablePathFinder(this.m_x >> 8, this.m_y >> 8)) { if (level.GetTileMap().IsValidAttackPos(tileX, tileY)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { int unitCount = level.GetVillageType() == 1 ? playerAvatar.GetUnitCountVillage2(this.m_data) : playerAvatar.GetUnitCount(this.m_data); if (unitCount > 0) { if (level.GetBattleLog() != null) { if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0) { level.UpdateLastUsedArmy(); } } if (level.GetGameMode().IsInAttackPreparationMode()) { level.GetGameMode().EndAttackPreparation(); } LogicCharacter character = LogicPlaceAttackerCommand.PlaceAttacker(playerAvatar, this.m_data, level, this.m_x, this.m_y); if (character != null && character.HasSpecialAbility()) { if (this.m_data.GetSpecialAbilityType() == LogicCharacterData.SPECIAL_ABILITY_TYPE_START_RAGE) { LogicSpellData specialAbilitySpellData = this.m_data.GetSpecialAbilitySpell(); level.BoostGameObject(character, specialAbilitySpellData.GetSpeedBoost(0), specialAbilitySpellData.GetSpeedBoost2(0), specialAbilitySpellData.GetDamageBoostPercent(0), specialAbilitySpellData.GetAttackSpeedBoost(0), 60 * this.m_data.GetSpecialAbilityAttribute(character.GetUpgradeLevel()), specialAbilitySpellData.GetBoostLinkedToPoison()); } else if (this.m_data.GetSpecialAbilityType() == LogicCharacterData.SPECIAL_ABILITY_TYPE_START_CLOAK) { character.SetStealthTime(15 * this.m_data.GetSpecialAbilityAttribute(character.GetUpgradeLevel())); } } return(0); } return(-7); } return(-5); } return(-4); } return(-2); } return(-3); } return(-1); }
public override int Execute(LogicLevel level) { if (this.m_trapData != null) { if (this.m_trapData.GetVillageType() == level.GetVillageType()) { if (level.IsValidPlaceForBuilding(this.m_x, this.m_y, this.m_trapData.GetWidth(), this.m_trapData.GetHeight(), null)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData buildResourceData = this.m_trapData.GetBuildResource(); int buildCost = this.m_trapData.GetBuildCost(0); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false) && !level.IsTrapCapReached(this.m_trapData, true)) { if (level.GetGameMode().GetCalendar().IsEnabled(this.m_trapData)) { if (buildResourceData.IsPremiumCurrency()) { playerAvatar.UseDiamonds(buildCost); playerAvatar.GetChangeListener().DiamondPurchaseMade(1, this.m_trapData.GetGlobalID(), 0, buildCost, level.GetVillageType()); } else { playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); } LogicTrap trap = (LogicTrap)LogicGameObjectFactory.CreateGameObject(this.m_trapData, level, level.GetVillageType()); if (this.m_trapData.GetBuildTime(0) == 0) { trap.FinishConstruction(false); } trap.SetInitialPosition(this.m_x << 9, this.m_y << 9); level.GetGameObjectManager().AddGameObject(trap, -1); if (level.IsTrapCapReached(this.m_trapData, false)) { level.GetGameListener().TrapCapReached(this.m_trapData); } 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(this.m_x + i, this.m_y + j).GetTallGrass(); if (tallGrass != null) { level.GetGameObjectManager().RemoveGameObject(tallGrass); } } } return(0); } } } return(-1); } return(-32); } return(-1); }
public override int Execute(LogicLevel level) { if (level.IsReadyForAttack()) { if (this.m_data != null && !level.IsAttackerHeroPlaced(this.m_data)) { if (level.GetVillageType() == this.m_data.GetVillageType()) { int tileX = this.m_x >> 9; int tileY = this.m_y >> 9; if (level.GetTileMap().GetTile(tileX, tileY) != null) { if (level.GetTileMap().IsPassablePathFinder(this.m_x >> 8, this.m_y >> 8)) { if (level.GetTileMap().IsValidAttackPos(tileX, tileY)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { if (playerAvatar.IsHeroAvailableForAttack(this.m_data)) { if (level.GetBattleLog() != null) { if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0) { level.UpdateLastUsedArmy(); } } if (level.GetGameMode().IsInAttackPreparationMode()) { level.GetGameMode().EndAttackPreparation(); } int health = playerAvatar.GetHeroHealth(this.m_data); int upgLevel = playerAvatar.GetUnitUpgradeLevel(this.m_data); level.SetAttackerHeroPlaced(this.m_data, LogicPlaceHeroCommand.PlaceHero(this.m_data, level, this.m_x, this.m_y, this.m_data.GetHeroHitpoints(health, upgLevel), upgLevel)); return(0); } } return(-5); } return(-4); } return(-2); } return(-3); } return(-23); } return(-5); } return(-1); }
public override int Execute(LogicLevel level) { if (level.IsReadyForAttack()) { if (level.GetVillageType() == 0) { if (LogicDataTables.GetGlobals().AllowClanCastleDeployOnObstacles()) { if (!level.GetTileMap().IsValidAttackPos(this.m_x >> 9, this.m_y >> 9)) { return(-2); } } else { LogicTile tile = level.GetTileMap().GetTile(this.m_x >> 9, this.m_y >> 9); if (tile == null) { return(-4); } if (tile.GetPassableFlag() == 0) { return(-3); } } LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { if (this.m_data != null) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); if (gameObjectManager.GetGameObjectCountByData(this.m_data) <= 0 && playerAvatar.GetAllianceCastleUsedCapacity() > 0) { LogicAlliancePortal alliancePortal = (LogicAlliancePortal)LogicGameObjectFactory.CreateGameObject(this.m_data, level, level.GetVillageType()); LogicBunkerComponent bunkerComponent = alliancePortal.GetBunkerComponent(); alliancePortal.SetInitialPosition(this.m_x, this.m_y); if (bunkerComponent != null) { bunkerComponent.SetMaxCapacity(playerAvatar.GetAllianceCastleTotalCapacity()); if (level.GetBattleLog() != null) { if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0) { level.UpdateLastUsedArmy(); } } if (level.GetGameMode().IsInAttackPreparationMode()) { level.GetGameMode().EndAttackPreparation(); } bunkerComponent.RemoveAllUnits(); LogicArrayList <LogicUnitSlot> allianceUnits = playerAvatar.GetAllianceUnits(); for (int i = 0; i < allianceUnits.Size(); i++) { LogicUnitSlot slot = allianceUnits[i]; LogicCombatItemData data = (LogicCombatItemData)slot.GetData(); if (data != null) { int count = slot.GetCount(); if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { for (int j = 0; j < count; j++) { if (bunkerComponent.GetUnusedCapacity() >= data.GetHousingSpace()) { bunkerComponent.AddUnitImpl(data, slot.GetLevel()); } } } } else { Debugger.Error("LogicPlaceAlliancePortalCommand::execute - NULL alliance character"); } } } gameObjectManager.AddGameObject(alliancePortal, -1); return(0); } } } return(-5); } } return(-1); }
public void UpdatePatrolArea(LogicLevel level) { if (this.m_wayPoints != null) { int wayPointCount = this.m_wayPoints.Size(); if (wayPointCount > 0 && this.m_pathLength == 0) { for (int i = wayPointCount - 1; i >= 0; i--) { this.m_patrolAreaCounter = (this.m_patrolAreaCounter + 1) % wayPointCount; if (this.MoveTo(this.m_wayPoints[this.m_patrolAreaCounter].m_x, this.m_wayPoints[this.m_patrolAreaCounter].m_y, level.GetTileMap(), true)) { break; } } if (this.m_patrolPost != null && this.m_patrolPost.GetDefenceUnitProduction() != null) { this.m_freezeTime = (level.IsInCombatState() ? 100 : 5000) + level.GetLogicTime().GetTick() % (level.IsInCombatState() ? 200 : 3000); } } } }
public void CreatePatrolArea(LogicGameObject patrolPost, LogicLevel level, bool unk, int idx) { LogicArrayList <LogicVector2> wayPoints = new LogicArrayList <LogicVector2>(8); if (this.m_patrolPost == null) { this.m_patrolPost = patrolPost; } int startX = 0; int startY = 0; int endX = 0; int endY = 0; int midX = 0; int midY = 0; int width = 0; int height = 0; int radius = 0; if (patrolPost != null) { startX = patrolPost.GetX() - 128; startY = patrolPost.GetY() - 128; endX = patrolPost.GetX() + (patrolPost.GetWidthInTiles() << 9) + 128; endY = patrolPost.GetY() + (patrolPost.GetHeightInTiles() << 9) + 128; midX = patrolPost.GetMidX(); midY = patrolPost.GetMidY(); width = patrolPost.GetWidthInTiles() << 8; height = patrolPost.GetHeightInTiles() << 8; radius = 1536; } if (radius * radius >= (uint)(width * width + height * height)) { LogicVector2 tmp1 = new LogicVector2(); LogicVector2 tmp2 = new LogicVector2(); LogicVector2 tmp3 = new LogicVector2(); LogicVector2 tmp4 = new LogicVector2(); tmp2.Set(midX, midY); int rnd = patrolPost.GetLevel().GetLogicTime().GetTick() + idx; midX = midX + 127 * rnd % 1024 - 512; midY = midY + 271 * rnd % 1024 - 512; for (int i = 0, j = 45; i < 4; i++, j += 90) { tmp1.Set(midX + LogicMath.Cos(j, radius), midY + LogicMath.Sin(j, radius)); LogicHeroBaseComponent.FindPoint(patrolPost.GetLevel().GetTileMap(), tmp3, tmp2, tmp1, tmp4); wayPoints.Add(new LogicVector2(tmp4.m_x, tmp4.m_y)); } tmp1.Destruct(); tmp2.Destruct(); tmp3.Destruct(); tmp4.Destruct(); } else { wayPoints.Add(new LogicVector2(endX, endY)); wayPoints.Add(new LogicVector2(startX, endY)); wayPoints.Add(new LogicVector2(startX, startY)); wayPoints.Add(new LogicVector2(endX, startY)); } this.ClearPatrolArea(); this.m_wayPoints = wayPoints; this.m_patrolAreaCounter = 0; if (this.m_wayPoints.Size() > 1) { int closestLength = 0x7FFFFFFF; for (int i = 1, size = this.m_wayPoints.Size(); i < size; i++) { LogicVector2 wayPoint = this.m_wayPoints[i]; int length = (wayPoint.m_x - (this.m_position.m_x >> 16)) * (wayPoint.m_x - (this.m_position.m_x >> 16)) + (wayPoint.m_y - (this.m_position.m_y >> 16)) * (wayPoint.m_y - (this.m_position.m_y >> 16)); if (length < closestLength) { this.m_patrolAreaCounter = i; closestLength = length; } } } this.MoveTo(this.m_wayPoints[this.m_patrolAreaCounter].m_x, this.m_wayPoints[this.m_patrolAreaCounter].m_y, level.GetTileMap(), true); }
public static bool FindGoodDuplicatePosAround(LogicLevel level, int x, int y, out int outputX, out int outputY, int radiusInTiles) { int width = level.GetWidth(); int height = level.GetHeight(); int radius = radiusInTiles << 9; if (-512 * radiusInTiles < x) { x = x >= 0 ? x : 0; } if (-512 * radiusInTiles < y) { y = y >= 0 ? y : 0; } if (level.IsNpcVillage()) { if (x <= 0) { x = 512; } if (y <= 0) { y = 512; } width -= 512; height -= 512; if (x - radius > width || y - radius > height) { outputX = 0; outputY = 0; return(false); } } int startX = x; int startY = y; if (x < width + radius) { startX = x <= width ? x : width; } if (y < height + radius) { startY = y <= height ? y : height; } int tileX = startX / 512 - 1; int tileY = startY / 512 - 1; for (int i = 0; i < 9; i++) { int randomPos = (i + 4) % 9; int randomX = tileX + randomPos % 3; int randomY = tileY + randomPos / 3; LogicTile tile = level.GetTileMap().GetTile(randomX, randomY); if (tile != null) { if (tile.GetPassableFlag() != 0) { if (i == 0) { outputX = startX; outputY = startY; return(true); } outputX = randomX << 9; outputY = randomY << 9; return(true); } for (int j = 0; j < 4; j++) { if (tile.IsPassablePathFinder(j & 1, j >> 1)) { outputX = (randomX << 9) | ((j & 1) << 8); outputY = (randomY << 9) + ((j >> 1) << 8); return(true); } } } } outputX = 0; outputY = 0; return(false); }
public static bool GetNearestValidAttackPos(LogicLevel level, int x, int y, out int outputX, out int outputY) { if ((uint)x > 0xFFFFF600) { x = 0; } if ((uint)y > 0xFFFFF600) { y = 0; } int width = level.GetWidth(); int height = level.GetHeight(); if (level.IsNpcVillage()) { if (x <= 0) { x = 512; } if (y <= 0) { y = 512; } if (x - 2048 > width || y - 2048 > height) { outputX = 0; outputY = 0; return(false); } width -= 512; height -= 512; } int startX = x; int startY = y; if (x < width + 2560) { startX = x <= width ? x : width; } if (y < height + 2560) { startY = y <= height ? y : height; } int tileX = startX / 512 - 1; int tileY = startY / 512 - 1; for (int i = 0; i < 9; i++) { int randomPos = (i + 4) % 9; int randomX = tileX + randomPos % 3; int randomY = tileY + randomPos / 3; LogicTile tile = level.GetTileMap().GetTile(randomX, randomY); if (tile != null && level.GetTileMap().IsValidAttackPos(randomX, randomY)) { if (tile.GetPassableFlag() != 0) { if (i == 0) { outputX = startX; outputY = startY; return(true); } outputX = randomX << 9; outputY = randomY << 9; return(true); } for (int j = 0; j < 4; j++) { if (tile.IsPassablePathFinder(j & 1, j >> 1)) { outputX = (randomX << 9) | ((j & 1) << 8); outputY = (randomY << 9) + ((j >> 1) << 8); return(true); } } } } outputX = 0; outputY = 0; return(false); }
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); }