public override int Execute(LogicLevel level) { if (level.GetVillageType() == 0) { LogicUnitProduction unitProduction = null; switch (this.m_index) { case 1: unitProduction = level.GetGameObjectManagerAt(0).GetUnitProduction(); break; case 2: unitProduction = level.GetGameObjectManagerAt(0).GetSpellProduction(); break; } if (unitProduction == null) { return(-1); } unitProduction.SetLocked(this.m_disabled); return(0); } return(-32); }
public override int Execute(LogicLevel level) { if (level.GetVillageType() == 0) { LogicGameMode gameMode = level.GetGameMode(); if (gameMode.GetShieldRemainingSeconds() <= 0) { gameMode.SetShieldRemainingSeconds(0); gameMode.SetGuardRemainingSeconds(0); gameMode.GetLevel().GetHome().GetChangeListener().ShieldActivated(0, 0); } else { int guardTime = gameMode.GetGuardRemainingSeconds(); gameMode.SetShieldRemainingSeconds(0); gameMode.SetGuardRemainingSeconds(guardTime); gameMode.SetPersonalBreakCooldownSeconds(LogicDataTables.GetGlobals().GetPersonalBreakLimitSeconds()); level.GetHome().GetChangeListener().ShieldActivated(0, guardTime); } return(0); } return(-32); }
private static bool CanUpgradeTHV2(LogicLevel level) { if (level.GetVillageType() == 1) { LogicDataTable buildingTable = LogicDataTables.GetTable(LogicDataType.BUILDING); for (int i = 0; i < buildingTable.GetItemCount(); i++) { LogicBuildingData buildingData = (LogicBuildingData)buildingTable.GetItemAt(i); if (buildingData.GetVillageType() == 1 && !level.IsBuildingCapReached(buildingData, false)) { return(false); } } LogicDataTable trapTable = LogicDataTables.GetTable(LogicDataType.TRAP); for (int i = 0; i < trapTable.GetItemCount(); i++) { LogicTrapData trapData = (LogicTrapData)trapTable.GetItemAt(i); if (trapData.GetVillageType() == 1 && !level.IsTrapCapReached(trapData, false)) { return(false); } } return(true); } return(false); }
public override int Execute(LogicLevel level) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (level.GetVillageType() == 1) { LogicGameMode gameMode = level.GetGameMode(); if (!gameMode.IsInAttackPreparationMode()) { if (gameMode.GetState() != 5) { return(-9); } } if (this.m_oldUnitData != null && this.m_newUnitData != null && gameMode.GetCalendar().IsProductionEnabled(this.m_newUnitData)) { if (!this.m_newUnitData.IsUnlockedForBarrackLevel(playerAvatar.GetVillage2BarrackLevel())) { if (gameMode.GetState() != 7) { return(-7); } } int oldUnitCount = playerAvatar.GetUnitCountVillage2(this.m_oldUnitData); int oldUnitsInCamp = this.m_oldUnitData.GetUnitsInCamp(playerAvatar.GetUnitUpgradeLevel(this.m_oldUnitData)); if (oldUnitCount >= oldUnitsInCamp) { int newUnitCount = playerAvatar.GetUnitCountVillage2(this.m_newUnitData); int newUnitsInCamp = this.m_newUnitData.GetUnitsInCamp(playerAvatar.GetUnitUpgradeLevel(this.m_newUnitData)); playerAvatar.SetUnitCountVillage2(this.m_oldUnitData, oldUnitCount - oldUnitsInCamp); playerAvatar.SetUnitCountVillage2(this.m_newUnitData, newUnitCount + newUnitsInCamp); LogicArrayList <LogicDataSlot> unitsNew = playerAvatar.GetUnitsNewVillage2(); for (int i = 0; i < unitsNew.Size(); i++) { LogicDataSlot slot = unitsNew[i]; if (slot.GetCount() > 0) { playerAvatar.CommodityCountChangeHelper(8, slot.GetData(), -slot.GetCount()); } } return(0); } return(-23); } return(-7); } return(-10); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { int villageType = level.GetVillageType(); if (this._villageType != -1) { villageType = this._villageType; } int freeWorkers = level.GetWorkerManagerAt(villageType).GetFreeWorkers(); if (freeWorkers == 0) { if (level.GetWorkerManagerAt(villageType).FinishTaskOfOneWorker()) { if (this._command != null) { int commandType = this._command.GetCommandType(); if (commandType < 1000) { if (commandType >= 500 && commandType < 700) { this._command.Execute(level); } } } return(0); } } return(-1); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { if (LogicDataTables.GetGlobals().UseNewTraining()) { if (level.GetVillageType() == 0) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicUnitProduction unitProduction = this._productionType == 1 ? level.GetGameObjectManager().GetSpellProduction() : level.GetGameObjectManager().GetUnitProduction(); if (unitProduction.CanBeBoosted()) { int cost = unitProduction.GetBoostCost(); if (playerAvatar.HasEnoughDiamonds(cost, true, level)) { playerAvatar.UseDiamonds(cost); unitProduction.Boost(); return(0); } return(-2); } return(-1); } return(-32); } return(-99); }
/// <summary> /// Executes this instance. /// </summary> public override int Execute(LogicLevel level) { if (true) { int tileX = this._x >> 9; int tileY = this._y >> 9; if (level.GetTileMap().GetTile(tileX, tileY) != null) { // if (level.GetTileMap().IsPassablePathFinder(this._x >> 8, this._y >> 8)) { if (level.GetTileMap().IsValidAttackPos(tileX, tileY)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { int unitCount = level.GetVillageType() == 1 ? playerAvatar.GetUnitCountVillage2(this._data) : playerAvatar.GetUnitCount(this._data); if (unitCount > 0) { if (level.GetBattleLog() != null) { // ? } if (level.GetGameMode().IsInAttackPreparationMode()) { level.GetGameMode().EndAttackPreparation(); } LogicCharacter character = LogicPlaceAttackerCommand.PlaceAttacker(playerAvatar, this._data, level, this._x, this._y); if (character != null) { // TODO: Finish this. } return(0); } return(-7); } return(-5); } return(-4); } // return -2; } return(-3); } return(-1); }
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); }
public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { if (gameObject.GetVillageType() == level.GetVillageType()) { LogicResourceProductionComponent resourceProductionComponent = gameObject.GetResourceProductionComponent(); if (resourceProductionComponent != null) { if (LogicDataTables.GetGlobals().CollectAllResourcesAtOnce()) { int baseAvailableResources = resourceProductionComponent.GetResourceCount(); int baseCollectedResources = resourceProductionComponent.CollectResources(true); bool storageIsFull = baseAvailableResources > 0 && baseCollectedResources == 0; LogicArrayList <LogicComponent> components = level.GetComponentManager().GetComponents(resourceProductionComponent.GetComponentType()); for (int i = 0; i < components.Size(); i++) { LogicResourceProductionComponent component = (LogicResourceProductionComponent)components[i]; if (resourceProductionComponent != component && resourceProductionComponent.GetResourceData() == component.GetResourceData()) { int availableResources = component.GetResourceCount(); int collectedResources = component.CollectResources(!storageIsFull); if (availableResources > 0) { if (collectedResources == 0) { storageIsFull = true; } } } } } else { resourceProductionComponent.CollectResources(true); } return(0); } return(-1); } return(-3); } return(-2); }
public override int Execute(LogicLevel level) { if (level.GetVillageType() == 1) { if (this.m_gameObjectId != 0) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(1); LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (this.m_unitData != null && level.GetGameMode().GetCalendar().IsProductionEnabled(this.m_unitData)) { if (this.m_unitData.GetVillageType() == 1) { LogicVillage2UnitComponent village2UnitComponent = building.GetVillage2UnitComponent(); if (village2UnitComponent != null) { if (this.m_unitData.IsUnlockedForProductionHouseLevel(gameObjectManager.GetHighestBuildingLevel(this.m_unitData.GetProductionHouseData(), true)) ) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData trainResource = this.m_unitData.GetTrainingResource(); int trainCost = this.m_unitData.GetTrainingCost(playerAvatar.GetUnitUpgradeLevel(this.m_unitData)); if (playerAvatar.HasEnoughResources(trainResource, trainCost, true, this, false)) { village2UnitComponent.TrainUnit(this.m_unitData); playerAvatar.CommodityCountChangeHelper(0, trainResource, -trainCost); } return(0); } return(-7); } return(-4); } return(-8); } } return(-5); } return(-1); } return(-10); }
public override int Execute(LogicLevel level) { if (level.GetVillageType() == 1) { if (level.IsUnitsTrainedVillage2()) { if (level.GetState() == 1) { if (this.m_buyResourceCount > 0) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.GetUnusedResourceCap(LogicDataTables.GetGold2Data()) < this.m_buyResourceCount) { return(-1); } int buyResourceCost = LogicGamePlayUtil.GetResourceDiamondCost(this.m_buyResourceCount, LogicDataTables.GetGold2Data()); if (playerAvatar.HasEnoughDiamonds(buyResourceCost, true, level)) { return(-2); } playerAvatar.UseDiamonds(buyResourceCost); playerAvatar.GetChangeListener().DiamondPurchaseMade(5, LogicDataTables.GetGold2Data().GetGlobalID(), this.m_buyResourceCount, buyResourceCost, level.GetVillageType()); playerAvatar.CommodityCountChangeHelper(0, LogicDataTables.GetGold2Data(), this.m_buyResourceCount); } level.GetGameListener().MatchmakingVillage2CommandExecuted(); return(0); } return(-3); } return(-24); } return(-32); }
/// <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); }
public static LogicCharacter PlaceAttacker(LogicAvatar avatar, LogicCharacterData characterData, LogicLevel level, int x, int y) { avatar.CommodityCountChangeHelper(level.GetVillageType() == 1 ? 7 : 0, characterData, -1); LogicCharacter character = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(characterData, level, level.GetVillageType()); int upgradeLevel = avatar.GetUnitUpgradeLevel(characterData); if (level.GetMissionManager().GetMissionByCategory(2) != null && level.GetVillageType() == 1 && level.GetHomeOwnerAvatar() != null) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar.IsNpcAvatar()) { upgradeLevel = LogicMath.Clamp(LogicDataTables.GetGlobals().GetVillage2StartUnitLevel(), 0, characterData.GetUpgradeLevelCount() - 1); } } character.SetUpgradeLevel(upgradeLevel); character.SetInitialPosition(x, y); if (characterData.IsJumper()) { character.GetMovementComponent().EnableJump(3600000); character.GetCombatComponent().RefreshTarget(true); } level.GetGameObjectManager().AddGameObject(character, -1); level.GetGameListener().AttackerPlaced(characterData); LogicBattleLog battleLog = level.GetBattleLog(); if (battleLog != null) { battleLog.IncrementDeployedAttackerUnits(characterData, 1); battleLog.SetCombatItemLevel(characterData, upgradeLevel); } character.UpdateAutoMerge(); return(character); }
/// <summary> /// Places the specified attacker. /// </summary> public static LogicCharacter PlaceAttacker(LogicAvatar avatar, LogicCharacterData characterData, LogicLevel level, int x, int y) { avatar.CommodityCountChangeHelper(level.GetVillageType() == 1 ? 7 : 0, characterData, -1); LogicCharacter character = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(characterData, level, level.GetVillageType()); Int32 upgradeLevel = avatar.GetUnitUpgradeLevel(characterData); if (level.GetMissionManager().GetMissionByCategory(2) != null && level.GetVillageType() == 1 && level.GetHomeOwnerAvatar() != null) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar.IsNpcAvatar()) { upgradeLevel = LogicMath.Clamp(LogicDataTables.GetGlobals().GetVillage2StartUnitLevel(), 0, characterData.GetUpgradeLevelCount()); } } character.SetUpgradeLevel(upgradeLevel); character.SetInitialPosition(x, y); return(character); }
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.GetVillageType() == 0) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { int unitCount = this.m_allianceSpell ? playerAvatar.GetAllianceUnitCount(this.m_data, this.m_upgLevel) : 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(); } LogicCastSpellCommand.CastSpell(playerAvatar, this.m_data, this.m_allianceSpell, this.m_upgLevel, level, this.m_x, this.m_y); return(0); } } return(-3); } Debugger.Error("not available for village"); return(-23); } return(-3); } return(-1); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { if (level.GetVillageType() <= 1) { if (!LogicDataTables.GetGlobals().UseNewTraining()) { return(-1); // TODO: Implement this. } return(this.NewTrainingUnit(level)); } return(-32); }
public override int Execute(LogicLevel level) { if (level.GetVillageType() == 0) { if (!LogicDataTables.GetGlobals().UseNewTraining()) { throw new NotImplementedException(); // TODO: Implement this. } return(this.SpeedUpNewTrainingUnit(level)); } return(-32); }
/// <summary> /// Executes this instance. /// </summary> public override int Execute(LogicLevel level) { if (true) { int tileX = this._x >> 9; int tileY = this._y >> 9; if (level.GetTileMap().GetTile(tileX, tileY) != null) { if (level.GetVillageType() == 0) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { int unitCount = this._allianceSpell ? playerAvatar.GetAllianceUnitCount(this._data, this._upgLevel) : playerAvatar.GetUnitCount(this._data); if (unitCount > 0) { if (level.GetBattleLog() != null) { // ? } if (level.GetGameMode().IsInAttackPreparationMode()) { level.GetGameMode().EndAttackPreparation(); } LogicCastSpellCommand.CastSpell(playerAvatar, this._data, this._allianceSpell, this._upgLevel, level, this._x, this._y); return(0); } } return(-3); } else { Debugger.Error("not available for village"); } return(-23); } return(-3); } return(-1); }
/// <summary> /// Gets the worker cost. /// </summary> public int GetWorkerCost(LogicLevel level) { int totalWorkers = level.GetWorkerManagerAt(level.GetVillageType()).GetTotalWorkers() + level.GetUnplacedObjectCount(LogicDataTables.GetWorkerData()); switch (totalWorkers) { case 1: return(this._workerCostSecondBuildCost); case 2: return(this._workerCostThirdBuildCost); case 3: return(this._workerCostFourthBuildCost); case 4: return(this._workerCostFifthBuildCost); default: return(this._workerCostFifthBuildCost); } }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { if (this._newShopItemsType <= 17) { if (level.SetUnlockedShopItemCount(LogicDataTables.GetTable(this._newShopItemsType).GetItemAt(this._newShopItemsIndex), this._newShopItemsIndex, this._newShopItemsCount, level.GetVillageType())) { return(0); } return(-2); } return(-1); }
public override int Execute(LogicLevel level) { if (level.GetVillageType() == 0) { if (level.GetState() == 2 || level.GetState() == 1) { if (this.m_buyResourceData != null) { if (this.m_buyResourceCount > 0 && !this.m_buyResourceData.IsPremiumCurrency()) { int cost = LogicGamePlayUtil.GetResourceDiamondCost(this.m_buyResourceCount, this.m_buyResourceData); LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.GetUnusedResourceCap(this.m_buyResourceData) >= this.m_buyResourceCount) { if (playerAvatar.HasEnoughDiamonds(cost, true, level)) { playerAvatar.UseDiamonds(cost); playerAvatar.GetChangeListener() .DiamondPurchaseMade(5, this.m_buyResourceData.GetGlobalID(), this.m_buyResourceCount, cost, level.GetVillageType()); playerAvatar.CommodityCountChangeHelper(0, this.m_buyResourceData, this.m_buyResourceCount); } else { return(-2); } } else { return(-1); } } } level.GetGameListener().MatchmakingCommandExecuted(); return(0); } return(-3); } return(-32); }
public override int Execute(LogicLevel level) { if (this.m_newShopItemsType == LogicDataType.BUILDING || this.m_newShopItemsType == LogicDataType.TRAP || this.m_newShopItemsType == LogicDataType.DECO) { if (level.SetUnlockedShopItemCount((LogicGameObjectData)LogicDataTables.GetTable(this.m_newShopItemsType).GetItemAt(this.m_newShopItemsIndex), this.m_newShopItemsIndex, this.m_newShopItemsCount, level.GetVillageType())) { return(0); } return(-2); } return(-1); }
public override int Execute(LogicLevel level) { if (level.GetVillageType() == 0) { if (!LogicDataTables.GetGlobals().UseNewTraining()) { if (this.m_gameObjectId == 0) { return(-1); } // TODO: Implement this. } else { return(this.NewTrainingUnit(level)); } } return(-32); }
public override int Execute(LogicLevel level) { this.m_level = level; if (level.GetVillageType() == 0) { if (LogicDataTables.GetGlobals().EnablePresets()) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetEnablePresetsTownHallLevel()) { if (this.m_presetId <= 3) { if (this.HasEnoughFreeHousingSpace()) { int elixirCost = this.GetResourceCost(LogicDataTables.GetElixirData()); int darkElixirCost = this.GetResourceCost(LogicDataTables.GetDarkElixirData()); if (level.GetPlayerAvatar().HasEnoughResources(LogicDataTables.GetElixirData(), elixirCost, LogicDataTables.GetDarkElixirData(), darkElixirCost, true, this, false)) { this.TrainUnits(); return(0); } } return(-1); } return(-2); } } return(-3); } return(-32); }
public override int Execute(LogicLevel level) { if (this.m_layoutId != 6) { if (this.m_layoutId != 7) { if (this.m_state == 0) { LogicGameObjectFilter filter = new LogicGameObjectFilter(); LogicArrayList <LogicGameObject> gameObjects = new LogicArrayList <LogicGameObject>(500); filter.AddGameObjectType(LogicGameObjectType.BUILDING); filter.AddGameObjectType(LogicGameObjectType.TRAP); filter.AddGameObjectType(LogicGameObjectType.DECO); level.GetGameObjectManager().GetGameObjects(gameObjects, filter); for (int i = 0; i < gameObjects.Size(); i++) { gameObjects[i].SetPositionLayoutXY(-1, -1, this.m_layoutId, true); } filter.Destruct(); } level.SetLayoutState(this.m_layoutId, level.GetVillageType(), this.m_state); if (this.m_updateListener) { } return(0); } return(-11); } return(-10); }
public override int Execute(LogicLevel level) { LogicBuilding building = (LogicBuilding)level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (!building.IsLocked()) { if (building.GetBuildingData().GetVillageType() == level.GetVillageType()) { LogicHeroBaseComponent heroBaseComponent = building.GetHeroBaseComponent(); if (heroBaseComponent != null && heroBaseComponent.CanStartUpgrading(true)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicHeroData heroData = building.GetBuildingData().GetHeroData(); int upgLevel = playerAvatar.GetUnitUpgradeLevel(heroData); int upgradeCost = heroData.GetUpgradeCost(upgLevel); LogicResourceData upgradeResourceData = heroData.GetUpgradeResource(upgLevel); if (playerAvatar.HasEnoughResources(upgradeResourceData, upgradeCost, true, this, false)) { if (level.HasFreeWorkers(this, -1)) { playerAvatar.CommodityCountChangeHelper(0, upgradeResourceData, -upgradeCost); heroBaseComponent.StartUpgrading(); return(0); } } } return(-1); } return(-32); } return(-23); }
public override int Execute(LogicLevel level) { if (this.m_villageType >= 0) { if (this.m_villageType <= 1) { if (this.m_villageType != level.GetVillageType()) { if (level.GetGameObjectManagerAt(1).GetTownHall() == null) { // ship was not found!. } return(this.ChangeVillage(level, false)); } return(-3); } return(-2); } return(-1); }
/// <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); }
public void CalculateAvailableResources(LogicLevel level, int matchType) { for (int i = this.m_availableLootCount.Size() - 1; i >= 0; i--) { this.m_availableLootCount[i].Destruct(); this.m_availableLootCount.Remove(i); } LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); LogicResourceData warResourceReferenceData = data.GetWarResourceReferenceData(); LogicDataSlot dataSlot = null; if (warResourceReferenceData != null) { for (int j = 0; j < this.m_availableLootCount.Size(); j++) { if (this.m_availableLootCount[j].GetData() == warResourceReferenceData) { dataSlot = this.m_availableLootCount[j]; break; } } Debugger.DoAssert(dataSlot != null, "Didn't find the resource slot"); } else { this.m_availableLootCount.Add(dataSlot = new LogicDataSlot(data, 0)); } if (matchType == 8 || matchType == 9) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null) { LogicArrayList <LogicDataSlot> resourceCount = homeOwnerAvatar.GetResources(); for (int j = 0; j < resourceCount.Size(); j++) { if (resourceCount[j].GetData() == data) { dataSlot.SetCount(resourceCount[j].GetCount()); } } } } else { LogicComponentManager componentManager = level.GetComponentManagerAt(level.GetVillageType()); if (warResourceReferenceData == null) { LogicArrayList <LogicComponent> resourceProductionComponents = componentManager.GetComponents(LogicComponentType.RESOURCE_PRODUCTION); LogicArrayList <LogicComponent> resourceStorageComponents = componentManager.GetComponents(LogicComponentType.RESOURCE_STORAGE); for (int j = 0; j < resourceProductionComponents.Size(); j++) { LogicResourceProductionComponent resourceProductionComponent = (LogicResourceProductionComponent)resourceProductionComponents[j]; LogicGameObject gameObject = resourceProductionComponent.GetParent(); if (gameObject.IsAlive() && resourceProductionComponent.IsEnabled()) { if (resourceProductionComponent.GetResourceData() == data) { dataSlot.SetCount(dataSlot.GetCount() + resourceProductionComponent.GetStealableResourceCount()); } } } for (int j = 0; j < resourceStorageComponents.Size(); j++) { LogicResourceStorageComponent resourceStorageComponent = (LogicResourceStorageComponent)resourceStorageComponents[j]; LogicGameObject gameObject = resourceStorageComponent.GetParent(); if (gameObject.IsAlive() && resourceStorageComponent.IsEnabled()) { dataSlot.SetCount(dataSlot.GetCount() + resourceStorageComponent.GetStealableResourceCount(i)); } } } else { LogicArrayList <LogicComponent> warResourceStorageComponents = componentManager.GetComponents(LogicComponentType.WAR_RESOURCE_STORAGE); for (int j = 0; j < warResourceStorageComponents.Size(); j++) { LogicWarResourceStorageComponent resourceWarStorageComponent = (LogicWarResourceStorageComponent)warResourceStorageComponents[j]; LogicGameObject gameObject = resourceWarStorageComponent.GetParent(); if (gameObject.IsAlive() && resourceWarStorageComponent.IsEnabled()) { dataSlot.SetCount(dataSlot.GetCount() + resourceWarStorageComponent.GetStealableResourceCount(i)); } } } } } }
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); }