public virtual void RecalculateAvailableLoot() { int matchType = this.m_parent.GetLevel().GetMatchType(); LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar(); LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < this.m_resourceCount.Size(); i++) { LogicResourceData data = (LogicResourceData)resourceTable.GetItemAt(i); int resourceCount = this.m_resourceCount[i]; if (!homeOwnerAvatar.IsNpcAvatar()) { if (matchType == 5 && this.m_parent.GetLevel().IsArrangedWar()) { if (resourceCount >= 0) { resourceCount = 0; } } else if (LogicDataTables.GetGlobals().UseTownHallLootPenaltyInWar() || matchType != 5) { if (matchType != 8 && matchType != 9) { int multiplier = 100; int calculateAvailableLootCount = 0; if (homeOwnerAvatar != null && homeOwnerAvatar.IsClientAvatar() && visitorAvatar != null && visitorAvatar.IsClientAvatar()) { multiplier = LogicDataTables.GetGlobals().GetLootMultiplierByTownHallDiff(visitorAvatar.GetTownHallLevel(), homeOwnerAvatar.GetTownHallLevel()); } if (this.m_parent.GetData() == LogicDataTables.GetTownHallData() && LogicDataTables.GetGlobals().GetTownHallLootPercentage() != -1) { calculateAvailableLootCount = resourceCount * (multiplier * LogicDataTables.GetGlobals().GetTownHallLootPercentage() / 100) / 100; } else if (!data.IsPremiumCurrency()) { int townHallLevel = homeOwnerAvatar.GetTownHallLevel(); int lootableResourceCount = 0; if (matchType != 3) { if (matchType == 5) { lootableResourceCount = resourceCount; } else if (matchType != 7) { lootableResourceCount = (int)((long)resourceCount * LogicDataTables.GetTownHallLevel(townHallLevel).GetStorageLootPercentage(data) / 100); } } int storageLootCap = LogicDataTables.GetTownHallLevel(townHallLevel).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) { if (storageLootCap < 1000) { clampedValue = (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount; } else { if (!LogicDataTables.GetGlobals().UseMoreAccurateLootCap()) { clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount); } else { if (resourceCount / 100 > maxResourceCount / storageLootCap) { clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount); } else { clampedValue = (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount; } } } } else { if (!LogicDataTables.GetGlobals().UseMoreAccurateLootCap()) { clampedValue = 1000 * ((resourceCount * (storageLootCap / 1000) + (maxResourceCount >> 1)) / maxResourceCount); } else { if (resourceCount / 1000 > maxResourceCount / storageLootCap) { clampedValue = 1000 * ((resourceCount * (storageLootCap / 1000) + (maxResourceCount >> 1)) / maxResourceCount); } else { if (resourceCount / 100 > maxResourceCount / storageLootCap) { clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount); } else { clampedValue = (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount; } } } } } else { if (!LogicDataTables.GetGlobals().UseMoreAccurateLootCap()) { clampedValue = 10000 * ((resourceCount * (storageLootCap / 10000) + (maxResourceCount >> 1)) / maxResourceCount); } else { if (resourceCount / 10000 > maxResourceCount / storageLootCap) { clampedValue = 10000 * ((resourceCount * (storageLootCap / 10000) + (maxResourceCount >> 1)) / maxResourceCount); } else { if (resourceCount / 1000 > maxResourceCount / storageLootCap) { clampedValue = 1000 * ((resourceCount * (storageLootCap / 1000) + (maxResourceCount >> 1)) / maxResourceCount); } else { if (resourceCount / 100 > maxResourceCount / storageLootCap) { clampedValue = 100 * ((resourceCount * (storageLootCap / 100) + (maxResourceCount >> 1)) / maxResourceCount); } else { clampedValue = (resourceCount * storageLootCap + (maxResourceCount >> 1)) / maxResourceCount; } } } } } } else { clampedValue = 40000 * ((resourceCount * (storageLootCap / 40000) + (maxResourceCount >> 1)) / maxResourceCount); } if (lootableResourceCount > clampedValue) { lootableResourceCount = clampedValue; } } calculateAvailableLootCount = multiplier * lootableResourceCount / 100; } if (calculateAvailableLootCount <= resourceCount) { resourceCount = calculateAvailableLootCount; } } } } this.m_stealableResourceCount[i] = resourceCount; } }
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; } } } }