public bool HasEnoughFreeHousingSpace()
        {
            LogicCalendar       calendar        = this.m_level.GetCalendar();
            LogicAvatar         homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();
            LogicUnitProduction unitProduction  = this.m_level.GetGameObjectManagerAt(0).GetUnitProduction();
            LogicDataTable      characterTable  = LogicDataTables.GetTable(LogicDataType.CHARACTER);

            int freeHousingSpace     = unitProduction.GetMaxTrainCount() - (homeOwnerAvatar.GetUnitsTotalCapacity() - unitProduction.GetTotalCount());
            int requiredHousingSpace = 0;

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

                if (calendar.IsProductionEnabled(data) && !data.IsSecondaryTroop())
                {
                    int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId);

                    if (count > 0)
                    {
                        requiredHousingSpace += data.GetHousingSpace() * count;
                    }
                }
            }

            if (requiredHousingSpace <= freeHousingSpace)
            {
                LogicUnitProduction spellProduction = this.m_level.GetGameObjectManagerAt(0).GetSpellProduction();
                LogicDataTable      spellTable      = LogicDataTables.GetTable(LogicDataType.SPELL);

                int freeSpellHousingSpace     = spellProduction.GetMaxTrainCount() - (homeOwnerAvatar.GetSpellsTotalCapacity() - spellProduction.GetTotalCount());
                int requiredSpellHousingSpace = 0;

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

                    if (calendar.IsProductionEnabled(data))
                    {
                        int count = homeOwnerAvatar.GetUnitPresetCount(data, this.m_presetId);

                        if (count > 0)
                        {
                            requiredSpellHousingSpace += data.GetHousingSpace() * count;
                        }
                    }
                }

                return(requiredSpellHousingSpace <= freeSpellHousingSpace);
            }

            return(false);
        }
        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");
            }
        }
Example #3
0
        public bool DuplicateCharacter(LogicCharacterData data, int upgLevel)
        {
            if (data != null)
            {
                int tick   = this.m_level.GetLogicTime().GetTick();
                int offset = 75 * this.GetSpellData().GetRadius(this.m_upgradeLevel) / 100 * (tick % 100) / 100;

                int posX = this.GetX() + ((offset * LogicMath.Sin(tick * 21 + 7 * this.m_duplicateCharacterPositionOffset)) >> 10);
                int posY = this.GetY() + ((offset * LogicMath.Cos(tick * 21 + 7 * this.m_duplicateCharacterPositionOffset)) >> 10);

                bool posNotFound = false;

                if (!data.IsFlying())
                {
                    posNotFound = !LogicGamePlayUtil.FindGoodDuplicatePosAround(this.m_level, posX, posY, out int outputX, out int outputY, 10);

                    posX = outputX;
                    posY = outputY;
                }

                if (!posNotFound)
                {
                    if (this.m_duplicateHousingSpace >= data.GetHousingSpace())
                    {
                        this.m_duplicateHousingSpace -= data.GetHousingSpace();
                        this.m_duplicateCharacters.Add(this.CreateDuplicateCharacter(data, upgLevel, posX, posY));

                        ++this.m_duplicateCharacterOffset;
                        ++this.m_duplicateCharacterPositionOffset;

                        return(true);
                    }
                }
            }

            return(false);
        }
