public void AddUnitsToQueue(LogicCombatItemData data, int count) { LogicCalendar calendar = this.m_level.GetCalendar(); LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar(); LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0); LogicUnitProduction production = gameObjectManager.GetUnitProduction(); if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_SPELL) { return; } production = gameObjectManager.GetSpellProduction(); } if (production != null) { int trainCost = calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data)); for (int i = 0; i < count; i++) { if (production.CanAddUnitToQueue(data, true) && playerAvatar.HasEnoughResources(data.GetTrainingResource(), trainCost, false, null, false)) { playerAvatar.CommodityCountChangeHelper(0, data.GetTrainingResource(), -trainCost); production.AddUnitToQueue(data, production.GetSlotCount(), true); } } } }
public void Dispose() { Timer.Stop(); Timer = null; Device = null; LogicGameObjectManager = null; Units = null; }
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) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicGameObjectManager gameObjectManager = level.GetGameObjectManager(); LogicResourceData repairResourceData = null; int repairCost = 0; for (int i = 0; i < this.m_gameObjectIds.Size(); i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectIds[i]); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; if (trap.IsDisarmed() && !trap.IsConstructing()) { LogicTrapData data = trap.GetTrapData(); repairResourceData = data.GetBuildResource(); repairCost += data.GetRearmCost(trap.GetUpgradeLevel()); } } } if (repairResourceData != null && repairCost != 0) { if (playerAvatar.HasEnoughResources(repairResourceData, repairCost, true, this, false)) { playerAvatar.CommodityCountChangeHelper(0, repairResourceData, -repairCost); for (int i = 0; i < this.m_gameObjectIds.Size(); i++) { LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectIds[i]); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.TRAP) { LogicTrap trap = (LogicTrap)gameObject; if (trap.IsDisarmed() && !trap.IsConstructing()) { trap.RepairTrap(); } } } return(0); } return(-2); } return(-1); }
public void Dispose() { Device = null; Units = null; Battle = null; Stream = null; HeroManager = null; Achievements = null; ResourcesManager = null; LogicGameObjectManager = null; }
public static void LoadDebugJSONArray(LogicLevel level, LogicJSONArray jsonArray, LogicGameObjectType gameObjectType, int villageType) { if (jsonArray != null) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(villageType); LogicArrayList <LogicGameObject> prevGameObjects = new LogicArrayList <LogicGameObject>(); prevGameObjects.AddAll(gameObjectManager.GetGameObjects(gameObjectType)); for (int i = 0; i < prevGameObjects.Size(); i++) { gameObjectManager.RemoveGameObject(prevGameObjects[i]); } for (int i = 0; i < jsonArray.Size(); i++) { LogicJSONObject jsonObject = jsonArray.GetJSONObject(i); LogicJSONNumber dataNumber = jsonObject.GetJSONNumber("data"); LogicJSONNumber lvlNumber = jsonObject.GetJSONNumber("lvl"); LogicJSONBoolean lockedBoolean = jsonObject.GetJSONBoolean("locked"); LogicJSONNumber xNumber = jsonObject.GetJSONNumber("x"); LogicJSONNumber yNumber = jsonObject.GetJSONNumber("y"); if (dataNumber != null && xNumber != null && yNumber != null) { LogicGameObjectData data = (LogicGameObjectData)LogicDataTables.GetDataById(dataNumber.GetIntValue()); if (data != null) { LogicGameObject gameObject = LogicGameObjectFactory.CreateGameObject(data, level, villageType); if (gameObjectType == LogicGameObjectType.BUILDING) { ((LogicBuilding)gameObject).StartConstructing(true); } if (lockedBoolean != null && lockedBoolean.IsTrue()) { ((LogicBuilding)gameObject).Lock(); } gameObject.Load(jsonObject); gameObjectManager.AddGameObject(gameObject, -1); if (lvlNumber != null) { LogicDebugUtil.SetBuildingUpgradeLevel(level, gameObject.GetGlobalID(), lvlNumber.GetIntValue(), villageType); } } } } } }
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 override void FastForwardTime(int time) { while (time > 0) { LogicGameObjectManager gameObjectManager = this.m_parent.GetGameObjectManager(); for (int i = 0; i < this.m_spawned.Size(); i++) { if (gameObjectManager.GetGameObjectByID(this.m_spawned[i]) == null) { this.m_spawned.Remove(i--); } } if (this.m_lifeTimeSpawns < this.m_maxLifetimeSpawns && this.m_spawned.Size() < this.m_maxSpawned) { if (this.m_timer == null) { this.m_timer = new LogicTimer(); this.m_timer.StartTimer(this.m_intervalSeconds, this.m_parent.GetLevel().GetLogicTime(), false, -1); } int remainingSeconds = this.m_timer.GetRemainingSeconds(this.m_parent.GetLevel().GetLogicTime()); if (time < remainingSeconds) { break; } this.m_timer.FastForward(remainingSeconds); this.Spawn(); this.m_timer.StartTimer(this.m_intervalSeconds, this.m_parent.GetLevel().GetLogicTime(), false, -1); time -= remainingSeconds; } else { if (this.m_timer != null) { this.m_timer.Destruct(); this.m_timer = null; } break; } } }
public void AddAvatarAllianceUnitsToCastle() { LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0); LogicBuilding allianceCastle = gameObjectManager.GetAllianceCastle(); if (allianceCastle != null) { LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent(); if (bunkerComponent != null) { bunkerComponent.RemoveAllUnits(); LogicArrayList <LogicUnitSlot> units = this.m_level.GetHomeOwnerAvatar().GetAllianceUnits(); for (int i = 0; i < units.Size(); i++) { LogicUnitSlot unitSlot = units[i]; LogicCombatItemData data = (LogicCombatItemData)unitSlot.GetData(); int count = unitSlot.GetCount(); if (data != null) { if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { for (int j = 0; j < count; j++) { if (bunkerComponent.GetUnusedCapacity() >= data.GetHousingSpace()) { bunkerComponent.AddUnitImpl(data, unitSlot.GetLevel()); } } } } else { Debugger.Error("LogicComponentManager::addAvatarAllianceUnitsToCastle - NULL character"); } } } } }
public override int Execute(LogicLevel level) { if (LogicDataTables.GetGlobals().UseTroopRequestSpeedUp()) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0); LogicBuilding allianceCastle = gameObjectManager.GetAllianceCastle(); if (allianceCastle != null) { LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent(); if (bunkerComponent != null) { if (playerAvatar.GetAllianceCastleUsedCapacity() < playerAvatar.GetAllianceCastleTotalCapacity() || playerAvatar.GetAllianceCastleUsedSpellCapacity() < playerAvatar.GetAllianceCastleTotalSpellCapacity()) { int speedUpCost = LogicGamePlayUtil.GetSpeedUpCost(bunkerComponent.GetRequestCooldownTime(), 3, 0); if (playerAvatar.HasEnoughDiamonds(speedUpCost, true, level)) { playerAvatar.UseDiamonds(speedUpCost); playerAvatar.GetChangeListener().DiamondPurchaseMade(11, 0, 0, speedUpCost, level.GetVillageType()); bunkerComponent.StopRequestCooldownTime(); return(0); } return(-6); } return(-5); } return(-4); } return(-3); } return(-1); }
/// <summary> /// Gets if this mission is a open tutorial mission. /// </summary> public bool IsOpenTutorialMission() { if (this._data.GetVillageType() == this._level.GetVillageType()) { if (this._data.GetMissionCategory() == 2) { LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar(); if (homeOwnerAvatar == null || !homeOwnerAvatar.IsNpcAvatar() || this._level.GetVillageType() != -1) { LogicGameObjectManager gameObjectManager = this._level.GetGameObjectManagerAt(0); if (gameObjectManager.GetShipyard() == null || gameObjectManager.GetShipyard().GetUpgradeLevel() != 0) { int missionType = this._data.GetMissionType(); if ((missionType == 16 || missionType == 14) && this._level.GetState() == 1 && this._level.GetVillageType() == 0) { if (gameObjectManager.GetShipyard().IsConstructing()) { return(false); } } return(this._data.GetMissionCategory() != 1); } } return(true); } else { return(this._data.GetMissionCategory() != 1); } } else { return(false); } }
public override int Execute(LogicLevel level) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManager(); LogicGameObject gameObject = gameObjectManager.GetGameObjectByID(this.m_gameObjectId); if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING) { LogicBuilding building = (LogicBuilding)gameObject; LogicVillage2UnitComponent village2UnitComponent = building.GetVillage2UnitComponent(); if (village2UnitComponent != null) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); playerAvatar.CommodityCountChangeHelper(7, village2UnitComponent.GetUnitData(), -village2UnitComponent.GetUnitCount()); village2UnitComponent.RemoveUnits(); return(0); } } return(-1); }
public override int Execute(LogicLevel level) { LogicClientAvatar playerAvatar = level.GetPlayerAvatar(); if (playerAvatar != null) { LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(1); if (gameObjectManager.GetTownHall() == null) { LogicJSONObject jsonObject = level.GetGameListener().ParseCompressedHomeJSON(this.m_compressedHomeJSON, this.m_compressedHomeJSON.Length); level.SetLoadingVillageType(1); this.LoadGameObjectsJsonArray(level, jsonObject.GetJSONArray("buildings2"), 1); this.LoadGameObjectsJsonArray(level, jsonObject.GetJSONArray("obstacles2"), 1); this.LoadGameObjectsJsonArray(level, jsonObject.GetJSONArray("traps2"), 1); this.LoadGameObjectsJsonArray(level, jsonObject.GetJSONArray("decos2"), 1); level.SetLoadingVillageType(-1); if (playerAvatar.GetResourceCount(LogicDataTables.GetGold2Data()) == 0) { playerAvatar.CommodityCountChangeHelper(0, LogicDataTables.GetGold2Data(), LogicDataTables.GetGlobals().GetStartingGold2()); } if (playerAvatar.GetResourceCount(LogicDataTables.GetElixir2Data()) == 0) { playerAvatar.CommodityCountChangeHelper(0, LogicDataTables.GetElixir2Data(), LogicDataTables.GetGlobals().GetStartingElixir2()); } } return(0); } return(-1); }
public LogicCharacter ClosestAttacker(bool flyingTroop) { LogicGameObjectManager gameObjectManager = this.m_parent.GetLevel().GetGameObjectManagerAt(0); LogicArrayList <LogicGameObject> gameObjects = gameObjectManager.GetGameObjects(LogicGameObjectType.CHARACTER); int closestDistance = 0x7fffffff; LogicCharacter closestCharacter = null; for (int i = 0; i < gameObjects.Size(); i++) { LogicCharacter character = (LogicCharacter)gameObjects[i]; LogicHitpointComponent hitpointComponent = character.GetHitpointComponent(); LogicCombatComponent combatComponent = character.GetCombatComponent(); bool deployTime = combatComponent != null && combatComponent.GetUndergroundTime() > 0; if (!deployTime && (LogicDataTables.GetGlobals().SkeletonOpenClanCastle() || !LogicDataTables.IsSkeleton(character.GetCharacterData()))) { if (hitpointComponent != null) { if (character.IsAlive() && character.IsFlying() == flyingTroop && hitpointComponent.GetTeam() == 0) { int distance = character.GetPosition().GetDistanceSquaredTo(this.m_parent.GetMidX(), this.m_parent.GetMidY()); if (distance < closestDistance) { closestDistance = distance; closestCharacter = character; } } } } } return(closestCharacter); }
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 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); }
/// <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); }
private void SimulateEndAttackState() { LogicLevel level = this.m_logicGameMode.GetLevel(); LogicGameObjectManager gameObjectManager = level.GetGameObjectManager(); LogicArrayList <LogicGameObject> characterList = gameObjectManager.GetGameObjects(LogicGameObjectType.CHARACTER); LogicArrayList <LogicGameObject> projectileList = gameObjectManager.GetGameObjects(LogicGameObjectType.PROJECTILE); LogicArrayList <LogicGameObject> spellList = gameObjectManager.GetGameObjects(LogicGameObjectType.SPELL); LogicArrayList <LogicGameObject> alliancePortalList = gameObjectManager.GetGameObjects(LogicGameObjectType.ALLIANCE_PORTAL); this.m_logicWatch.Start(); while (!this.m_logicGameMode.IsBattleOver()) { bool canStopBattle = !this.m_logicGameMode.GetConfiguration().GetBattleWaitForProjectileDestruction() || projectileList.Size() == 0; for (int i = 0; i < characterList.Size(); i++) { LogicCharacter character = (LogicCharacter)characterList[i]; LogicHitpointComponent hitpointComponent = character.GetHitpointComponent(); if (hitpointComponent != null && hitpointComponent.GetTeam() == 0) { LogicAttackerItemData data = character.GetAttackerItemData(); if (data.GetDamage(0, false) > 0 && (hitpointComponent.GetHitpoints() > 0 || this.m_logicGameMode.GetConfiguration().GetBattleWaitForDieDamage() && character.GetWaitDieDamage())) { canStopBattle = false; } } } for (int i = 0; i < spellList.Size(); i++) { LogicSpell spell = (LogicSpell)spellList[i]; if (!spell.GetHitsCompleted() && (spell.GetSpellData().IsDamageSpell() || spell.GetSpellData().GetSummonTroop() != null)) { canStopBattle = false; } } for (int i = 0; i < alliancePortalList.Size(); i++) { LogicAlliancePortal alliancePortal = (LogicAlliancePortal)alliancePortalList[i]; if (alliancePortal.GetBunkerComponent().GetTeam() == 0 && !alliancePortal.GetBunkerComponent().IsEmpty()) { canStopBattle = false; } } bool isEnded = canStopBattle || this.m_logicWatch.ElapsedMilliseconds >= 10000; if (isEnded) { LogicEndCombatCommand logicEndCombatCommand = new LogicEndCombatCommand(); logicEndCombatCommand.SetExecuteSubTick(this.m_logicGameMode.GetLevel().GetLogicTime().GetTick()); this.m_logicGameMode.GetCommandManager().AddCommand(logicEndCombatCommand); } this.m_logicGameMode.UpdateOneSubTick(); if (isEnded) { break; } } this.m_logicWatch.Reset(); if (!this.m_logicGameMode.IsBattleOver()) { this.m_logicGameMode.SetBattleOver(); } if (this.m_liveReplayId != null) { this.UpdateLiveReplay(this.m_logicGameMode.GetLevel().GetLogicTime().GetTick(), null); } }
public void SetBattleOver() { if (this.m_battleOver) { return; } this.m_level.GetBattleLog().SetBattleEnded(LogicDataTables.GetGlobals().GetAttackLengthSecs() - this.GetRemainingAttackSeconds()); this.m_level.GetMissionManager().Tick(); LogicArrayList <LogicComponent> components = this.m_level.GetComponentManager().GetComponents(LogicComponentType.COMBAT); for (int i = 0; i < components.Size(); i++) { ((LogicCombatComponent)components[i]).Boost(0, 0, 0); } bool duelMatch = (this.m_level.GetMatchType() & 0xFFFFFFFE) == 8; if (duelMatch) { LogicAvatar avatar = this.m_level.GetVisitorAvatar(); if (avatar != null && avatar.IsClientAvatar()) { ((LogicClientAvatar)avatar).RemoveUnitsVillage2(); } } if (this.m_state == 3) { this.EndDefendState(); } else { LogicBattleLog battleLog = this.m_level.GetBattleLog(); if (battleLog.GetBattleStarted()) { LogicAvatar visitorAvatar = this.m_level.GetVisitorAvatar(); LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); int stars = battleLog.GetStars(); if (!this.m_level.GetVisitorAvatar().IsClientAvatar() || !this.m_level.GetHomeOwnerAvatar().IsClientAvatar()) { if (visitorAvatar.IsClientAvatar() && homeOwnerAvatar.IsNpcAvatar()) { LogicNpcAvatar npcAvatar = (LogicNpcAvatar)homeOwnerAvatar; LogicNpcData npcData = npcAvatar.GetNpcData(); int npcStars = visitorAvatar.GetNpcStars(npcData); if (stars > npcStars && npcData.IsSinglePlayer()) { visitorAvatar.SetNpcStars(npcData, stars); visitorAvatar.GetChangeListener().CommodityCountChanged(0, npcData, stars); } // TODO: LogicBattleLog::sendNpcAttackEndEvents. } } else { LogicClientAvatar attacker = (LogicClientAvatar)visitorAvatar; LogicClientAvatar defender = (LogicClientAvatar)homeOwnerAvatar; int originalAttackerScore = attacker.GetScore(); int originalDefenderScore = defender.GetScore(); int matchType = this.m_level.GetMatchType(); if (matchType == 1 || !LogicDataTables.GetGlobals().ScoringOnlyFromMatchedMode() && (matchType == 0 || matchType == 2 || matchType == 4 || matchType == 6)) { LogicGamePlayUtil.CalculateCombatScore(attacker, defender, stars, false, matchType == 4, battleLog.GetDestructionPercentage(), this.m_calendar.GetStarBonusMultiplier(), duelMatch); if (!duelMatch && homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetLootCartEnabledTownHall()) { LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); if (resourceTable.GetItemCount() > 0) { bool hasStolen = false; for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); if (!data.IsPremiumCurrency()) { if (battleLog.GetStolenResources(data) > 0) { hasStolen = true; } } } if (hasStolen) { LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0); LogicObstacle lootCart = gameObjectManager.GetLootCart(); if (lootCart == null) { gameObjectManager.AddLootCart(); lootCart = gameObjectManager.GetLootCart(); } if (lootCart != null) { LogicLootCartComponent lootCartComponent = lootCart.GetLootCartComponent(); if (lootCartComponent != null) { for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); if (!data.IsPremiumCurrency() && data.GetWarResourceReferenceData() == null) { int lootPercentage = lootCart.GetObstacleData().GetLootDefensePercentage(); int lootCount = battleLog.GetStolenResources(data) * lootPercentage / 100; lootCartComponent.SetResourceCount(i, LogicMath.Min(LogicMath.Max(lootCount, lootCartComponent.GetResourceCount(i)), lootCartComponent.GetCapacityCount(i))); } } } } } } } this.m_level.UpdateBattleShieldStatus(false); if (stars > 0) { LogicArrayList <LogicDataSlot> castedUnits = battleLog.GetCastedUnits(); LogicArrayList <LogicDataSlot> castedSpells = battleLog.GetCastedSpells(); LogicArrayList <LogicUnitSlot> castedAllianceUnits = battleLog.GetCastedAllianceUnits(); LogicArrayList <LogicDataSlot> placedUnits = new LogicArrayList <LogicDataSlot>(castedUnits.Size()); for (int i = 0; i < castedUnits.Size(); i++) { placedUnits.Add(new LogicDataSlot(castedUnits[i].GetData(), castedUnits[i].GetCount())); } for (int i = 0; i < castedSpells.Size(); i++) { int idx = -1; for (int j = 0; j < placedUnits.Size(); j++) { if (placedUnits[j].GetData() == castedSpells[i].GetData()) { idx = j; break; } } if (idx != -1) { placedUnits[idx].SetCount(placedUnits[idx].GetCount() + castedSpells[i].GetCount()); } else { placedUnits.Add(new LogicDataSlot(castedSpells[i].GetData(), castedSpells[i].GetCount())); } } for (int i = 0; i < castedAllianceUnits.Size(); i++) { placedUnits.Add(new LogicDataSlot(castedAllianceUnits[i].GetData(), castedAllianceUnits[i].GetCount())); } for (int i = 0; i < placedUnits.Size(); i++) { LogicCombatItemData data = (LogicCombatItemData)placedUnits[i].GetData(); LogicCalendarUseTroop calendarUseTroopEvent = this.m_calendar.GetUseTroopEvents(data); if (calendarUseTroopEvent != null) { int count = attacker.GetEventUnitCounterCount(data); if (placedUnits[i].GetCount() >= count >> 16) { int progressCount = (short)count + 1; int eventCounter = progressCount | (int)(count & 0xFFFF0000); attacker.SetCommodityCount(6, data, eventCounter); attacker.GetChangeListener().CommodityCountChanged(6, data, eventCounter); if (calendarUseTroopEvent.GetParameter(0) == progressCount) { int diamonds = calendarUseTroopEvent.GetParameter(2); int xp = calendarUseTroopEvent.GetParameter(3); attacker.XpGainHelper(xp); attacker.SetDiamonds(attacker.GetDiamonds() + diamonds); attacker.SetFreeDiamonds(attacker.GetFreeDiamonds() + diamonds); attacker.GetChangeListener().FreeDiamondsAdded(diamonds, 9); Debugger.HudPrint(string.Format("USE TROOP Event: Awarding XP: {0} GEMS {1}", xp, diamonds)); } } } } for (int i = 0; i < placedUnits.Size(); i++) { placedUnits[i].Destruct(); } placedUnits.Destruct(); } } if (this.m_state != 5 && this.m_level.GetDefenseShieldActivatedHours() == 0 && battleLog.GetDestructionPercentage() > 0) { int defenseVillageGuardCounter = defender.GetDefenseVillageGuardCounter() + 1; defender.SetDefenseVillageGuardCounter(defenseVillageGuardCounter); defender.GetChangeListener().DefenseVillageGuardCounterChanged(defenseVillageGuardCounter); int villageGuardMins = (defenseVillageGuardCounter & 0xFFFFFF) == 3 * ((defenseVillageGuardCounter & 0xFFFFFF) / 3) ? defender.GetLeagueTypeData().GetVillageGuardInMins() : LogicDataTables.GetGlobals().GetDefaultDefenseVillageGuard(); this.m_level.GetHome().GetChangeListener().GuardActivated(60 * villageGuardMins); Debugger.HudPrint(string.Format("Battle end. No Shield, Village Guard for defender: {0}", villageGuardMins)); } battleLog.SetAttackerScore(attacker.GetScore() - originalAttackerScore); battleLog.SetDefenderScore(defender.GetScore() - originalDefenderScore); battleLog.SetOriginalAttackerScore(originalAttackerScore); battleLog.SetOriginalDefenderScore(originalDefenderScore); if (this.m_state != 5) { if (stars != 0) { if (matchType != 3 && matchType != 7 && matchType != 8 && matchType != 9) { if (matchType == 5) { if (stars > this.m_level.GetPreviousAttackStars() && !this.m_level.GetIgnoreAttack()) { this.m_level.GetAchievementManager().IncreaseWarStars(stars); } } else { this.m_level.GetAchievementManager().PvpAttackWon(); } } } else if (matchType > 9 || matchType == 3 || matchType == 5 || matchType == 7 || matchType == 8 || matchType == 9) { this.m_level.GetAchievementManager().PvpDefenseWon(); } } } } } this.m_battleOver = true; }
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); }
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); }
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); }
/// <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); }