示例#1
0
        public void IncrementCastedSpells(LogicSpellData data, int count)
        {
            this.m_deployedHousingSpace    += LogicDataTables.GetGlobals().GetSpellHousingCostMultiplier() * data.GetHousingSpace() * count / 100;
            this.m_armyDeploymentPercentage =
                (100000 * this.m_deployedHousingSpace / LogicDataTables.GetTownHallLevel(this.m_level.GetTownHallLevel(0)).GetMaxHousingSpace() + 50) / 100;

            int index = -1;

            for (int i = 0; i < this.m_castedSpellCount.Size(); i++)
            {
                if (this.m_castedSpellCount[i].GetData() == data)
                {
                    index = i;
                    break;
                }
            }

            if (index != -1)
            {
                this.m_castedSpellCount[index].SetCount(this.m_castedSpellCount[index].GetCount() + count);
            }
            else
            {
                this.m_castedSpellCount.Add(new LogicDataSlot(data, count));
            }
        }
        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);
                }
            }
        }
示例#3
0
        public void IncrementDeployedAllianceUnits(LogicCombatItemData data, int count, int upgLevel)
        {
            int multiplier = data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_HERO
                ? LogicDataTables.GetGlobals().GetUnitHousingCostMultiplier()
                : LogicDataTables.GetGlobals().GetHeroHousingCostMultiplier();
            int maxHousingSpace = LogicDataTables.GetTownHallLevel(this.m_level.GetTownHallLevel(0)).GetMaxHousingSpace();

            if (maxHousingSpace > 0)
            {
                this.m_armyDeploymentPercentage =
                    (100000 * this.m_deployedHousingSpace / maxHousingSpace + 50) / 100;
            }

            this.m_deployedHousingSpace += multiplier * data.GetHousingSpace() * count / 100;

            int index = -1;

            for (int i = 0; i < this.m_castedAllianceUnitCount.Size(); i++)
            {
                if (this.m_castedAllianceUnitCount[i].GetData() == data && this.m_castedAllianceUnitCount[i].GetLevel() == upgLevel)
                {
                    index = i;
                    break;
                }
            }

            if (index != -1)
            {
                this.m_castedAllianceUnitCount[index].SetCount(this.m_castedAllianceUnitCount[index].GetCount() + count);
            }
            else
            {
                this.m_castedAllianceUnitCount.Add(new LogicUnitSlot(data, upgLevel, count));
            }
        }
示例#4
0
        public void StartUseTroopEvent(LogicAvatar homeOwnerAvatar, LogicLevel level)
        {
            if (homeOwnerAvatar != null)
            {
                for (int i = 0; i < this.m_useTroops.Size(); i++)
                {
                    LogicCalendarUseTroop calendarUseTroop = this.m_useTroops[i];
                    LogicCombatItemData   data             = calendarUseTroop.GetData();

                    int housingSpace;
                    int totalMaxHousing;
                    int unitCount;

                    if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                    {
                        housingSpace    = data.GetHousingSpace() * 2;
                        totalMaxHousing = data.GetHousingSpace() + 2 * (level.GetComponentManagerAt(data.GetVillageType()).GetTotalMaxHousing(data.GetCombatItemType()) *
                                                                        calendarUseTroop.GetParameter(1) / 100);
                        unitCount = totalMaxHousing / housingSpace;
                    }
                    else
                    {
                        LogicBuildingData troopHousingData      = LogicDataTables.GetBuildingByName("Troop Housing", null);
                        LogicBuildingData barrackData           = LogicDataTables.GetBuildingByName("Barrack", null);
                        LogicBuildingData darkElixirBarrackData = LogicDataTables.GetBuildingByName("Dark Elixir Barrack", null);

                        int townHallLevel        = homeOwnerAvatar.GetTownHallLevel();
                        int maxUpgradeLevelForTH = troopHousingData.GetMaxUpgradeLevelForTownHallLevel(townHallLevel);
                        int unitStorageCapacity  = troopHousingData.GetUnitStorageCapacity(maxUpgradeLevelForTH);

                        housingSpace = data.GetHousingSpace();

                        if (data.GetUnitOfType() == 1 && barrackData.GetRequiredTownHallLevel(data.GetRequiredProductionHouseLevel()) <= townHallLevel ||
                            data.GetUnitOfType() == 2 && darkElixirBarrackData.GetRequiredTownHallLevel(data.GetRequiredProductionHouseLevel()) <= townHallLevel)
                        {
                            int totalHousing = (int)((long)LogicDataTables.GetTownHallLevel(townHallLevel).GetUnlockedBuildingCount(troopHousingData) *
                                                     calendarUseTroop.GetParameter(1) *
                                                     unitStorageCapacity);
                            unitCount = (int)((housingSpace * 0.5f + totalHousing / 100) / housingSpace);
                        }
                        else
                        {
                            LogicBuildingData allianceCastleData = LogicDataTables.GetBuildingByName("Alliance Castle", null);

                            totalMaxHousing = allianceCastleData.GetUnitStorageCapacity(allianceCastleData.GetMaxUpgradeLevelForTownHallLevel(townHallLevel));
                            unitCount       = totalMaxHousing / housingSpace;
                        }
                    }

                    int eventCounter = LogicMath.Max(1, unitCount) << 16;

                    homeOwnerAvatar.SetCommodityCount(6, data, eventCounter);
                    homeOwnerAvatar.GetChangeListener().CommodityCountChanged(6, data, eventCounter);

                    Debugger.HudPrint("EVENT: Use troop/spell event started!");
                }
            }
        }
        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);
        }
示例#6
0
        public override bool CanBeDeliver(LogicLevel level)
        {
            int placedBuildingCount = level.GetObjectCount(this.m_buildingData, this.m_buildingData.GetVillageType());
            int townHallLevel       = this.m_buildingData.GetVillageType() == 1
                ? level.GetHomeOwnerAvatar().GetVillage2TownHallLevel()
                : level.GetHomeOwnerAvatar().GetTownHallLevel();
            int unlockedBuildingCount = LogicDataTables.GetTownHallLevel(townHallLevel).GetUnlockedBuildingCount(this.m_buildingData);

            if (placedBuildingCount >= unlockedBuildingCount || this.m_buildingCount != 0)
            {
                return(this.m_buildingCount == placedBuildingCount + 1);
            }

            return(true);
        }
        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 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);
        }
示例#10
0
        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;
            }
        }
示例#11
0
        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;
                    }
                }
            }
        }
        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);
        }