Exemplo n.º 1
0
        public bool CanAddUnit(LogicCombatItemData data)
        {
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

            if (!homeOwnerAvatar.IsNpcAvatar())
            {
                if (this.GetComponentType() != 0)
                {
                    if (this.m_storageType == data.GetCombatItemType())
                    {
                        return(this.m_maxCapacity >= data.GetHousingSpace() + this.GetUsedCapacity());
                    }
                }
                else
                {
                    LogicComponentManager componentManager = this.m_parent.GetComponentManager();

                    int totalUsedHousing = componentManager.GetTotalUsedHousing(this.m_storageType);
                    int totalMaxHousing  = componentManager.GetTotalMaxHousing(this.m_storageType);

                    if (data.GetCombatItemType() == this.m_storageType)
                    {
                        if (this.GetUsedCapacity() < this.m_maxCapacity)
                        {
                            return(totalMaxHousing >= totalUsedHousing + data.GetHousingSpace());
                        }
                    }
                }

                return(false);
            }

            return(true);
        }
        public bool CanAddDonation(LogicLong avatarId, LogicCombatItemData data, int allianceLevel)
        {
            if (!LogicLong.Equals(avatarId, this.GetSenderAvatarId()))
            {
                if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                {
                    if (data.GetHousingSpace() + this.m_castleUsedCapacity + LogicDonationHelper.GetTotalDonationCapacity(this.m_donationContainerList, 0) >
                        this.m_castleTotalCapacity)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (this.m_castleTotalSpellCapacity == 0 ||
                        data.GetHousingSpace() + this.m_castleUsedSpellCapacity + LogicDonationHelper.GetTotalDonationCapacity(this.m_donationContainerList, 1) >
                        this.m_castleTotalSpellCapacity)
                    {
                        return(false);
                    }
                }

                return(LogicDonationHelper.CanAddDonation(this.m_donationContainerList, avatarId, data, allianceLevel));
            }

            return(false);
        }
Exemplo n.º 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!");
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Tries to merge slots.
        /// </summary>
        public void MergeSlots()
        {
            LogicAvatar homeOwnerAvatar = this._level.GetHomeOwnerAvatar();

            if (this._slots.Count > 0)
            {
                if (this._slots.Count > 1)
                {
                    for (int i = 1; i < this._slots.Count; i++)
                    {
                        LogicUnitProductionSlot slot1 = this._slots[i];
                        LogicUnitProductionSlot slot2 = this._slots[i - 1];

                        if (slot1.GetData() == slot2.GetData())
                        {
                            if (slot1.IsTerminate() == slot2.IsTerminate())
                            {
                                this._slots.Remove(i--);
                                slot2.SetCount(slot2.GetCount() + slot1.GetCount());
                                slot1.Destruct();
                                slot1 = null;
                            }
                        }
                    }
                }
            }

            LogicComponentManager componentManager = this._level.GetComponentManagerAt(this._villageType);
            Int32 totalCapcity = componentManager.GetTotalMaxHousing(this._unitProductionType != 3 ? 1 : 0);
            Int32 usedCapacity = this._unitProductionType == 25 ? homeOwnerAvatar.GetSpellsTotalCapacity() : homeOwnerAvatar.GetUnitsTotalCapacity();
            Int32 freeCapacity = totalCapcity - usedCapacity;

            for (int i = 0; i < this._slots.Count; i++)
            {
                LogicUnitProductionSlot slot = this._slots[i];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();

                int housingSpace = data.GetHousingSpace() * slot.GetCount();

                if (freeCapacity < housingSpace)
                {
                    if (slot.GetCount() > 0 && housingSpace / data.GetHousingSpace() > 0)
                    {
                        if (slot.GetCount() > housingSpace / data.GetHousingSpace())
                        {
                            this._slots.Add(i + 1, new LogicUnitProductionSlot(data, slot.GetCount() - housingSpace / data.GetHousingSpace(), slot.IsTerminate()));
                        }
                    }

                    break;
                }

                freeCapacity -= housingSpace;
            }
        }
