public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (building.IsLocked()) { if (building.GetUpgradeLevel() == 0 && building.CanUnlock(true)) { LogicBuildingData buildingData = building.GetBuildingData(); if (buildingData.GetConstructionTime(0, level, 0) == 0 || level.HasFreeWorkers(this, -1)) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicResourceData buildResource = buildingData.GetBuildResource(0); int buildCost = buildingData.GetBuildCost(0, level); if (playerAvatar.HasEnoughResources(buildResource, buildCost, true, this, false)) { playerAvatar.CommodityCountChangeHelper(0, buildResource, -buildCost); building.StartConstructing(true); building.GetListener().RefreshState(); return(0); } } } } } return(-1); }
public override int Execute(LogicLevel level) { LogicBuilding allianceCastle = level.GetGameObjectManagerAt(0).GetAllianceCastle(); if (allianceCastle != null) { LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent(); if (bunkerComponent != null && bunkerComponent.GetRequestCooldownTime() == 0) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); homeOwnerAvatar.GetChangeListener().RequestAllianceUnits(allianceCastle.GetUpgradeLevel(), bunkerComponent.GetUsedCapacity(), bunkerComponent.GetMaxCapacity(), homeOwnerAvatar.GetAllianceCastleUsedSpellCapacity(), homeOwnerAvatar.GetAllianceCastleTotalSpellCapacity(), this.m_message); bunkerComponent.StartRequestCooldownTime(); return(0); } } return(-1); }
/// <summary> /// Gets the max spell forge level. /// </summary> public int GetMaxSpellForgeLevel() { LogicArrayList <LogicComponent> components = this._components[3]; if (components.Count > 0) { int maxUpgLevel = -1; int idx = 0; do { LogicUnitProductionComponent component = (LogicUnitProductionComponent)components[idx]; if (component.GetProductionType() != 0) { if (component.GetParent().GetGameObjectType() == 0) { LogicBuilding parent = (LogicBuilding)component.GetParent(); if (parent.GetBuildingData().GetProducesUnitsOfType() == 1 && (!parent.IsConstructing() || parent.IsUpgrading())) { maxUpgLevel = LogicMath.Max(parent.GetUpgradeLevel(), maxUpgLevel); } } } } while (++idx != components.Count); return(maxUpgLevel); } return(-1); }
public int GetMaxMiniSpellForgeLevel() { LogicArrayList <LogicComponent> components = this.m_components[(int)LogicComponentType.UNIT_PRODUCTION]; if (components.Size() > 0) { int maxUpgLevel = -1; int idx = 0; do { LogicUnitProductionComponent component = (LogicUnitProductionComponent)components[idx]; if (component.GetProductionType() != 0) { if (component.GetParent().GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding parent = (LogicBuilding)component.GetParent(); if (parent.GetBuildingData().GetProducesUnitsOfType() == 2 && (!parent.IsConstructing() || parent.IsUpgrading())) { maxUpgLevel = LogicMath.Max(parent.GetUpgradeLevel(), maxUpgLevel); } } } } while (++idx != components.Size()); return(maxUpgLevel); } return(-1); }
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); }
public bool CanAddUnitToQueue(LogicCombatItemData data, bool ignoreCapacity) { if (data != null) { if (data.GetDataType() == this.m_unitProductionType) { LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0); LogicBuilding productionHouse = gameObjectManager.GetHighestBuilding(data.GetProductionHouseData()); if (productionHouse != null) { if (!data.IsUnlockedForProductionHouseLevel(productionHouse.GetUpgradeLevel())) { return(false); } if (data.GetUnitOfType() != productionHouse.GetBuildingData().GetProducesUnitsOfType()) { return(false); } } if (this.m_level.GetMissionManager().IsTutorialFinished() || this.m_level.GetHomeOwnerAvatar().GetUnitsTotalCapacity() + this.GetTotalCount() < LogicUnitProduction.TUTORIAL_MAX_CAPACITY) { if (ignoreCapacity) { return(true); } LogicAvatar avatar = this.m_level.GetHomeOwnerAvatar(); LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType); int totalMaxHousing = componentManager.GetTotalMaxHousing(this.m_unitProductionType != LogicDataType.CHARACTER ? 1 : 0) * 2; int totalUsedCapacity = this.GetTotalCount() + data.GetHousingSpace() + (this.m_unitProductionType == LogicDataType.CHARACTER ? avatar.GetUnitsTotalCapacity() : avatar.GetSpellsTotalCapacity()); return(totalMaxHousing >= totalUsedCapacity); } } else { Debugger.Error("Trying to add wrong unit type to UnitProduction"); } } else { Debugger.Error("Trying to add NULL troop to UnitProduction"); } return(false); }
public bool CanStartUpgrading(LogicCombatItemData data) { if (data != null && this.m_unit == null) { if (this.m_parent.GetLevel().GetGameMode().GetCalendar().IsProductionEnabled(data)) { if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_HERO) { if (this.m_parent.GetVillageType() == data.GetVillageType()) { int upgLevel = this.m_parent.GetLevel().GetHomeOwnerAvatar().GetUnitUpgradeLevel(data); if (data.GetUpgradeLevelCount() - 1 > upgLevel) { int maxProductionHouseLevel; if (data.GetVillageType() == 1) { maxProductionHouseLevel = this.m_parent.GetComponentManager().GetMaxBarrackLevel(); } else { LogicComponentManager componentManager = this.m_parent.GetComponentManager(); if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { maxProductionHouseLevel = data.GetUnitOfType() != 1 ? componentManager.GetMaxDarkBarrackLevel() : componentManager.GetMaxBarrackLevel(); } else { maxProductionHouseLevel = data.GetUnitOfType() == 1 ? componentManager.GetMaxSpellForgeLevel() : componentManager.GetMaxMiniSpellForgeLevel(); } } if (maxProductionHouseLevel >= data.GetRequiredProductionHouseLevel()) { LogicBuilding building = (LogicBuilding)this.m_parent; if (!building.IsLocked()) { return(building.GetUpgradeLevel() >= data.GetRequiredLaboratoryLevel(upgLevel + 1)); } } } } } } } return(false); }
public LogicObstacle(LogicGameObjectData data, LogicLevel level, int villageType) : base(data, level, villageType) { LogicObstacleData obstacleData = this.GetObstacleData(); if (obstacleData.GetSpawnObstacle() != null) { this.AddComponent(new LogicSpawnerComponent(this, obstacleData.GetSpawnObstacle(), obstacleData.GetSpawnRadius(), obstacleData.GetSpawnIntervalSeconds(), obstacleData.GetSpawnCount(), obstacleData.GetMaxSpawned(), obstacleData.GetMaxLifetimeSpawns())); } if (obstacleData.IsLootCart()) { LogicLootCartComponent logicLootCartComponent = new LogicLootCartComponent(this); LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); LogicBuilding townHall = this.GetGameObjectManager().GetTownHall(); LogicArrayList <int> capacityCount = new LogicArrayList <int>(); for (int i = 0, cap = 0; i < resourceTable.GetItemCount(); i++, cap = 0) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); if (townHall != null) { if (!resourceData.IsPremiumCurrency() && resourceData.GetWarResourceReferenceData() == null) { cap = LogicDataTables.GetTownHallLevel(townHall.GetUpgradeLevel()).GetCartLootCap(resourceData); } } capacityCount.Add(cap); } logicLootCartComponent.SetCapacityCount(capacityCount); this.AddComponent(logicLootCartComponent); } }
public void ValidateTroopUpgradeLevels() { LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null) { if (homeOwnerAvatar.IsClientAvatar()) { int[] laboratoryLevels = new int[2]; for (int i = 0; i < 2; i++) { LogicBuilding laboratory = this.m_level.GetGameObjectManagerAt(i).GetLaboratory(); if (laboratory != null) { laboratoryLevels[i] = laboratory.GetUpgradeLevel(); } } LogicDataTable characterTable = LogicDataTables.GetTable(LogicDataType.CHARACTER); for (int i = 0; i < characterTable.GetItemCount(); i++) { LogicCharacterData characterData = (LogicCharacterData)characterTable.GetItemAt(i); int upgradeLevel = homeOwnerAvatar.GetUnitUpgradeLevel(characterData); int villageType = characterData.GetVillageType(); int newUpgradeLevel = upgradeLevel; if (upgradeLevel >= characterData.GetUpgradeLevelCount()) { newUpgradeLevel = characterData.GetUpgradeLevelCount() - 1; } int laboratoryLevel = laboratoryLevels[villageType]; int requireLaboratoryLevel; do { requireLaboratoryLevel = characterData.GetRequiredLaboratoryLevel(newUpgradeLevel--); } while (newUpgradeLevel >= 0 && requireLaboratoryLevel > laboratoryLevel); newUpgradeLevel += 1; if (upgradeLevel > newUpgradeLevel) { homeOwnerAvatar.SetUnitUpgradeLevel(characterData, newUpgradeLevel); homeOwnerAvatar.GetChangeListener().CommodityCountChanged(1, characterData, newUpgradeLevel); } } LogicDataTable spellTable = LogicDataTables.GetTable(LogicDataType.SPELL); for (int i = 0; i < spellTable.GetItemCount(); i++) { LogicSpellData spellData = (LogicSpellData)spellTable.GetItemAt(i); int upgradeLevel = homeOwnerAvatar.GetUnitUpgradeLevel(spellData); int villageType = spellData.GetVillageType(); int newUpgradeLevel = upgradeLevel; if (upgradeLevel >= spellData.GetUpgradeLevelCount()) { newUpgradeLevel = spellData.GetUpgradeLevelCount() - 1; } int laboratoryLevel = laboratoryLevels[villageType]; int requireLaboratoryLevel; do { requireLaboratoryLevel = spellData.GetRequiredLaboratoryLevel(newUpgradeLevel--); } while (newUpgradeLevel >= 0 && requireLaboratoryLevel > laboratoryLevel); newUpgradeLevel += 1; if (upgradeLevel > newUpgradeLevel) { homeOwnerAvatar.SetUnitUpgradeLevel(spellData, newUpgradeLevel); homeOwnerAvatar.GetChangeListener().CommodityCountChanged(1, spellData, newUpgradeLevel); } } } } }
public bool ProductionCompleted(bool speedUp) { bool success = false; if (!this.m_locked) { LogicComponentFilter filter = new LogicComponentFilter(); filter.SetComponentType(0); while (true) { LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType); LogicCombatItemData productionData = this.GetWaitingForSpaceUnit(); if (speedUp) { if (this.m_slots.Size() <= 0) { return(false); } productionData = (LogicCombatItemData)this.m_slots[0].GetData(); } if (productionData == null) { filter.Destruct(); return(false); } bool productionTerminate = this.m_slots[0].IsTerminate(); LogicBuildingData buildingProductionData = productionData.GetProductionHouseData(); LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(this.m_villageType); LogicBuilding productionHouse = gameObjectManager.GetHighestBuilding(buildingProductionData); if (LogicDataTables.GetGlobals().UseTroopWalksOutFromTraining()) { int gameObjectCount = gameObjectManager.GetNumGameObjects(); for (int i = 0; i < gameObjectCount; i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i); if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; LogicUnitProductionComponent unitProductionComponent = building.GetUnitProductionComponent(); if (unitProductionComponent != null) { if (unitProductionComponent.GetProductionType() == productionData.GetCombatItemType()) { if (building.GetBuildingData().GetProducesUnitsOfType() == productionData.GetUnitOfType() && !building.IsUpgrading() && !building.IsConstructing()) { if (productionData.IsUnlockedForProductionHouseLevel(building.GetUpgradeLevel())) { if (productionHouse != null) { int seed = this.m_level.GetPlayerAvatar().GetExpPoints(); if (building.Rand(seed) % 1000 > 750) { productionHouse = building; } } else { productionHouse = building; } } } } } } } } if (productionHouse != null) { LogicUnitStorageComponent unitStorageComponent = (LogicUnitStorageComponent)componentManager.GetClosestComponent(productionHouse.GetX(), productionHouse.GetY(), filter); if (unitStorageComponent != null) { if (unitStorageComponent.CanAddUnit(productionData)) { homeOwnerAvatar.CommodityCountChangeHelper(0, productionData, 1); unitStorageComponent.AddUnit(productionData); if (productionTerminate) { this.RemoveUnit(productionData, -1); } else { this.StartProducingNextUnit(); } success = true; if (this.m_slots.Size() > 0 && this.m_slots[0].IsTerminate() && this.m_slots[0].GetCount() > 0) { continue; } break; } filter.AddIgnoreObject(unitStorageComponent.GetParent()); } else { if (this.m_timer != null && this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime()) == 0) { success = this.TrainingFinished(); } break; } } else { break; } } filter.Destruct(); if (success) { this.m_nextProduction = 0; } else { this.m_nextProduction = 2000; } } return(success); }
public override int Execute(LogicLevel level) { if (this.m_gameObjectIds.Size() > 0) { LogicResourceData ammoResourceData = null; int ammoCost = 0; int idx = 0; do { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[idx]); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; if (building.GetData().GetVillageType() == level.GetVillageType()) { LogicCombatComponent combatComponent = building.GetCombatComponent(false); if (combatComponent != null && combatComponent.UseAmmo()) { if (combatComponent.GetAmmoCount() < combatComponent.GetMaxAmmo() && !building.IsUpgrading()) { LogicBuildingData buildingData = building.GetBuildingData(); ammoResourceData = buildingData.GetAmmoResourceData(0); ammoCost += buildingData.GetAmmoCost(building.GetUpgradeLevel(), combatComponent.GetMaxAmmo() - combatComponent.GetAmmoCount()); } } } else { return(-32); } } } while (++idx < this.m_gameObjectIds.Size()); if (ammoResourceData != null && ammoCost > 0) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(ammoResourceData, ammoCost, true, this, false)) { for (int i = 0; i < this.m_gameObjectIds.Size(); i++) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectIds[i]); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; LogicCombatComponent combatComponent = building.GetCombatComponent(false); if (combatComponent != null && combatComponent.UseAmmo()) { if (combatComponent.GetAmmoCount() < combatComponent.GetMaxAmmo()) { int upgradeLevel = building.GetUpgradeLevel(); LogicBuildingData buildingData = building.GetBuildingData(); LogicResourceData loadAmmoResourceData = buildingData.GetAmmoResourceData(upgradeLevel); int loadAmmoCost = buildingData.GetAmmoCost(upgradeLevel, combatComponent.GetMaxAmmo() - combatComponent.GetAmmoCount()); if (playerAvatar.HasEnoughResources(loadAmmoResourceData, loadAmmoCost, true, this, false)) { playerAvatar.CommodityCountChangeHelper(0, loadAmmoResourceData, -loadAmmoCost); combatComponent.LoadAmmo(); continue; } } } } break; } return(0); } return(-2); } } return(-1); }
public void ReengageLootCart(int secs) { LogicObstacleData obstacleData = this.GetObstacleData(); LogicLootCartComponent lootCartComponent = (LogicLootCartComponent)this.GetComponent(LogicComponentType.LOOT_CART); LogicBuilding townHall = this.m_level.GetGameObjectManagerAt(0).GetTownHall(); Debugger.DoAssert(obstacleData.IsLootCart(), string.Empty); Debugger.DoAssert(lootCartComponent != null, string.Empty); Debugger.DoAssert(townHall != null, string.Empty); LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); LogicTownhallLevelData townhallLevelData = LogicDataTables.GetTownHallLevel(townHall.GetUpgradeLevel()); int cap = secs * townhallLevelData.GetCartLootReengagement(resourceData) / 100; if (cap > lootCartComponent.GetResourceCount(i)) { lootCartComponent.SetResourceCount(i, cap); } } }
/// <summary> /// Gets the unit training time. /// </summary> public int GetTrainingTime(int index, LogicLevel level, int additionalBarrackCount) { int trainingTime = this._trainingTime[index]; if (this.GetVillageType() != 1 && LogicDataTables.GetGlobals().UseNewTraining() && this.GetCombatItemType() == 0) { if (level != null) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); if (this._unitType != 0) { if (this._unitType == 1) { int barrackCount = gameObjectManager.GetBarrackCount(); int barrackFound = 0; if (barrackCount > 0) { int productionLevel = this.GetRequiredProductionHouseLevel(); int idx = 0; do { LogicBuilding barrack = (LogicBuilding)gameObjectManager.GetBarrack(idx); if (barrack != null) { if (barrack.GetBuildingData().GetProducesUnitsOfType() == this.GetUnitOfType()) { if (barrack.GetUpgradeLevel() >= productionLevel) { if (!barrack.IsConstructing()) { barrackFound += 1; } } } } } while (++idx != barrackCount); } if (barrackFound + additionalBarrackCount <= 0) { return(trainingTime); } int[] barrackDivisor = LogicDataTables.GetGlobals().GetBarrackReduceTrainingDevisor(); int divisor = barrackDivisor[LogicMath.Min(barrackDivisor.Length - 1, barrackFound + additionalBarrackCount - 1)]; if (divisor > 0) { return(trainingTime / divisor); } return(trainingTime); } if (this.GetUnitOfType() == 2) { int barrackCount = gameObjectManager.GetDarkBarrackCount(); int barrackFound = 0; if (barrackCount > 0) { int productionLevel = this.GetRequiredProductionHouseLevel(); int idx = 0; do { LogicBuilding barrack = (LogicBuilding)gameObjectManager.GetDarkBarrack(idx); if (barrack != null) { if (barrack.GetBuildingData().GetProducesUnitsOfType() == this.GetCombatItemType()) { if (barrack.GetUpgradeLevel() >= productionLevel) { if (!barrack.IsConstructing()) { barrackFound += 1; } } } } } while (++idx != barrackCount); } if (barrackCount + additionalBarrackCount <= 0) { return(trainingTime); } int[] barrackDivisor = LogicDataTables.GetGlobals().GetDarkBarrackReduceTrainingDevisor(); int divisor = barrackDivisor[LogicMath.Min(barrackDivisor.Length - 1, barrackCount + additionalBarrackCount - 1)]; if (divisor > 0) { return(trainingTime / divisor); } return(trainingTime); } } Debugger.Error("invalid type for unit"); } else { Debugger.Error("level was null in getTrainingTime()"); } } return(trainingTime); }
public int GetTrainingTime(int index, LogicLevel level, int additionalBarrackCount) { int trainingTime = this.m_trainingTime[index]; if (LogicDataTables.GetGlobals().UseNewTraining() && this.GetVillageType() != 1 && this.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { if (level != null) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); switch (this.m_unitType) { case 1: int barrackCount = gameObjectManager.GetBarrackCount(); int productionLevel = this.GetRequiredProductionHouseLevel(); int barrackFound = 0; for (int i = 0; i < barrackCount; i++) { LogicBuilding barrack = (LogicBuilding)gameObjectManager.GetBarrack(i); if (barrack != null) { if (barrack.GetBuildingData().GetProducesUnitsOfType() == this.GetUnitOfType()) { if (barrack.GetUpgradeLevel() >= productionLevel) { if (!barrack.IsConstructing()) { barrackFound += 1; } } } } } if (barrackFound + additionalBarrackCount <= 0) { return(trainingTime); } int[] barrackDivisor = LogicDataTables.GetGlobals().GetBarrackReduceTrainingDevisor(); int divisor = barrackDivisor[LogicMath.Min(barrackDivisor.Length - 1, barrackFound + additionalBarrackCount - 1)]; if (divisor > 0) { return(trainingTime / divisor); } return(trainingTime); case 2: barrackCount = gameObjectManager.GetDarkBarrackCount(); productionLevel = this.GetRequiredProductionHouseLevel(); barrackFound = 0; for (int i = 0; i < barrackCount; i++) { LogicBuilding barrack = (LogicBuilding)gameObjectManager.GetDarkBarrack(i); if (barrack != null) { if (barrack.GetBuildingData().GetProducesUnitsOfType() == this.GetUnitOfType()) { if (barrack.GetUpgradeLevel() >= productionLevel) { if (!barrack.IsConstructing()) { barrackFound += 1; } } } } } if (barrackFound + additionalBarrackCount <= 0) { return(trainingTime); } barrackDivisor = LogicDataTables.GetGlobals().GetDarkBarrackReduceTrainingDevisor(); divisor = barrackDivisor[LogicMath.Min(barrackDivisor.Length - 1, barrackFound + additionalBarrackCount - 1)]; if (divisor > 0) { return(trainingTime / divisor); } return(trainingTime); default: Debugger.Error("invalid type for unit"); break; } } else { Debugger.Error("level was null in getTrainingTime()"); } } return(trainingTime); }
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; LogicBuildingData buildingData = building.GetBuildingData(); if (buildingData.IsTownHallVillage2()) { if (!LogicUpgradeBuildingCommand.CanUpgradeTHV2(level)) { return(-76); } } if (buildingData.GetVillageType() == level.GetVillageType()) { if (level.GetGameObjectManager().GetAvailableBuildingUpgradeCount(building) <= 0) { return(-34); } if (building.GetWallIndex() == 0) { if (building.CanUpgrade(true)) { int nextUpgradeLevel = building.GetUpgradeLevel() + 1; int buildCost = buildingData.GetBuildCost(nextUpgradeLevel, level); LogicResourceData buildResourceData = this.m_useAltResource ? buildingData.GetAltBuildResource(nextUpgradeLevel) : buildingData.GetBuildResource(nextUpgradeLevel); if (buildResourceData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { if (buildingData.GetConstructionTime(nextUpgradeLevel, level, 0) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); building.StartUpgrading(true, false); return(0); } } } return(-1); } return(-35); } return(-32); } if (gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; if (trap.CanUpgrade(true)) { LogicTrapData data = trap.GetTrapData(); LogicResourceData buildResourceData = data.GetBuildResource(); LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); int buildCost = data.GetBuildCost(trap.GetUpgradeLevel() + 1); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { if (data.GetBuildTime(trap.GetUpgradeLevel() + 1) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); trap.StartUpgrading(); return(0); } } } else if (gameObject.GetGameObjectType() == LogicGameObjectType.VILLAGE_OBJECT) { if (!this.m_useAltResource) { LogicVillageObject villageObject = (LogicVillageObject)gameObject; if (villageObject.CanUpgrade(true)) { LogicVillageObjectData data = villageObject.GetVillageObjectData(); LogicResourceData buildResourceData = data.GetBuildResource(); int buildCost = data.GetBuildCost(villageObject.GetUpgradeLevel() + 1); if (buildResourceData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { if (data.GetBuildTime(villageObject.GetUpgradeLevel() + 1) != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); villageObject.StartUpgrading(true); return(0); } } } return(-1); } return(-31); } } return(-1); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { if (this._gameObjectIds.Count > 0) { LogicResourceData buildResourceData = null; int buildCost = 0; for (int i = 0; i < this._gameObjectIds.Count; i++) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectIds[i]); if (gameObject != null && gameObject.GetGameObjectType() == 0) { LogicBuilding building = (LogicBuilding)gameObject; LogicBuildingData buildingData = building.GetBuildingData(); int upgradeLevel = building.GetUpgradeLevel(); if (buildingData.IsTownHallVillage2()) { return(-76); } if (building.CanUpgrade(false) && buildingData.GetUpgradeLevelCount() > upgradeLevel + 1 && buildingData.GetAmountCanBeUpgraded(0) == 0) { buildResourceData = buildingData.GetBuildResource(upgradeLevel + 1); if (this._useAltResources) { buildResourceData = buildingData.GetAltBuildResource(upgradeLevel + 1); } buildCost += buildingData.GetBuildCost(upgradeLevel + 1, level); } } } if (buildResourceData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { if (level.HasFreeWorkers(this, -1)) { bool ignoreState = true; for (int i = 0; i < this._gameObjectIds.Count; i++) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectIds[i]); if (gameObject != null && gameObject.GetGameObjectType() == 0) { LogicBuilding building = (LogicBuilding)gameObject; LogicBuildingData buildingData = building.GetBuildingData(); int upgradeLevel = building.GetUpgradeLevel(); if (building.CanUpgrade(false) && buildingData.GetUpgradeLevelCount() > upgradeLevel + 1 && buildingData.GetAmountCanBeUpgraded(0) == 0) { if (this._gameObjectIds.Count > 6) { ignoreState = (building.GetTileX() + building.GetTileY()) % (this._gameObjectIds.Count / 4) == 0; } building.StartUpgrading(ignoreState, false); } } } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); return(0); } } } } return(-2); }
/// <summary> /// Executes this command. /// </summary> public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this._gameObjectId); if (gameObject != null) { if (gameObject.GetGameObjectType() == 0) { LogicBuilding building = (LogicBuilding)gameObject; LogicBuildingData buildingData = building.GetBuildingData(); if (buildingData.IsTownHallVillage2()) { if (!this.UnlockVillage2()) { return(-76); } } if (buildingData.GetVillageType() == level.GetVillageType()) { if (building.GetWallIndex() == 0) { if (building.CanUpgrade(true)) { int nextUpgradeLevel = building.GetUpgradeLevel() + 1; int buildCost = buildingData.GetBuildCost(nextUpgradeLevel, level); LogicResourceData buildResourceData = this._useAltResources ? buildingData.GetAltBuildResource(nextUpgradeLevel) : buildingData.GetBuildResource(nextUpgradeLevel); if (buildResourceData != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { int constructionTime = buildingData.GetConstructionTime(nextUpgradeLevel, level, 0); if (constructionTime != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); building.StartUpgrading(true, false); return(0); } } } return(-1); } return(-35); } return(-32); } else if (gameObject.GetGameObjectType() == 4) { LogicTrap trap = (LogicTrap)gameObject; if (trap.CanUpgrade(true)) { LogicTrapData data = trap.GetTrapData(); LogicResourceData buildResourceData = data.GetBuildResource(); LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); int buildCost = data.GetBuildCost(trap.GetUpgradeLevel() + 1); if (playerAvatar.HasEnoughResources(buildResourceData, buildCost, true, this, false)) { int constructionTime = data.GetBuildTime(trap.GetUpgradeLevel() + 1); if (constructionTime != 0 || LogicDataTables.GetGlobals().WorkerForZeroBuilTime()) { if (!level.HasFreeWorkers(this, -1)) { return(-1); } playerAvatar.CommodityCountChangeHelper(0, buildResourceData, -buildCost); trap.StartUpgrading(); return(0); } } } } else if (gameObject.GetGameObjectType() == 8) { if (!this._useAltResources) { LogicVillageObject villageObject = (LogicVillageObject)gameObject; // TODO: Implement upgrade vObjs. } return(-31); } } return(-1); }
public override int Execute(LogicLevel level) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { if (this.m_unitData != null) { if (this.m_unitData.GetVillageType() == 0) { if (!this.m_unitData.IsDonationDisabled()) { bool containsUnit = false; int upgLevel = playerAvatar.GetUnitUpgradeLevel(this.m_unitData); LogicUnitProductionComponent unitProductionComponent = null; if (this.m_quickDonate) { int cost = this.m_unitData.GetDonateCost(); if (!playerAvatar.HasEnoughDiamonds(cost, true, level) || !LogicDataTables.GetGlobals().EnableQuickDonateWar()) { playerAvatar.GetChangeListener().WarDonateFailed(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate); return(0); } } else { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); if (LogicDataTables.GetGlobals().UseNewTraining()) { LogicUnitProduction unitProduction = gameObjectManager.GetUnitProduction(); LogicUnitProduction spellProduction = gameObjectManager.GetSpellProduction(); if (unitProduction.GetWaitingForSpaceUnitCount(this.m_unitData) > 0) { if (unitProduction.GetUnitProductionType() == this.m_unitData.GetDataType()) { containsUnit = true; } } if (spellProduction.GetWaitingForSpaceUnitCount(this.m_unitData) > 0) { if (spellProduction.GetUnitProductionType() == this.m_unitData.GetDataType()) { containsUnit = true; } } } else { for (int i = 0, c = gameObjectManager.GetNumGameObjects(); i < c; i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i); if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; LogicUnitProductionComponent component = building.GetUnitProductionComponent(); if (component != null) { unitProductionComponent = component; if (component.ContainsUnit(this.m_unitData)) { if (component.GetRemainingSeconds() == 0 && component.GetCurrentlyTrainedUnit() == this.m_unitData) { containsUnit = true; } } else { unitProductionComponent = null; } } } } } if (!containsUnit) { if (playerAvatar.GetUnitCount(this.m_unitData) <= 0) { playerAvatar.GetChangeListener().WarDonateFailed(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate); return(0); } } } if (this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { playerAvatar.XpGainHelper(this.m_unitData.GetHousingSpace() * LogicDataTables.GetGlobals().GetDarkSpellDonationXP()); level.GetAchievementManager().AlianceSpellDonated((LogicSpellData)this.m_unitData); } else { playerAvatar.XpGainHelper(((LogicCharacterData)this.m_unitData).GetDonateXP()); level.GetAchievementManager().AlianceUnitDonated((LogicCharacterData)this.m_unitData); } playerAvatar.GetChangeListener().WarDonateOk(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate); if (this.m_quickDonate) { int cost = this.m_unitData.GetDonateCost(); playerAvatar.UseDiamonds(cost); playerAvatar.GetChangeListener().DiamondPurchaseMade(12, this.m_unitData.GetGlobalID(), 0, cost, level.GetVillageType()); if (level.GetState() == 1 || level.GetState() == 3 && this.m_unitData.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { // TODO: Finish this. } } else { if (!containsUnit) { playerAvatar.CommodityCountChangeHelper(0, this.m_unitData, -1); } LogicResourceData trainingResource = this.m_unitData.GetTrainingResource(); int trainingCost = level.GetGameMode().GetCalendar().GetTrainingCost(this.m_unitData, upgLevel); int refund = playerAvatar.GetTroopDonationRefund() * trainingCost / 100; playerAvatar.CommodityCountChangeHelper(0, trainingResource, LogicMath.Max(refund, 0)); if (level.GetState() == 1 || level.GetState() == 3) { if (containsUnit) { if (LogicDataTables.GetGlobals().UseNewTraining()) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); LogicUnitProduction unitProduction = this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER ? gameObjectManager.GetSpellProduction() : gameObjectManager.GetUnitProduction(); unitProduction.RemoveTrainedUnit(this.m_unitData); } if (this.m_unitData.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { LogicBuilding productionHouse = null; if (unitProductionComponent != null) { productionHouse = (LogicBuilding)unitProductionComponent.GetParent(); } else { if (LogicDataTables.GetGlobals().UseTroopWalksOutFromTraining()) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); int gameObjectCount = gameObjectManager.GetNumGameObjects(); for (int i = 0; i < gameObjectCount; i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding tmpBuilding = (LogicBuilding)gameObject; LogicUnitProductionComponent tmpComponent = tmpBuilding.GetUnitProductionComponent(); if (tmpComponent != null) { if (tmpComponent.GetProductionType() == this.m_unitData.GetCombatItemType()) { if (tmpBuilding.GetBuildingData().GetProducesUnitsOfType() == this.m_unitData.GetUnitOfType() && !tmpBuilding.IsUpgrading() && !tmpBuilding.IsConstructing()) { if (this.m_unitData.IsUnlockedForProductionHouseLevel(tmpBuilding.GetUpgradeLevel())) { if (productionHouse != null) { int seed = playerAvatar.GetExpPoints(); if (tmpBuilding.Rand(seed) % 1000 > 750) { productionHouse = tmpBuilding; } } else { productionHouse = tmpBuilding; } } } } } } } } } if (productionHouse != null) { // TODO: Implement listener. } } } else { LogicArrayList <LogicComponent> components = level.GetComponentManagerAt(0).GetComponents(LogicComponentType.UNIT_STORAGE); for (int i = 0; i < components.Size(); i++) { LogicUnitStorageComponent unitStorageComponent = (LogicUnitStorageComponent)components[i]; int idx = unitStorageComponent.GetUnitTypeIndex(this.m_unitData); if (idx != -1) { if (unitStorageComponent.GetUnitCount(idx) > 0) { unitStorageComponent.RemoveUnits(this.m_unitData, 1); if (LogicDataTables.GetGlobals().UseNewTraining()) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); LogicUnitProduction unitProduction = this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER ? gameObjectManager.GetSpellProduction() : gameObjectManager.GetUnitProduction(); unitProduction.MergeSlots(); unitProduction.UnitRemoved(); } break; } } } } // TODO: Finish this. } } return(0); } return(-91); } return(-45); } } return(0); }
public override int Execute(LogicLevel level) { LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; LogicBuildingData buildingData = building.GetBuildingData(); if (buildingData.GetVillageType() == level.GetVillageType()) { if (!level.IsBuildingGearUpCapReached(buildingData, true)) { if (building.GetGearLevel() == 0) { int upgLevel = building.GetUpgradeLevel(); int gearUpCost = buildingData.GetGearUpCost(upgLevel); if (gearUpCost > 0) { if (upgLevel >= buildingData.GetMinUpgradeLevelForGearUp()) { if (level.GetGameObjectManagerAt(1).GetHighestBuildingLevel(buildingData.GetGearUpBuildingData()) < buildingData.GetGearUpLevelRequirement()) { return(-1); } LogicResourceData gearUpResource = buildingData.GetGearUpResource(); if (gearUpResource != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar.HasEnoughResources(gearUpResource, gearUpCost, true, this, false)) { if (level.HasFreeWorkers(this, 1)) { playerAvatar.CommodityCountChangeHelper(0, gearUpResource, -gearUpCost); building.StartUpgrading(true, true); return(0); } } } return(-1); } return(-37); } return(-36); } return(-35); } return(-31); } return(-32); } return(-1); }
public static float GetDefenseStrength(LogicArrayList <LogicGameObject> buildings, LogicArrayList <LogicGameObject> traps, LogicArrayList <LogicHeroData> heroes, int[] heroUpgLevel) { float heroStrength = 0f; float buildingStrength = 0f; float trapStrength = 0; for (int i = 0; i < heroes.Size(); i++) { heroStrength += LogicStrengthUtil.GetHeroStrength(heroes[i], heroUpgLevel[i], true); } for (int i = 0; i < buildings.Size(); i++) { LogicBuilding building = (LogicBuilding)buildings[i]; if (!building.IsLocked()) { if (!building.IsConstructing() || building.IsUpgrading()) { buildingStrength += LogicStrengthUtil.GetBuildingStrength(building.GetBuildingData(), building.GetUpgradeLevel()); } } } for (int i = 0; i < traps.Size(); i++) { LogicTrap trap = (LogicTrap)traps[i]; if (!trap.IsConstructing() || trap.IsUpgrading()) { trapStrength += LogicStrengthUtil.GetTrapStrength(trap.GetTrapData(), trap.GetUpgradeLevel()); } } return(buildingStrength + trapStrength + heroStrength); }
/// <summary> /// Refreshes the mission progress. /// </summary> public void RefreshProgress() { LogicGameObjectManager gameObjectManager = this._level.GetGameObjectManager(); switch (this._data.GetMissionType()) { case 0: case 5: this._progress = 0; if (this._level.GetState() == 1) { LogicArrayList <LogicGameObject> gameObjects = gameObjectManager.GetGameObjects(0); for (int i = 0; i < gameObjects.Count; i++) { LogicBuilding building = (LogicBuilding)gameObjects[i]; if (building.GetBuildingData() == this._data.GetBuildBuildingData()) { if (!building.IsConstructing() || building.IsUpgrading()) { if (building.GetUpgradeLevel() >= this._data.GetBuildBuildingLevel()) { ++this._progress; } } } } } break; case 4: this._progress = this._level.GetPlayerAvatar().GetUnitsTotalCapacity(); break; case 6: this._progress = this._level.GetPlayerAvatar().GetNameSetByUser() ? 1 : 0; break; case 13: this._progress = 0; if (this._level.GetState() == 1) { LogicArrayList <LogicGameObject> gameObjects = gameObjectManager.GetGameObjects(8); for (int i = 0; i < gameObjects.Count; i++) { LogicVillageObject villageObject = (LogicVillageObject)gameObjects[i]; if (villageObject.GetVillageObjectData() == this._data.GetFixVillageObjectData() && villageObject.GetUpgradeLevel() >= this._data.GetBuildBuildingLevel()) { ++this._progress; } } } break; case 14: this._progress = 0; if (this._level.GetState() == 1 && this._level.GetVillageType() == 1) { ++this._progress; } break; case 15: this._progress = 0; if (this._level.GetState() == 1) { LogicArrayList <LogicGameObject> gameObjects = gameObjectManager.GetGameObjects(0); for (int i = 0; i < gameObjects.Count; i++) { LogicBuilding building = (LogicBuilding)gameObjects[i]; if (building.GetBuildingData() == this._data.GetBuildBuildingData()) { if (!building.IsLocked()) { ++this._progress; } } } } break; case 17: this._progress = 0; if (this._level.GetState() == 1 && this._level.GetVillageType() == 1) { if (this._level.GetPlayerAvatar().GetUnitUpgradeLevel(this._data.GetCharacterData()) > 0) { ++this._progress; } } break; } if (this._progress >= this._requireProgress) { this._progress = this._requireProgress; this.Finished(); } }
public static LogicClientHome GenerateBase(LogicGameObjectData gameObjectData) { LogicClientHome logicClientHome = new LogicClientHome(); LogicGameMode logicGameMode = new LogicGameMode(); LogicLevel logicLevel = logicGameMode.GetLevel(); LogicGameObjectManager logicGameObjectManager = logicLevel.GetGameObjectManagerAt(0); logicLevel.SetLoadingVillageType(-1); logicLevel.SetVillageType(0); logicLevel.SetExperienceVersion(1); logicLevel.SetHomeOwnerAvatar(GameBaseGenerator.HomeOwnerAvatar); LogicBuilding townHall = new LogicBuilding(LogicDataTables.GetTownHallData(), logicLevel, 0); townHall.SetInitialPosition((LogicLevel.TILEMAP_SIZE_X / 2 - townHall.GetWidthInTiles() / 2) << 9, (LogicLevel.TILEMAP_SIZE_Y / 2 - townHall.GetHeightInTiles() / 2) << 9); townHall.SetUpgradeLevel(townHall.GetBuildingData().GetUpgradeLevelCount() - 1); logicGameObjectManager.AddGameObject(townHall, -1); LogicTownhallLevelData townhallLevelData = LogicDataTables.GetTownHallLevel(townHall.GetUpgradeLevel()); if (gameObjectData == null) { LogicArrayList <LogicGameObject> scrambler = new LogicArrayList <LogicGameObject>(); for (int i = 0; i < GameBaseGenerator.m_defenseBuildingArray.Size(); i++) { LogicBuildingData buildingData = GameBaseGenerator.m_defenseBuildingArray[i]; for (int j = townhallLevelData.GetUnlockedBuildingCount(buildingData); j > 0; j--) { LogicBuilding logicBuilding = (LogicBuilding)GameBaseGenerator.CreateAndPlaceRandomlyGameObject(buildingData, logicLevel, buildingData.GetWidth(), buildingData.GetHeight(), 0); if (logicBuilding != null) { logicBuilding.SetLocked(false); logicBuilding.SetUpgradeLevel(buildingData.GetUpgradeLevelCount() - 1); scrambler.Add(logicBuilding); int upgradeLevel = buildingData.GetUpgradeLevelCount() - 1; int minUpgradeLevelForGearUp = buildingData.GetMinUpgradeLevelForGearUp(); if (minUpgradeLevelForGearUp > -1 && upgradeLevel >= minUpgradeLevelForGearUp) { if (GameBaseGenerator.m_random.Rand(100) >= 50) { logicBuilding.SetGearLevel(1); } } if (buildingData.GetAttackerItemData(upgradeLevel).GetTargetingConeAngle() != 0) { logicBuilding.GetCombatComponent().ToggleAimAngle(buildingData.GetAimRotateStep() * GameBaseGenerator.m_random.Rand(360 / buildingData.GetAimRotateStep()), 0, false); } if (buildingData.GetAttackerItemData(upgradeLevel).HasAlternativeAttackMode()) { if (minUpgradeLevelForGearUp > -1 && logicBuilding.GetGearLevel() != 1) { continue; } if (GameBaseGenerator.m_random.Rand(100) >= 50) { logicBuilding.GetCombatComponent().ToggleAttackMode(0, false); } } } } } for (int i = 0; i < GameBaseGenerator.m_otherBuildingArray.Size(); i++) { LogicBuildingData buildingData = GameBaseGenerator.m_otherBuildingArray[i]; for (int j = townhallLevelData.GetUnlockedBuildingCount(buildingData); j > 0; j--) { LogicBuilding logicBuilding = (LogicBuilding)GameBaseGenerator.CreateAndPlaceRandomlyGameObject(buildingData, logicLevel, buildingData.GetWidth(), buildingData.GetHeight(), 0); if (logicBuilding != null) { logicBuilding.SetLocked(false); logicBuilding.SetUpgradeLevel(buildingData.GetUpgradeLevelCount() - 1); scrambler.Add(logicBuilding); } } } for (int i = 0; i < GameBaseGenerator.m_trapArray.Size(); i++) { LogicTrapData trapData = (LogicTrapData)GameBaseGenerator.m_trapArray[i]; for (int j = townhallLevelData.GetUnlockedTrapCount(trapData); j > 0; j--) { LogicTrap trap = (LogicTrap)GameBaseGenerator.CreateAndPlaceRandomlyGameObject(trapData, logicLevel, trapData.GetWidth(), trapData.GetHeight(), 0); if (trap != null) { trap.SetUpgradeLevel(trapData.GetUpgradeLevelCount() - 1); scrambler.Add(trap); } } } for (int i = 0; i < scrambler.Size(); i++) { LogicGameObject gameObject = scrambler[i]; LogicData data = gameObject.GetData(); int width = gameObject.GetWidthInTiles(); int height = gameObject.GetHeightInTiles(); int x = gameObject.GetX(); int y = gameObject.GetY(); LogicArrayList <LogicGameObject> available = new LogicArrayList <LogicGameObject>(); for (int j = i + 1; j < scrambler.Size(); j++) { if (data != scrambler[j].GetData()) { if (scrambler[j].GetWidthInTiles() == width && scrambler[j].GetHeightInTiles() == height) { available.Add(scrambler[j]); } } } if (available.Size() != 0) { LogicGameObject swapObj = available[GameBaseGenerator.m_random.Rand(available.Size())]; gameObject.SetInitialPosition(swapObj.GetX(), swapObj.GetY()); swapObj.SetInitialPosition(x, y); } } } else { int maxUpgradeLevel = 0; int width = 1; int height = 1; switch (gameObjectData.GetDataType()) { case LogicDataType.BUILDING: { LogicBuildingData logicBuildingData = (LogicBuildingData)gameObjectData; maxUpgradeLevel = logicBuildingData.GetUpgradeLevelCount(); width = logicBuildingData.GetWidth(); height = logicBuildingData.GetHeight(); break; } case LogicDataType.TRAP: LogicTrapData logicTrapData = (LogicTrapData)gameObjectData; maxUpgradeLevel = logicTrapData.GetUpgradeLevelCount(); width = logicTrapData.GetWidth(); height = logicTrapData.GetHeight(); break; } int upgLevel = maxUpgradeLevel - 1; int x = 0; int y = 0; while (true) { LogicBuilding building = (LogicBuilding)GameBaseGenerator.CreateGameObjectIfAnyPlaceExist(gameObjectData, logicLevel, width, height, 0, x, y); if (building == null) { break; } building.SetLocked(false); building.SetUpgradeLevel(upgLevel != -1 ? upgLevel : GameBaseGenerator.m_random.Rand(building.GetUpgradeLevel())); x = building.GetTileX(); y = building.GetTileY(); } } for (int i = 0; i < 10; i++) { logicGameObjectManager.Village1CreateObstacle(); } LogicJSONObject jsonObject = new LogicJSONObject(); logicGameMode.SaveToJSON(jsonObject); logicGameMode.Destruct(); logicClientHome.SetHomeJSON(LogicJSONParser.CreateJSONString(jsonObject, 2048)); CompressibleStringHelper.Compress(logicClientHome.GetCompressibleHomeJSON()); return(logicClientHome); }