public void StartUseTroopEvent(LogicAvatar homeOwnerAvatar, LogicLevel level) { if (homeOwnerAvatar != null) { for (int i = 0; i < this.m_useTroops.Size(); i++) { LogicCalendarUseTroop calendarUseTroop = this.m_useTroops[i]; LogicCombatItemData data = calendarUseTroop.GetData(); int housingSpace; int totalMaxHousing; int unitCount; if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER) { housingSpace = data.GetHousingSpace() * 2; totalMaxHousing = data.GetHousingSpace() + 2 * (level.GetComponentManagerAt(data.GetVillageType()).GetTotalMaxHousing(data.GetCombatItemType()) * calendarUseTroop.GetParameter(1) / 100); unitCount = totalMaxHousing / housingSpace; } else { LogicBuildingData troopHousingData = LogicDataTables.GetBuildingByName("Troop Housing", null); LogicBuildingData barrackData = LogicDataTables.GetBuildingByName("Barrack", null); LogicBuildingData darkElixirBarrackData = LogicDataTables.GetBuildingByName("Dark Elixir Barrack", null); int townHallLevel = homeOwnerAvatar.GetTownHallLevel(); int maxUpgradeLevelForTH = troopHousingData.GetMaxUpgradeLevelForTownHallLevel(townHallLevel); int unitStorageCapacity = troopHousingData.GetUnitStorageCapacity(maxUpgradeLevelForTH); housingSpace = data.GetHousingSpace(); if (data.GetUnitOfType() == 1 && barrackData.GetRequiredTownHallLevel(data.GetRequiredProductionHouseLevel()) <= townHallLevel || data.GetUnitOfType() == 2 && darkElixirBarrackData.GetRequiredTownHallLevel(data.GetRequiredProductionHouseLevel()) <= townHallLevel) { int totalHousing = (int)((long)LogicDataTables.GetTownHallLevel(townHallLevel).GetUnlockedBuildingCount(troopHousingData) * calendarUseTroop.GetParameter(1) * unitStorageCapacity); unitCount = (int)((housingSpace * 0.5f + totalHousing / 100) / housingSpace); } else { LogicBuildingData allianceCastleData = LogicDataTables.GetBuildingByName("Alliance Castle", null); totalMaxHousing = allianceCastleData.GetUnitStorageCapacity(allianceCastleData.GetMaxUpgradeLevelForTownHallLevel(townHallLevel)); unitCount = totalMaxHousing / housingSpace; } } int eventCounter = LogicMath.Max(1, unitCount) << 16; homeOwnerAvatar.SetCommodityCount(6, data, eventCounter); homeOwnerAvatar.GetChangeListener().CommodityCountChanged(6, data, eventCounter); Debugger.HudPrint("EVENT: Use troop/spell event started!"); } } }
public static void AddDebugTroopsPreset(LogicLevel level, int townHallLevel, LogicClientAvatar playerAvatar) { if (playerAvatar != null) { LogicDataTable characterTable = LogicDataTables.GetTable(LogicDataType.CHARACTER); LogicDataTable spellTable = LogicDataTables.GetTable(LogicDataType.SPELL); LogicBuildingData laboratoryData = LogicDataTables.GetBuildingByName("Laboratory", null); int laboratoryLevel = laboratoryData.GetMaxUpgradeLevelForTownHallLevel(townHallLevel); int totalHousing = LogicDebugUtil.GetTotalCharacterMaxHousing(townHallLevel, true) / 5; for (int i = 0; i < characterTable.GetItemCount(); i++) { playerAvatar.SetUnitCount((LogicCharacterData)characterTable.GetItemAt(i), 0); } for (int i = 0; i < spellTable.GetItemCount(); i++) { playerAvatar.SetUnitCount((LogicSpellData)spellTable.GetItemAt(i), 0); } for (int i = 0; i < 7; i++) { if (i != 2 && i != 5) { LogicCharacterData characterData = (LogicCharacterData)characterTable.GetItemAt(i); if (characterData.GetVillageType() == 0) { int upgradeLevel = 0; for (int j = characterData.GetUpgradeLevelCount(); j >= 2; j--) { int requiredLaboratoryLevel = characterData.GetRequiredLaboratoryLevel(j - 1); if (laboratoryLevel >= requiredLaboratoryLevel) { upgradeLevel = j - 1; break; } } playerAvatar.SetUnitCount(characterData, totalHousing / characterData.GetHousingSpace()); playerAvatar.SetUnitUpgradeLevel(characterData, upgradeLevel); } } } } else { Debugger.Warning("addDebugTroopsPreset: pAvatar is NULL"); } }