public virtual int GetMax(int idx) { if (this.m_parent.GetData() != LogicDataTables.GetTownHallData() || !this.m_parent.GetLevel().IsNpcVillage()) { return(this.m_maxResourceCount[idx]); } return(10000000); }
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 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); }