public void AddDefendingHero() { LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar(); LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar(); int randomPatrolPoint = visitorAvatar != null ? (int)(((visitorAvatar.GetResourceCount(LogicDataTables.GetGoldData()) + 10 * this.m_hero.GetGlobalID()) & 0x7FFFFFFFu) % this.m_patrolPath.Size()) : 0; int upgLevel = homeOwnerAvatar.GetUnitUpgradeLevel(this.m_hero); int heroHitpoints = this.m_hero.GetHeroHitpoints(homeOwnerAvatar.GetHeroHealth(this.m_hero), upgLevel); if (this.m_hero.HasEnoughHealthForAttack(heroHitpoints, upgLevel)) { LogicVector2 patrolPoint = this.m_patrolPath[randomPatrolPoint]; LogicCharacter hero = (LogicCharacter)LogicGameObjectFactory.CreateGameObject(this.m_hero, this.m_parent.GetLevel(), this.m_parent.GetVillageType()); hero.GetMovementComponent().SetBaseBuilding((LogicBuilding)this.m_parent); hero.GetHitpointComponent().SetTeam(1); hero.SetUpgradeLevel(upgLevel); hero.GetHitpointComponent().SetHitpoints(heroHitpoints); hero.SetInitialPosition(patrolPoint.m_x, patrolPoint.m_y); this.m_parent.GetGameObjectManager().AddGameObject(hero, -1); hero.GetCombatComponent().SetSearchRadius(this.m_hero.GetMaxSearchRadiusForDefender() / 512); if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump()) { hero.GetMovementComponent().EnableJump(3600000); } } }
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 override bool Deliver(LogicLevel level) { LogicAvatar avatar = level.GetHomeOwnerAvatar(); int count = avatar.GetResourceCount(this.m_resourceData) + this.m_resourceAmount; avatar.SetResourceCount(this.m_resourceData, count); avatar.GetChangeListener().CommodityCountChanged(0, this.m_resourceData, count); return(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 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; } } } }