Example #4
0
        public bool DuplicateCharacter()
        {
            if (this.m_duplicateHousingSpace < 0)
            {
                this.m_duplicateHousingSpace = this.GetSpellData().GetDuplicateHousing(this.m_upgradeLevel);
            }

            if (this.m_duplicableCharacters != null)
            {
                if (this.m_duplicableCharacters.Size() > 0)
                {
                    int minHousingSpace = ((LogicCharacter)this.m_duplicableCharacters[0]).GetCharacterData().GetHousingSpace();

                    for (int i = 0; i < this.m_duplicableCharacters.Size(); i++)
                    {
                        LogicCharacter     character = (LogicCharacter)this.m_duplicableCharacters[(i + this.m_duplicateCharacterOffset) % this.m_duplicableCharacters.Size()];
                        LogicCharacterData data      = character.GetCharacterData();

                        int housingSpace = data.GetHousingSpace();

                        if (minHousingSpace > housingSpace)
                        {
                            minHousingSpace = housingSpace;
                        }

                        if (this.DuplicateCharacter(data, character.GetUpgradeLevel()))
                        {
                            return(true);
                        }
                    }

                    return(false);
                }

                return(this.DuplicateCharacter(this.m_duplicateCharacterData, this.m_duplicateCharacterUpgradeLevel));
            }

            return(this.m_duplicateCharacterData != null && this.DuplicateCharacter(this.m_duplicateCharacterData, this.m_duplicateCharacterUpgradeLevel));
        }
        public static float GetCharacterStrength(LogicCharacterData data, int upgLevel)
        {
            if (data.IsProductionEnabled())
            {
                float attackStrength = data.GetHitpoints(upgLevel) * 0.04f +
                                       LogicMath.Abs(data.GetAttackerItemData(upgLevel).GetDamagePerMS(0, false)) * 0.2f;

                if (data.GetUnitsInCamp(upgLevel) > 0 && data.GetUnitsInCamp(0) > 0)
                {
                    attackStrength = (float)data.GetUnitsInCamp(upgLevel) / data.GetUnitsInCamp(0) * attackStrength;
                }

                for (int i = data.GetSpecialAbilityLevel(upgLevel); i > 0; i--)
                {
                    attackStrength *= 1.1f;
                }

                return(attackStrength * 0.01f * data.GetStrengthWeight(upgLevel) / data.GetHousingSpace() * 10f);
            }

            return(0f);
        }