Exemplo n.º 5
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));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Speed up the unit production.
        /// </summary>
        public void SpeedUp()
        {
            LogicAvatar           homeOwnerAvatar  = this._level.GetHomeOwnerAvatar();
            LogicComponentManager componentManager = this._level.GetComponentManagerAt(this._villageType);
            Int32 totalMaxHousing   = componentManager.GetTotalMaxHousing(this._unitProductionType != 3 ? 1 : 0);
            Int32 totalUsedCapacity = this._unitProductionType == 3 ? homeOwnerAvatar.GetUnitsTotalCapacity() : homeOwnerAvatar.GetSpellsTotalCapacity();
            Int32 freeCapacity      = totalMaxHousing - totalUsedCapacity;

            while (this._slots.Count > 0)
            {
                LogicUnitProductionSlot slot = this._slots[0];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();
                Int32 count = slot.GetCount();

                if (count > 0)
                {
                    do
                    {
                        freeCapacity -= data.GetHousingSpace();

                        if (freeCapacity < 0)
                        {
                            return;
                        }

                        this.ProductionCompleted(true);
                    } while (--count > 0);
                }
                else
                {
                    break;
                }
            }
        }
Exemplo n.º 7
0
        public bool CanAddUnitToQueue(LogicCombatItemData data, bool ignoreCapacity)
        {
            if (data != null)
            {
                if (data.GetDataType() == this.m_unitProductionType)
                {
                    LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0);
                    LogicBuilding          productionHouse   = gameObjectManager.GetHighestBuilding(data.GetProductionHouseData());

                    if (productionHouse != null)
                    {
                        if (!data.IsUnlockedForProductionHouseLevel(productionHouse.GetUpgradeLevel()))
                        {
                            return(false);
                        }

                        if (data.GetUnitOfType() != productionHouse.GetBuildingData().GetProducesUnitsOfType())
                        {
                            return(false);
                        }
                    }

                    if (this.m_level.GetMissionManager().IsTutorialFinished() ||
                        this.m_level.GetHomeOwnerAvatar().GetUnitsTotalCapacity() + this.GetTotalCount() < LogicUnitProduction.TUTORIAL_MAX_CAPACITY)
                    {
                        if (ignoreCapacity)
                        {
                            return(true);
                        }

                        LogicAvatar           avatar           = this.m_level.GetHomeOwnerAvatar();
                        LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType);
                        int totalMaxHousing   = componentManager.GetTotalMaxHousing(this.m_unitProductionType != LogicDataType.CHARACTER ? 1 : 0) * 2;
                        int totalUsedCapacity = this.GetTotalCount() + data.GetHousingSpace() + (this.m_unitProductionType == LogicDataType.CHARACTER
                                                    ? avatar.GetUnitsTotalCapacity()
                                                    : avatar.GetSpellsTotalCapacity());

                        return(totalMaxHousing >= totalUsedCapacity);
                    }
                }
                else
                {
                    Debugger.Error("Trying to add wrong unit type to UnitProduction");
                }
            }
            else
            {
                Debugger.Error("Trying to add NULL troop to UnitProduction");
            }

            return(false);
        }
        /// <summary>
        ///     Gets the used capacity.
        /// </summary>
        public int GetUsedCapacity()
        {
            int usedCapacity = 0;

            for (int i = 0; i < this._slots.Count; i++)
            {
                LogicUnitSlot       unitSlot       = this._slots[i];
                LogicCombatItemData combatItemData = (LogicCombatItemData)unitSlot.GetData();

                usedCapacity += combatItemData.GetHousingSpace() * unitSlot.GetCount();
            }

            return(usedCapacity);
        }
Exemplo n.º 9
0
        public int GetTotalCount()
        {
            int count = 0;

            for (int i = 0; i < this.m_slots.Size(); i++)
            {
                LogicUnitProductionSlot slot = this.m_slots[i];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();

                count += data.GetHousingSpace() * slot.GetCount();
            }

            return(count);
        }
