private void SortProduction(LogicArrayList <LogicCombatItemData> arrayList)
        {
            for (int i = 0; i < arrayList.Size(); i++)
            {
                bool change = false;

                for (int j = 0; j < arrayList.Size() - 1; j++)
                {
                    LogicCombatItemData data     = arrayList[j];
                    LogicCombatItemData nextData = arrayList[j + 1];

                    int sort1 = data.GetRequiredProductionHouseLevel() + 100 * data.GetUnitOfType() + 500 * data.GetCombatItemType();
                    int sort2 = nextData.GetRequiredProductionHouseLevel() + 100 * nextData.GetUnitOfType() + 500 * nextData.GetCombatItemType();

                    if (sort1 > sort2)
                    {
                        arrayList[j]     = nextData;
                        arrayList[j + 1] = data;
                        change           = true;
                    }
                }

                if (!change)
                {
                    break;
                }
            }
        }
Exemple #2
0
        public bool CanStartUpgrading(LogicCombatItemData data)
        {
            if (data != null && this.m_unit == null)
            {
                if (this.m_parent.GetLevel().GetGameMode().GetCalendar().IsProductionEnabled(data))
                {
                    if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_HERO)
                    {
                        if (this.m_parent.GetVillageType() == data.GetVillageType())
                        {
                            int upgLevel = this.m_parent.GetLevel().GetHomeOwnerAvatar().GetUnitUpgradeLevel(data);

                            if (data.GetUpgradeLevelCount() - 1 > upgLevel)
                            {
                                int maxProductionHouseLevel;

                                if (data.GetVillageType() == 1)
                                {
                                    maxProductionHouseLevel = this.m_parent.GetComponentManager().GetMaxBarrackLevel();
                                }
                                else
                                {
                                    LogicComponentManager componentManager = this.m_parent.GetComponentManager();

                                    if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                    {
                                        maxProductionHouseLevel = data.GetUnitOfType() != 1 ? componentManager.GetMaxDarkBarrackLevel() : componentManager.GetMaxBarrackLevel();
                                    }
                                    else
                                    {
                                        maxProductionHouseLevel =
                                            data.GetUnitOfType() == 1 ? componentManager.GetMaxSpellForgeLevel() : componentManager.GetMaxMiniSpellForgeLevel();
                                    }
                                }

                                if (maxProductionHouseLevel >= data.GetRequiredProductionHouseLevel())
                                {
                                    LogicBuilding building = (LogicBuilding)this.m_parent;

                                    if (!building.IsLocked())
                                    {
                                        return(building.GetUpgradeLevel() >= data.GetRequiredLaboratoryLevel(upgLevel + 1));
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
Exemple #3
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!");
                }
            }
        }