コード例 #1
0
        public static void AddDebugTroopsPreset(LogicLevel level, int townHallLevel, LogicClientAvatar playerAvatar)
        {
            if (playerAvatar != null)
            {
                LogicDataTable    characterTable = LogicDataTables.GetTable(LogicDataType.CHARACTER);
                LogicDataTable    spellTable     = LogicDataTables.GetTable(LogicDataType.SPELL);
                LogicBuildingData laboratoryData = LogicDataTables.GetBuildingByName("Laboratory", null);

                int laboratoryLevel = laboratoryData.GetMaxUpgradeLevelForTownHallLevel(townHallLevel);
                int totalHousing    = LogicDebugUtil.GetTotalCharacterMaxHousing(townHallLevel, true) / 5;

                for (int i = 0; i < characterTable.GetItemCount(); i++)
                {
                    playerAvatar.SetUnitCount((LogicCharacterData)characterTable.GetItemAt(i), 0);
                }

                for (int i = 0; i < spellTable.GetItemCount(); i++)
                {
                    playerAvatar.SetUnitCount((LogicSpellData)spellTable.GetItemAt(i), 0);
                }

                for (int i = 0; i < 7; i++)
                {
                    if (i != 2 && i != 5)
                    {
                        LogicCharacterData characterData = (LogicCharacterData)characterTable.GetItemAt(i);

                        if (characterData.GetVillageType() == 0)
                        {
                            int upgradeLevel = 0;

                            for (int j = characterData.GetUpgradeLevelCount(); j >= 2; j--)
                            {
                                int requiredLaboratoryLevel = characterData.GetRequiredLaboratoryLevel(j - 1);

                                if (laboratoryLevel >= requiredLaboratoryLevel)
                                {
                                    upgradeLevel = j - 1;
                                    break;
                                }
                            }

                            playerAvatar.SetUnitCount(characterData, totalHousing / characterData.GetHousingSpace());
                            playerAvatar.SetUnitUpgradeLevel(characterData, upgradeLevel);
                        }
                    }
                }
            }
            else
            {
                Debugger.Warning("addDebugTroopsPreset: pAvatar is NULL");
            }
        }
コード例 #2
0
        public void ValidateTroopUpgradeLevels()
        {
            LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

            if (homeOwnerAvatar != null)
            {
                if (homeOwnerAvatar.IsClientAvatar())
                {
                    int[] laboratoryLevels = new int[2];

                    for (int i = 0; i < 2; i++)
                    {
                        LogicBuilding laboratory = this.m_level.GetGameObjectManagerAt(i).GetLaboratory();

                        if (laboratory != null)
                        {
                            laboratoryLevels[i] = laboratory.GetUpgradeLevel();
                        }
                    }

                    LogicDataTable characterTable = LogicDataTables.GetTable(LogicDataType.CHARACTER);

                    for (int i = 0; i < characterTable.GetItemCount(); i++)
                    {
                        LogicCharacterData characterData = (LogicCharacterData)characterTable.GetItemAt(i);

                        int upgradeLevel    = homeOwnerAvatar.GetUnitUpgradeLevel(characterData);
                        int villageType     = characterData.GetVillageType();
                        int newUpgradeLevel = upgradeLevel;

                        if (upgradeLevel >= characterData.GetUpgradeLevelCount())
                        {
                            newUpgradeLevel = characterData.GetUpgradeLevelCount() - 1;
                        }

                        int laboratoryLevel = laboratoryLevels[villageType];
                        int requireLaboratoryLevel;

                        do
                        {
                            requireLaboratoryLevel = characterData.GetRequiredLaboratoryLevel(newUpgradeLevel--);
                        } while (newUpgradeLevel >= 0 && requireLaboratoryLevel > laboratoryLevel);

                        newUpgradeLevel += 1;

                        if (upgradeLevel > newUpgradeLevel)
                        {
                            homeOwnerAvatar.SetUnitUpgradeLevel(characterData, newUpgradeLevel);
                            homeOwnerAvatar.GetChangeListener().CommodityCountChanged(1, characterData, newUpgradeLevel);
                        }
                    }

                    LogicDataTable spellTable = LogicDataTables.GetTable(LogicDataType.SPELL);

                    for (int i = 0; i < spellTable.GetItemCount(); i++)
                    {
                        LogicSpellData spellData = (LogicSpellData)spellTable.GetItemAt(i);

                        int upgradeLevel    = homeOwnerAvatar.GetUnitUpgradeLevel(spellData);
                        int villageType     = spellData.GetVillageType();
                        int newUpgradeLevel = upgradeLevel;

                        if (upgradeLevel >= spellData.GetUpgradeLevelCount())
                        {
                            newUpgradeLevel = spellData.GetUpgradeLevelCount() - 1;
                        }

                        int laboratoryLevel = laboratoryLevels[villageType];
                        int requireLaboratoryLevel;

                        do
                        {
                            requireLaboratoryLevel = spellData.GetRequiredLaboratoryLevel(newUpgradeLevel--);
                        } while (newUpgradeLevel >= 0 && requireLaboratoryLevel > laboratoryLevel);

                        newUpgradeLevel += 1;

                        if (upgradeLevel > newUpgradeLevel)
                        {
                            homeOwnerAvatar.SetUnitUpgradeLevel(spellData, newUpgradeLevel);
                            homeOwnerAvatar.GetChangeListener().CommodityCountChanged(1, spellData, newUpgradeLevel);
                        }
                    }
                }
            }
        }