public override void ResourcesStolen(int damage, int hp) { if (damage > 0 && hp > 0) { LogicDataTable table = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < this.m_stealableResourceCount.Size(); i++) { LogicResourceData data = (LogicResourceData)table.GetItemAt(i); int stealableResource = this.GetStealableResourceCount(i); if (damage < hp) { stealableResource = damage * stealableResource / hp; } if (stealableResource > 0 && data.GetWarResourceReferenceData() != null) { this.m_parent.GetLevel().GetBattleLog().IncreaseStolenResourceCount(data.GetWarResourceReferenceData(), stealableResource); this.m_resourceCount[i] -= stealableResource; LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar(); homeOwnerAvatar.CommodityCountChangeHelper(0, data, -stealableResource); visitorAvatar.CommodityCountChangeHelper(0, data.GetWarResourceReferenceData(), stealableResource); this.m_stealableResourceCount[i] = LogicMath.Max(this.m_stealableResourceCount[i] - stealableResource, 0); } } } }
public int CollectResources() { int collected = -1; if (this.m_parent.GetLevel().GetHomeOwnerAvatar().IsClientAvatar()) { collected = 0; LogicClientAvatar playerAvatar = (LogicClientAvatar)this.m_parent.GetLevel().GetHomeOwnerAvatar(); LogicDataTable table = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < table.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)table.GetItemAt(i); if (data.GetWarResourceReferenceData() != null) { int count = playerAvatar.GetResourceCount(data); if (count > 0) { int unusedResourceCap = playerAvatar.GetUnusedResourceCap(data.GetWarResourceReferenceData()); if (unusedResourceCap != 0) { if (count > unusedResourceCap) { count = unusedResourceCap; } if (data.GetName().Equals("WarGold")) { this.m_parent.GetLevel().GetAchievementManager().IncreaseWarGoldResourceLoot(count); } collected = count; playerAvatar.CommodityCountChangeHelper(0, data.GetWarResourceReferenceData(), count); playerAvatar.CommodityCountChangeHelper(0, data, -count); } } } } } return(collected); }
public void DivideAvatarResourcesToStorages() { LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null) { LogicArrayList <LogicComponent> resourceStorageComponents = this.m_components[(int)LogicComponentType.RESOURCE_STORAGE]; LogicArrayList <LogicComponent> warResourceStorageComponents = this.m_components[(int)LogicComponentType.WAR_RESOURCE_STORAGE]; LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); if (!data.IsPremiumCurrency()) { if (data.GetWarResourceReferenceData() != null) { Debugger.DoAssert(warResourceStorageComponents.Size() < 2, "Too many war storage components"); for (int j = 0; j < warResourceStorageComponents.Size(); j++) { LogicWarResourceStorageComponent warResourceStorageComponent = (LogicWarResourceStorageComponent)warResourceStorageComponents[j]; warResourceStorageComponent.SetCount(i, homeOwnerAvatar.GetResourceCount(data)); } } else { for (int j = 0; j < resourceStorageComponents.Size(); j++) { ((LogicResourceStorageComponent)resourceStorageComponents[j]).SetCount(i, 0); } int resourceCount = homeOwnerAvatar.GetResourceCount(data); if (this.m_level.GetBattleLog() != null && data.GetVillageType() == 1) { resourceCount = LogicMath.Max(resourceCount - this.m_level.GetBattleLog().GetCostCount(data), 0); } this.AddResources(i, resourceCount, true); } } } } }
public bool IsNotEmpty() { LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); LogicDataTable table = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < table.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)table.GetItemAt(i); if (data.GetWarResourceReferenceData() != null) { if (homeOwnerAvatar.GetResourceCount(data) > 0) { return(true); } } } return(false); }
public override void Save(LogicJSONObject jsonObject, int villageType) { LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); if (!resourceData.IsPremiumCurrency() && resourceData.GetWarResourceReferenceData() == null) { if (LogicDataTables.GetGoldData() == resourceData) { int count = this.GetResourceCount(i); if (count > 0) { jsonObject.Put("defg", new LogicJSONNumber(count)); } } else if (LogicDataTables.GetElixirData() == resourceData) { int count = this.GetResourceCount(i); if (count > 0) { jsonObject.Put("defe", new LogicJSONNumber(count)); } } else if (LogicDataTables.GetDarkElixirData() == resourceData) { int count = this.GetResourceCount(i); if (count > 0) { jsonObject.Put("defde", new LogicJSONNumber(count)); } } } } }
public override void Load(LogicJSONObject jsonObject) { LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); if (!resourceData.IsPremiumCurrency() && resourceData.GetWarResourceReferenceData() == null) { if (LogicDataTables.GetGoldData() == resourceData) { LogicJSONNumber count = jsonObject.GetJSONNumber("defg"); if (count != null) { this.SetResourceCount(i, count.GetIntValue()); } } else if (LogicDataTables.GetElixirData() == resourceData) { LogicJSONNumber count = jsonObject.GetJSONNumber("defe"); if (count != null) { this.SetResourceCount(i, count.GetIntValue()); } } else if (LogicDataTables.GetDarkElixirData() == resourceData) { LogicJSONNumber count = jsonObject.GetJSONNumber("defde"); if (count != null) { this.SetResourceCount(i, count.GetIntValue()); } } } } }
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 CalculateAvailableResources(LogicLevel level, int matchType) { for (int i = this.m_availableLootCount.Size() - 1; i >= 0; i--) { this.m_availableLootCount[i].Destruct(); this.m_availableLootCount.Remove(i); } LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); LogicResourceData warResourceReferenceData = data.GetWarResourceReferenceData(); LogicDataSlot dataSlot = null; if (warResourceReferenceData != null) { for (int j = 0; j < this.m_availableLootCount.Size(); j++) { if (this.m_availableLootCount[j].GetData() == warResourceReferenceData) { dataSlot = this.m_availableLootCount[j]; break; } } Debugger.DoAssert(dataSlot != null, "Didn't find the resource slot"); } else { this.m_availableLootCount.Add(dataSlot = new LogicDataSlot(data, 0)); } if (matchType == 8 || matchType == 9) { LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar(); if (homeOwnerAvatar != null) { LogicArrayList <LogicDataSlot> resourceCount = homeOwnerAvatar.GetResources(); for (int j = 0; j < resourceCount.Size(); j++) { if (resourceCount[j].GetData() == data) { dataSlot.SetCount(resourceCount[j].GetCount()); } } } } else { LogicComponentManager componentManager = level.GetComponentManagerAt(level.GetVillageType()); if (warResourceReferenceData == null) { LogicArrayList <LogicComponent> resourceProductionComponents = componentManager.GetComponents(LogicComponentType.RESOURCE_PRODUCTION); LogicArrayList <LogicComponent> resourceStorageComponents = componentManager.GetComponents(LogicComponentType.RESOURCE_STORAGE); for (int j = 0; j < resourceProductionComponents.Size(); j++) { LogicResourceProductionComponent resourceProductionComponent = (LogicResourceProductionComponent)resourceProductionComponents[j]; LogicGameObject gameObject = resourceProductionComponent.GetParent(); if (gameObject.IsAlive() && resourceProductionComponent.IsEnabled()) { if (resourceProductionComponent.GetResourceData() == data) { dataSlot.SetCount(dataSlot.GetCount() + resourceProductionComponent.GetStealableResourceCount()); } } } for (int j = 0; j < resourceStorageComponents.Size(); j++) { LogicResourceStorageComponent resourceStorageComponent = (LogicResourceStorageComponent)resourceStorageComponents[j]; LogicGameObject gameObject = resourceStorageComponent.GetParent(); if (gameObject.IsAlive() && resourceStorageComponent.IsEnabled()) { dataSlot.SetCount(dataSlot.GetCount() + resourceStorageComponent.GetStealableResourceCount(i)); } } } else { LogicArrayList <LogicComponent> warResourceStorageComponents = componentManager.GetComponents(LogicComponentType.WAR_RESOURCE_STORAGE); for (int j = 0; j < warResourceStorageComponents.Size(); j++) { LogicWarResourceStorageComponent resourceWarStorageComponent = (LogicWarResourceStorageComponent)warResourceStorageComponents[j]; LogicGameObject gameObject = resourceWarStorageComponent.GetParent(); if (gameObject.IsAlive() && resourceWarStorageComponent.IsEnabled()) { dataSlot.SetCount(dataSlot.GetCount() + resourceWarStorageComponent.GetStealableResourceCount(i)); } } } } } }
public void ClearingFinished(bool ignoreState) { int state = this.m_level.GetState(); if (state == 1 || !LogicDataTables.GetGlobals().CompleteConstructionOnlyHome() && ignoreState) { if (this.m_level.GetHomeOwnerAvatar().IsClientAvatar()) { LogicClientAvatar homeOwnerAvatar = (LogicClientAvatar)this.m_level.GetHomeOwnerAvatar(); LogicObstacleData obstacleData = this.GetObstacleData(); LogicResourceData lootResourceData = obstacleData.GetLootResourceData(); int lootCount = obstacleData.GetLootCount(); if (obstacleData.IsLootCart()) { LogicLootCartComponent lootCartComponent = (LogicLootCartComponent)this.GetComponent(LogicComponentType.LOOT_CART); if (lootCartComponent != null) { LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); bool empty = true; for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); if (!resourceData.IsPremiumCurrency() && resourceData.GetWarResourceReferenceData() == null) { int resourceCount = lootCartComponent.GetResourceCount(i); int rewardCount = LogicMath.Min(homeOwnerAvatar.GetUnusedResourceCap(resourceData), resourceCount); int remainingCount = resourceCount - rewardCount; if (rewardCount > 0) { homeOwnerAvatar.CommodityCountChangeHelper(0, resourceData, rewardCount); lootCartComponent.SetResourceCount(i, remainingCount); } if (remainingCount > 0) { empty = false; } } } if (!empty) { return; } } } if (!obstacleData.IsTombstone() && !obstacleData.IsLootCart()) { this.m_level.GetAchievementManager().ObstacleCleared(); } this.m_level.GetWorkerManagerAt(this.m_villageType).DeallocateWorker(this); this.XpGainHelper(LogicGamePlayUtil.TimeToExp(obstacleData.GetClearTime()), homeOwnerAvatar, ignoreState || state == 1); if (lootResourceData != null && lootCount > 0) { if (homeOwnerAvatar != null) { if (lootResourceData.IsPremiumCurrency()) { int lootMultipler = 1; if (this.m_lootMultiplyVersion >= 2) { lootMultipler = obstacleData.GetLootMultiplierVersion2(); } int diamondsCount = obstacleData.GetName().Equals("Bonus Gembox") ? lootCount * lootMultipler : this.m_level.GetGameObjectManagerAt(this.m_villageType).IncreaseObstacleClearCounter(lootMultipler); if (diamondsCount > 0) { homeOwnerAvatar.SetDiamonds(homeOwnerAvatar.GetDiamonds() + diamondsCount); homeOwnerAvatar.SetFreeDiamonds(homeOwnerAvatar.GetFreeDiamonds() + diamondsCount); homeOwnerAvatar.GetChangeListener().FreeDiamondsAdded(diamondsCount, 6); } } else { int gainCount = LogicMath.Min(homeOwnerAvatar.GetUnusedResourceCap(lootResourceData), lootCount); if (gainCount > 0) { homeOwnerAvatar.CommodityCountChangeHelper(0, lootResourceData, gainCount); } } } else { Debugger.Error("LogicObstacle::clearingFinished - Home owner avatar is NULL!"); } } if (obstacleData.IsEnabledInVillageType(this.m_level.GetVillageType())) { // ? } if (this.m_clearTimer != null) { this.m_clearTimer.Destruct(); this.m_clearTimer = null; } this.m_fadeTime = 1; } } }
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 void RecalculateAvailableLoot() { LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < this.m_resourceCount.Size(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); if (this.m_parent.GetData() == LogicDataTables.GetAllianceCastleData()) { LogicResourceData refData = data.GetWarResourceReferenceData(); int resourceCount = this.m_resourceCount[i]; if (refData != null) { int warLootPercentage = LogicDataTables.GetGlobals().GetWarLootPercentage(); int lootableResourceCount = 0; if ((this.m_parent.GetLevel().GetMatchType() | 4) != 7 && !this.m_parent.GetLevel().IsArrangedWar()) { lootableResourceCount = (int)((long)resourceCount * warLootPercentage / 100); } int storageLootCap = LogicDataTables.GetTownHallLevel(homeOwnerAvatar.GetTownHallLevel()).GetStorageLootCap(data); int maxResourceCount = LogicMath.Min(homeOwnerAvatar.GetResourceCount(data), homeOwnerAvatar.GetResourceCap(data)); if (maxResourceCount > storageLootCap && maxResourceCount > 0) { int clampedValue; if (storageLootCap < 1000000) { if (storageLootCap < 100000) { if (storageLootCap < 10000) { clampedValue = storageLootCap < 1000 ? (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount : 10 * ((resourceCount * (storageLootCap / 10) + (maxResourceCount >> 1)) / maxResourceCount); } else { clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount); } } else { clampedValue = 1000 * ((resourceCount * (storageLootCap / 1000) + (maxResourceCount >> 1)) / maxResourceCount); } } else { clampedValue = 40000 * ((resourceCount * (storageLootCap / 40000) + (maxResourceCount >> 1)) / maxResourceCount); } if (lootableResourceCount > clampedValue) { lootableResourceCount = clampedValue; } } if (lootableResourceCount > resourceCount) { lootableResourceCount = resourceCount; } this.m_stealableResourceCount[i] = lootableResourceCount; } } } }