Example #6
0
        public void ObjectClose(LogicGameObject gameObject)
        {
            LogicHitpointComponent hitpointComponent = gameObject.GetHitpointComponent();

            if (hitpointComponent == null || hitpointComponent.GetTeam() != 1)
            {
                if (gameObject.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                {
                    LogicCharacter     character = (LogicCharacter)gameObject;
                    LogicCharacterData data      = character.GetCharacterData();

                    if (data.GetHousingSpace() < this.m_minTriggerHousingLimit)
                    {
                        return;
                    }
                }

                LogicCombatComponent combatComponent = gameObject.GetCombatComponent();

                if (combatComponent == null || combatComponent.GetUndergroundTime() <= 0)
                {
                    if ((!gameObject.IsFlying() || this.m_airTrigger) && (gameObject.IsFlying() || this.m_groundTrigger))
                    {
                        if (this.m_healerTrigger || combatComponent == null || !combatComponent.IsHealer())
                        {
                            int distanceX = gameObject.GetX() - this.m_parent.GetMidX();
                            int distanceY = gameObject.GetY() - this.m_parent.GetMidY();

                            if (LogicMath.Abs(distanceX) <= this.m_triggerRadius &&
                                LogicMath.Abs(distanceY) <= this.m_triggerRadius &&
                                distanceX * distanceX + distanceY * distanceY < (uint)(this.m_triggerRadius * this.m_triggerRadius))
                            {
                                this.Trigger();
                            }
                        }
                    }
                }
            }
        }
Example #7
0
        public void AlianceUnitDonated(LogicCharacterData data)
        {
            if (data != null)
            {
                LogicClientAvatar playerAvatar = this.m_level.GetPlayerAvatar();
                LogicDataTable    dataTable    = LogicDataTables.GetTable(LogicDataType.ACHIEVEMENT);

                for (int i = 0; i < dataTable.GetItemCount(); i++)
                {
                    LogicAchievementData achievementData = (LogicAchievementData)dataTable.GetItemAt(i);

                    if (achievementData.GetActionType() == LogicAchievementData.ACTION_TYPE_DONATE_UNITS)
                    {
                        this.RefreshAchievementProgress(playerAvatar, achievementData, playerAvatar.GetAchievementProgress(achievementData) + data.GetHousingSpace());
                    }
                }
            }
        }
Example #8
0
        public void SelectDuplicableCharacters()
        {
            if (this.m_duplicableCharacters == null)
            {
                this.m_duplicableCharacters = new LogicArrayList <LogicGameObject>(20);
            }

            if (this.m_duplicateCharacters == null)
            {
                this.m_duplicateCharacters = new LogicArrayList <LogicGameObject>(20);
            }

            int radius = this.GetSpellData().GetRadius(this.m_upgradeLevel);

            LogicArrayList <LogicComponent> components = this.GetComponentManager().GetComponents(LogicComponentType.MOVEMENT);

            for (int i = 0; i < components.Size(); i++)
            {
                LogicMovementComponent movementComponent = (LogicMovementComponent)components[i];
                LogicGameObject        parent            = movementComponent.GetParent();

                if (parent.GetGameObjectType() == LogicGameObjectType.CHARACTER)
                {
                    LogicCharacter         character         = (LogicCharacter)parent;
                    LogicCharacterData     characterData     = character.GetCharacterData();
                    LogicHitpointComponent hitpointComponent = character.GetHitpointComponent();

                    if (hitpointComponent != null && hitpointComponent.GetTeam() == 0 && character.IsAlive() && !character.IsHero() &&
                        characterData.GetHousingSpace() <= this.m_duplicateHousingSpace)
                    {
                        int distanceX = character.GetPosition().m_x - this.GetMidX();
                        int distanceY = character.GetPosition().m_y - this.GetMidY();

                        if (LogicMath.Abs(distanceX) <= radius &&
                            LogicMath.Abs(distanceY) <= radius &&
                            distanceX * distanceX + distanceY * distanceY < (uint)(radius * radius))
                        {
                            int idx = -1;

                            for (int j = 0, size = this.m_duplicableCharacters.Size(); j < size; j++)
                            {
                                if (this.m_duplicableCharacters[j] == character)
                                {
                                    idx = j;
                                    break;
                                }
                            }

                            if (idx == -1)
                            {
                                this.m_duplicateCharacterData         = characterData;
                                this.m_duplicateCharacterUpgradeLevel = character.GetUpgradeLevel();

                                this.m_duplicableCharacters.Add(character);

                                // Listener.
                            }
                        }
                    }
                }
            }
        }
        public override int Execute(LogicLevel level)
        {
            this.m_level = level;

            if (LogicDataTables.GetGlobals().EnablePresets())
            {
                LogicAvatar homeOwnerAvatar = level.GetHomeOwnerAvatar();

                if (homeOwnerAvatar.GetTownHallLevel() >= LogicDataTables.GetGlobals().GetEnablePresetsTownHallLevel())
                {
                    if (this.m_presetId <= 3)
                    {
                        LogicDataTable        table            = LogicDataTables.GetTable(LogicDataType.CHARACTER);
                        LogicComponentManager componentManager = level.GetComponentManager();

                        int totalMaxHousing = componentManager.GetTotalMaxHousing(0);

                        for (int i = 0, housingSpace = 0; i < table.GetItemCount(); i++)
                        {
                            LogicCharacterData data = (LogicCharacterData)table.GetItemAt(i);

                            if (level.GetGameMode().GetCalendar().IsProductionEnabled(data) && !data.IsSecondaryTroop())
                            {
                                int count = 0;

                                if (this.m_slots.Size() > 0)
                                {
                                    for (int j = 0; j < this.m_slots.Size(); j++)
                                    {
                                        if (this.m_slots[j].GetData() == data)
                                        {
                                            count = this.m_slots[j].GetCount();
                                            break;
                                        }
                                    }
                                }

                                housingSpace += count * data.GetHousingSpace();

                                if (housingSpace > totalMaxHousing || !this.IsUnlocked(data))
                                {
                                    this.SetUnitPresetCount(data, 0);
                                }
                                else
                                {
                                    this.SetUnitPresetCount(data, count);
                                }
                            }
                        }

                        table           = LogicDataTables.GetTable(LogicDataType.SPELL);
                        totalMaxHousing = componentManager.GetTotalMaxHousing(0);

                        for (int i = 0, housingSpace = 0; i < table.GetItemCount(); i++)
                        {
                            LogicSpellData data = (LogicSpellData)table.GetItemAt(i);

                            if (level.GetGameMode().GetCalendar().IsProductionEnabled(data))
                            {
                                int count = 0;

                                if (this.m_slots.Size() > 0)
                                {
                                    for (int j = 0; j < this.m_slots.Size(); j++)
                                    {
                                        if (this.m_slots[j].GetData() == data)
                                        {
                                            count = this.m_slots[j].GetCount();
                                            break;
                                        }
                                    }
                                }

                                housingSpace += count * data.GetHousingSpace();

                                if (housingSpace > totalMaxHousing || !this.IsUnlocked(data))
                                {
                                    this.SetUnitPresetCount(data, 0);
                                }
                                else
                                {
                                    this.SetUnitPresetCount(data, count);
                                }
                            }
                        }

                        return(0);
                    }

                    return(-2);
                }
            }

            return(-1);
        }