Exemplo n.º 10
0
        public int GetTotalRemainingSeconds()
        {
            LogicAvatar           homeOwnerAvatar  = this.m_level.GetHomeOwnerAvatar();
            LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType);

            int totalMaxHousing   = componentManager.GetTotalMaxHousing(this.m_unitProductionType != LogicDataType.CHARACTER ? 1 : 0);
            int totalUsedCapacity = this.m_unitProductionType == LogicDataType.CHARACTER ? homeOwnerAvatar.GetUnitsTotalCapacity() : homeOwnerAvatar.GetSpellsTotalCapacity();
            int freeCapacity      = totalMaxHousing - totalUsedCapacity;
            int remainingSecs     = 0;

            for (int i = 0; i < this.m_slots.Size(); i++)
            {
                LogicUnitProductionSlot slot = this.m_slots[i];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();
                int housingSpace             = data.GetHousingSpace();
                int count = slot.GetCount();

                if (count > 0)
                {
                    if (i == 0)
                    {
                        if (!slot.IsTerminate() && freeCapacity - housingSpace >= 0)
                        {
                            if (this.m_timer != null)
                            {
                                remainingSecs += this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime());
                            }
                        }

                        freeCapacity -= housingSpace;
                        count        -= 1;
                    }

                    for (int j = 0; j < count; j++)
                    {
                        if (!slot.IsTerminate() && freeCapacity - housingSpace >= 0)
                        {
                            remainingSecs += data.GetTrainingTime(homeOwnerAvatar.GetUnitUpgradeLevel(data), this.m_level, 0);
                        }

                        freeCapacity -= housingSpace;
                    }
                }
            }

            return(remainingSecs);
        }
