public void ReengageLootCart(int secs) { LogicObstacleData obstacleData = this.GetObstacleData(); LogicLootCartComponent lootCartComponent = (LogicLootCartComponent)this.GetComponent(LogicComponentType.LOOT_CART); LogicBuilding townHall = this.m_level.GetGameObjectManagerAt(0).GetTownHall(); Debugger.DoAssert(obstacleData.IsLootCart(), string.Empty); Debugger.DoAssert(lootCartComponent != null, string.Empty); Debugger.DoAssert(townHall != null, string.Empty); LogicDataTable resourceTable = LogicDataTables.GetTable(LogicDataType.RESOURCE); for (int i = 0; i < resourceTable.GetItemCount(); i++) { LogicResourceData resourceData = (LogicResourceData)resourceTable.GetItemAt(i); LogicTownhallLevelData townhallLevelData = LogicDataTables.GetTownHallLevel(townHall.GetUpgradeLevel()); int cap = secs * townhallLevelData.GetCartLootReengagement(resourceData) / 100; if (cap > lootCartComponent.GetResourceCount(i)) { lootCartComponent.SetResourceCount(i, cap); } } }
public override bool ShouldDestruct() { if (this.m_fadeTime >= 1000) { int trapCount = this.GetGameObjectManager().GetGameObjectCountByData(this.GetData()); int townHallLevel = this.m_level.GetTownHallLevel(this.m_level.GetVillageType()); LogicTownhallLevelData townhallLevelData = LogicDataTables.GetTownHallLevel(townHallLevel); return(townhallLevelData.GetUnlockedTrapCount(this.GetTrapData()) < trapCount); } return(false); }
public static int GetTotalCharacterMaxHousing(int townHallLevel, bool includeAllianceCastle) { LogicTownhallLevelData townhallLevelData = LogicDataTables.GetTownHallLevel(townHallLevel); LogicDataTable table = LogicDataTables.GetTable(LogicDataType.BUILDING); int housingSpace = 0; for (int i = 0; i < table.GetItemCount(); i++) { LogicBuildingData buildingData = (LogicBuildingData)table.GetItemAt(i); if (includeAllianceCastle || buildingData != LogicDataTables.GetAllianceCastleData()) { int unlockedBuildingCount = townhallLevelData.GetUnlockedBuildingCount(buildingData); if (unlockedBuildingCount > 0 && !buildingData.IsForgesSpells()) { housingSpace += unlockedBuildingCount * buildingData.GetUnitStorageCapacity(buildingData.GetMaxUpgradeLevelForTownHallLevel(townHallLevel)); } } } return(housingSpace); }
public static float GetGlobalCharacterStrength(LogicArrayList <LogicCharacterData> characterData, float[] strength, int townHallLevel) { LogicTownhallLevelData townhallLevelData = LogicDataTables.GetTownHallLevel(townHallLevel); Debugger.HudPrint(string.Format("TH{0} counts up to {1} troops (out of {2} available):", townHallLevel + 1, townhallLevelData.GetStrengthMaxTroopTypes(), characterData.Size())); float sumStrength = 0; for (int i = LogicMath.Min(townhallLevelData.GetStrengthMaxTroopTypes(), characterData.Size()); i > 0; i--) { float max = 0f; int maxIdx = 0; for (int j = 0; j < characterData.Size(); j++) { if (strength[j] > max) { max = strength[j]; maxIdx = j; } } if (max == 0f) { break; } sumStrength += max; strength[maxIdx] = 0f; Debugger.HudPrint(string.Format("{0}. {1} ({2})", i + 1, characterData[maxIdx].GetName(), max)); } return(sumStrength); }
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); }