Exemplo n.º 11
0
        public void AddAvatarAllianceUnitsToCastle()
        {
            LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0);
            LogicBuilding          allianceCastle    = gameObjectManager.GetAllianceCastle();

            if (allianceCastle != null)
            {
                LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent();

                if (bunkerComponent != null)
                {
                    bunkerComponent.RemoveAllUnits();

                    LogicArrayList <LogicUnitSlot> units = this.m_level.GetHomeOwnerAvatar().GetAllianceUnits();

                    for (int i = 0; i < units.Size(); i++)
                    {
                        LogicUnitSlot       unitSlot = units[i];
                        LogicCombatItemData data     = (LogicCombatItemData)unitSlot.GetData();
                        int count = unitSlot.GetCount();

                        if (data != null)
                        {
                            if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                            {
                                for (int j = 0; j < count; j++)
                                {
                                    if (bunkerComponent.GetUnusedCapacity() >= data.GetHousingSpace())
                                    {
                                        bunkerComponent.AddUnitImpl(data, unitSlot.GetLevel());
                                    }
                                }
                            }
                        }
                        else
                        {
                            Debugger.Error("LogicComponentManager::addAvatarAllianceUnitsToCastle - NULL character");
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        public void SpeedUp()
        {
            LogicAvatar           homeOwnerAvatar  = this.m_level.GetHomeOwnerAvatar();
            LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType);

            int totalMaxHousing   = componentManager.GetTotalMaxHousing(this.m_unitProductionType != LogicDataType.CHARACTER ? 1 : 0);
            int totalUsedCapacity = this.m_unitProductionType == LogicDataType.CHARACTER ? homeOwnerAvatar.GetUnitsTotalCapacity() : homeOwnerAvatar.GetSpellsTotalCapacity();
            int freeCapacity      = totalMaxHousing - totalUsedCapacity;

            bool armyCampFull = false;

            while (!armyCampFull && this.m_slots.Size() > 0)
            {
                LogicUnitProductionSlot slot = this.m_slots[0];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();

                int count = slot.GetCount();

                if (count <= 0)
                {
                    break;
                }

                armyCampFull = true;

                do
                {
                    freeCapacity -= data.GetHousingSpace();

                    if (freeCapacity >= 0)
                    {
                        this.ProductionCompleted(true);
                        armyCampFull = false;
                    }
                } while (--count > 0);
            }
        }
Exemplo n.º 13
0
        public void MergeSlots()
        {
            LogicAvatar homeOwnerAvatar = this.m_level.GetHomeOwnerAvatar();

            if (this.m_slots.Size() > 0)
            {
                if (this.m_slots.Size() > 1)
                {
                    for (int i = 1; i < this.m_slots.Size(); i++)
                    {
                        LogicUnitProductionSlot slot1 = this.m_slots[i];
                        LogicUnitProductionSlot slot2 = this.m_slots[i - 1];

                        if (slot1.GetData() == slot2.GetData())
                        {
                            if (slot1.IsTerminate() == slot2.IsTerminate())
                            {
                                this.m_slots.Remove(i--);

                                slot2.SetCount(slot2.GetCount() + slot1.GetCount());
                                slot1.Destruct();
                                slot1 = null;
                            }
                        }
                    }
                }
            }

            LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType);

            int usedCapacity  = this.m_unitProductionType == LogicDataType.SPELL ? homeOwnerAvatar.GetSpellsTotalCapacity() : homeOwnerAvatar.GetUnitsTotalCapacity();
            int totalCapacity = componentManager.GetTotalMaxHousing(this.m_unitProductionType != LogicDataType.CHARACTER ? 1 : 0);
            int freeCapacity  = totalCapacity - usedCapacity;

            for (int i = 0, j = freeCapacity; i < this.m_slots.Size(); i++)
            {
                LogicUnitProductionSlot slot = this.m_slots[i];
                LogicCombatItemData     data = (LogicCombatItemData)slot.GetData();

                int count        = slot.GetCount();
                int housingSpace = data.GetHousingSpace() * count;

                if (j < housingSpace)
                {
                    if (count > 1)
                    {
                        int maxInProduction = j / data.GetHousingSpace();

                        if (maxInProduction > 0)
                        {
                            int inQueue = count - maxInProduction;

                            if (inQueue > 0)
                            {
                                slot.SetCount(maxInProduction);
                                this.m_slots.Add(i + 1, new LogicUnitProductionSlot(data, inQueue, slot.IsTerminate()));
                            }
                        }
                    }

                    break;
                }

                j -= housingSpace;
            }
        }
Exemplo n.º 14
0
        public override int Execute(LogicLevel level)
        {
            if (level.IsReadyForAttack())
            {
                if (level.GetVillageType() == 0)
                {
                    if (LogicDataTables.GetGlobals().AllowClanCastleDeployOnObstacles())
                    {
                        if (!level.GetTileMap().IsValidAttackPos(this.m_x >> 9, this.m_y >> 9))
                        {
                            return(-2);
                        }
                    }
                    else
                    {
                        LogicTile tile = level.GetTileMap().GetTile(this.m_x >> 9, this.m_y >> 9);

                        if (tile == null)
                        {
                            return(-4);
                        }

                        if (tile.GetPassableFlag() == 0)
                        {
                            return(-3);
                        }
                    }

                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                    if (playerAvatar != null)
                    {
                        if (this.m_data != null)
                        {
                            LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);

                            if (gameObjectManager.GetGameObjectCountByData(this.m_data) <= 0 && playerAvatar.GetAllianceCastleUsedCapacity() > 0)
                            {
                                LogicAlliancePortal  alliancePortal  = (LogicAlliancePortal)LogicGameObjectFactory.CreateGameObject(this.m_data, level, level.GetVillageType());
                                LogicBunkerComponent bunkerComponent = alliancePortal.GetBunkerComponent();

                                alliancePortal.SetInitialPosition(this.m_x, this.m_y);

                                if (bunkerComponent != null)
                                {
                                    bunkerComponent.SetMaxCapacity(playerAvatar.GetAllianceCastleTotalCapacity());

                                    if (level.GetBattleLog() != null)
                                    {
                                        if (!level.GetBattleLog().HasDeployedUnits() && level.GetTotalAttackerHeroPlaced() == 0)
                                        {
                                            level.UpdateLastUsedArmy();
                                        }
                                    }

                                    if (level.GetGameMode().IsInAttackPreparationMode())
                                    {
                                        level.GetGameMode().EndAttackPreparation();
                                    }

                                    bunkerComponent.RemoveAllUnits();

                                    LogicArrayList <LogicUnitSlot> allianceUnits = playerAvatar.GetAllianceUnits();

                                    for (int i = 0; i < allianceUnits.Size(); i++)
                                    {
                                        LogicUnitSlot       slot = allianceUnits[i];
                                        LogicCombatItemData data = (LogicCombatItemData)slot.GetData();

                                        if (data != null)
                                        {
                                            int count = slot.GetCount();

                                            if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                            {
                                                for (int j = 0; j < count; j++)
                                                {
                                                    if (bunkerComponent.GetUnusedCapacity() >= data.GetHousingSpace())
                                                    {
                                                        bunkerComponent.AddUnitImpl(data, slot.GetLevel());
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            Debugger.Error("LogicPlaceAlliancePortalCommand::execute - NULL alliance character");
                                        }
                                    }
                                }

                                gameObjectManager.AddGameObject(alliancePortal, -1);

                                return(0);
                            }
                        }
                    }

                    return(-5);
                }
            }

            return(-1);
        }