/// <summary>
        ///     Gets if the specified unit can be added.
        /// </summary>
        public bool CanAddUnit(LogicCombatItemData data)
        {
            LogicAvatar homeOwnerAvatar = this._parent.GetLevel().GetHomeOwnerAvatar();

            if (!homeOwnerAvatar.IsNpcAvatar())
            {
                if (this.GetComponentType() != 0)
                {
                    if (this._storageType == data.GetCombatItemType())
                    {
                        return(this._maxCapacity >= data.GetHousingSpace() + this.GetUsedCapacity());
                    }
                }
                else
                {
                    LogicComponentManager componentManager = this._parent.GetLevel().GetComponentManager();

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

                    if (data.GetCombatItemType() == this._storageType)
                    {
                        if (this.GetUsedCapacity() < this._maxCapacity)
                        {
                            return(totalMaxHousing >= totalUsedHousing);
                        }
                    }
                }

                return(false);
            }

            return(true);
        }
        public void AddUnitsToQueue(LogicCombatItemData data, int count)
        {
            LogicCalendar          calendar          = this.m_level.GetCalendar();
            LogicAvatar            homeOwnerAvatar   = this.m_level.GetHomeOwnerAvatar();
            LogicClientAvatar      playerAvatar      = this.m_level.GetPlayerAvatar();
            LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0);
            LogicUnitProduction    production        = gameObjectManager.GetUnitProduction();

            if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
            {
                if (data.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_SPELL)
                {
                    return;
                }

                production = gameObjectManager.GetSpellProduction();
            }

            if (production != null)
            {
                int trainCost = calendar.GetTrainingCost(data, homeOwnerAvatar.GetUnitUpgradeLevel(data));

                for (int i = 0; i < count; i++)
                {
                    if (production.CanAddUnitToQueue(data, true) &&
                        playerAvatar.HasEnoughResources(data.GetTrainingResource(), trainCost, false, null, false))
                    {
                        playerAvatar.CommodityCountChangeHelper(0, data.GetTrainingResource(), -trainCost);
                        production.AddUnitToQueue(data, production.GetSlotCount(), true);
                    }
                }
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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));
            }
        }
        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);
        }
        public bool CanAddUnit(LogicCombatItemData data, int allianceLevel)
        {
            int donationCount = 0;

            for (int i = 0; i < this.m_donationData.Size(); i++)
            {
                if (this.m_donationData[i].GetCombatItemType() == data.GetCombatItemType())
                {
                    ++donationCount;
                }
            }

            return(donationCount < (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_SPELL
                       ? LogicDataTables.GetGlobals().GetMaxSpellDonationCount()
                       : this.GetDonationLimit(allianceLevel)));
        }
Exemplo n.º 7
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.º 8
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.º 9
0
        public bool ProductionCompleted(bool speedUp)
        {
            bool success = false;

            if (!this.m_locked)
            {
                LogicComponentFilter filter = new LogicComponentFilter();

                filter.SetComponentType(0);

                while (true)
                {
                    LogicAvatar           homeOwnerAvatar  = this.m_level.GetHomeOwnerAvatar();
                    LogicComponentManager componentManager = this.m_level.GetComponentManagerAt(this.m_villageType);
                    LogicCombatItemData   productionData   = this.GetWaitingForSpaceUnit();

                    if (speedUp)
                    {
                        if (this.m_slots.Size() <= 0)
                        {
                            return(false);
                        }

                        productionData = (LogicCombatItemData)this.m_slots[0].GetData();
                    }

                    if (productionData == null)
                    {
                        filter.Destruct();
                        return(false);
                    }

                    bool productionTerminate = this.m_slots[0].IsTerminate();
                    LogicBuildingData      buildingProductionData = productionData.GetProductionHouseData();
                    LogicGameObjectManager gameObjectManager      = this.m_level.GetGameObjectManagerAt(this.m_villageType);
                    LogicBuilding          productionHouse        = gameObjectManager.GetHighestBuilding(buildingProductionData);

                    if (LogicDataTables.GetGlobals().UseTroopWalksOutFromTraining())
                    {
                        int gameObjectCount = gameObjectManager.GetNumGameObjects();

                        for (int i = 0; i < gameObjectCount; i++)
                        {
                            LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i);

                            if (gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                            {
                                LogicBuilding building = (LogicBuilding)gameObject;
                                LogicUnitProductionComponent unitProductionComponent = building.GetUnitProductionComponent();

                                if (unitProductionComponent != null)
                                {
                                    if (unitProductionComponent.GetProductionType() == productionData.GetCombatItemType())
                                    {
                                        if (building.GetBuildingData().GetProducesUnitsOfType() == productionData.GetUnitOfType() &&
                                            !building.IsUpgrading() &&
                                            !building.IsConstructing())
                                        {
                                            if (productionData.IsUnlockedForProductionHouseLevel(building.GetUpgradeLevel()))
                                            {
                                                if (productionHouse != null)
                                                {
                                                    int seed = this.m_level.GetPlayerAvatar().GetExpPoints();

                                                    if (building.Rand(seed) % 1000 > 750)
                                                    {
                                                        productionHouse = building;
                                                    }
                                                }
                                                else
                                                {
                                                    productionHouse = building;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    if (productionHouse != null)
                    {
                        LogicUnitStorageComponent unitStorageComponent =
                            (LogicUnitStorageComponent)componentManager.GetClosestComponent(productionHouse.GetX(), productionHouse.GetY(), filter);

                        if (unitStorageComponent != null)
                        {
                            if (unitStorageComponent.CanAddUnit(productionData))
                            {
                                homeOwnerAvatar.CommodityCountChangeHelper(0, productionData, 1);
                                unitStorageComponent.AddUnit(productionData);

                                if (productionTerminate)
                                {
                                    this.RemoveUnit(productionData, -1);
                                }
                                else
                                {
                                    this.StartProducingNextUnit();
                                }

                                success = true;

                                if (this.m_slots.Size() > 0 && this.m_slots[0].IsTerminate() && this.m_slots[0].GetCount() > 0)
                                {
                                    continue;
                                }

                                break;
                            }

                            filter.AddIgnoreObject(unitStorageComponent.GetParent());
                        }
                        else
                        {
                            if (this.m_timer != null && this.m_timer.GetRemainingSeconds(this.m_level.GetLogicTime()) == 0)
                            {
                                success = this.TrainingFinished();
                            }

                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                filter.Destruct();

                if (success)
                {
                    this.m_nextProduction = 0;
                }
                else
                {
                    this.m_nextProduction = 2000;
                }
            }

            return(success);
        }
        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;
                }
            }
        }
Exemplo n.º 11
0
        public override void Tick()
        {
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

            if (homeOwnerAvatar != null)
            {
                this.m_updateAvatarCooldown += 64;

                if (this.m_updateAvatarCooldown > 1000)
                {
                    homeOwnerAvatar.UpdateStarBonusLimitCooldown();
                    homeOwnerAvatar.UpdateLootLimitCooldown();

                    this.m_updateAvatarCooldown -= 1000;
                }
            }

            if (this.m_parent.IsAlive())
            {
                if (!this.IsEmpty())
                {
                    if (this.m_bunkerSearchTime > 0)
                    {
                        this.m_bunkerSearchTime -= 64;
                    }
                    else
                    {
                        bool airTriggered = false;
                        bool groundLocked = false;

                        if (this.m_team == 1)
                        {
                            bool inAirDistance    = false;
                            bool inGroundDistance = false;

                            int clanCastleRadius = LogicDataTables.GetGlobals().GetClanCastleRadius();

                            if (LogicDataTables.GetGlobals().CastleTroopTargetFilter())
                            {
                                LogicCharacter closestGroundAttacker = this.ClosestAttacker(false);
                                LogicCharacter closestAirAttacker    = this.ClosestAttacker(true);

                                if (closestAirAttacker != null)
                                {
                                    inAirDistance = closestAirAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) <
                                                    clanCastleRadius * clanCastleRadius;
                                }

                                if (closestGroundAttacker != null)
                                {
                                    inGroundDistance = closestGroundAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) <
                                                       clanCastleRadius * clanCastleRadius;
                                }
                            }
                            else
                            {
                                LogicCharacter closestAttacker =
                                    (LogicCharacter)this.m_parent.GetLevel().GetGameObjectManager()
                                    .GetClosestGameObject(this.m_parent.GetX(), this.m_parent.GetY(), this.m_filter);

                                if (closestAttacker != null)
                                {
                                    inAirDistance = inGroundDistance = closestAttacker.GetPosition().GetDistanceSquaredTo(this.m_parent.GetX(), this.m_parent.GetY()) <
                                                                       clanCastleRadius * clanCastleRadius;
                                }
                            }

                            groundLocked = !inGroundDistance;
                            airTriggered = inAirDistance;

                            if (!airTriggered && groundLocked)
                            {
                                this.m_bunkerSearchTime = LogicDataTables.GetGlobals().GetBunkerSearchTime();
                                return;
                            }
                        }
                        else
                        {
                            airTriggered = true;
                        }

                        LogicCharacterData spawnData = null;
                        int spawnLevel = -1;

                        for (int i = 0; i < this.GetUnitTypeCount(); i++)
                        {
                            LogicCombatItemData data = this.GetUnitType(i);

                            if (data != null)
                            {
                                int count = this.GetUnitCount(i);

                                if (count > 0)
                                {
                                    int upgLevel = this.GetUnitLevel(i);

                                    if (data.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                    {
                                        LogicCharacterData    characterData    = (LogicCharacterData)data;
                                        LogicAttackerItemData attackerItemData = characterData.GetAttackerItemData(upgLevel);

                                        if (!(airTriggered & groundLocked) || attackerItemData.GetTrackAirTargets(false))
                                        {
                                            if (airTriggered | groundLocked || attackerItemData.GetTrackGroundTargets(false))
                                            {
                                                this.RemoveUnits(data, upgLevel, 1);

                                                spawnData  = characterData;
                                                spawnLevel = upgLevel;
                                            }
                                        }
                                    }
                                }
                            }

                            if (spawnData != null)
                            {
                                break;
                            }
                        }

                        if (spawnData != null)
                        {
                            LogicCharacter character =
                                (LogicCharacter)LogicGameObjectFactory.CreateGameObject(spawnData, this.m_parent.GetLevel(), this.m_parent.GetVillageType());

                            character.GetHitpointComponent().SetTeam(this.m_team);

                            if (character.GetChildTroops() != null)
                            {
                                LogicArrayList <LogicCharacter> childrens = character.GetChildTroops();

                                for (int i = 0; i < childrens.Size(); i++)
                                {
                                    childrens[i].GetHitpointComponent().SetTeam(this.m_team);
                                }
                            }

                            character.SetUpgradeLevel(spawnLevel == -1 ? 0 : spawnLevel);
                            character.SetAllianceUnit();

                            if (character.GetCharacterData().IsJumper())
                            {
                                character.GetMovementComponent().EnableJump(3600000);
                            }

                            if (this.m_team == 1)
                            {
                                if (LogicDataTables.GetGlobals().EnableDefendingAllianceTroopJump())
                                {
                                    character.GetMovementComponent().EnableJump(3600000);
                                }

                                if (LogicDataTables.GetGlobals().AllianceTroopsPatrol())
                                {
                                    character.GetCombatComponent().SetSearchRadius(LogicDataTables.GetGlobals().GetClanCastleRadius() >> 9);

                                    if (this.m_parent.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                    {
                                        character.GetMovementComponent().SetBaseBuilding((LogicBuilding)this.m_parent);
                                    }
                                }
                            }
                            else
                            {
                                LogicAvatar visitorAvatar = this.m_parent.GetLevel().GetVisitorAvatar();

                                visitorAvatar.RemoveAllianceUnit(spawnData, spawnLevel);
                                visitorAvatar.GetChangeListener().AllianceUnitRemoved(spawnData, spawnLevel);

                                LogicBattleLog battleLog = this.m_parent.GetLevel().GetBattleLog();

                                battleLog.IncrementDeployedAllianceUnits(spawnData, 1, spawnLevel);
                                battleLog.SetAllianceUsed(true);
                            }

                            if (this.m_team == 1)
                            {
                                int spawnOffsetX = 0;
                                int spawnOffsetY = 0;

                                switch (this.m_troopSpawnOffset)
                                {
                                case 0:
                                    spawnOffsetX = 1;
                                    spawnOffsetY = 0;
                                    break;

                                case 1:
                                    spawnOffsetX = -1;
                                    spawnOffsetY = 0;
                                    break;

                                case 2:
                                    spawnOffsetX = 0;
                                    spawnOffsetY = 1;
                                    break;

                                case 3:
                                    spawnOffsetX = 0;
                                    spawnOffsetY = -1;
                                    break;
                                }

                                character.SetInitialPosition(this.m_parent.GetMidX() + ((this.m_parent.GetWidthInTiles() << 8) - 128) * spawnOffsetX,
                                                             this.m_parent.GetMidY() + ((this.m_parent.GetHeightInTiles() << 8) - 128) * spawnOffsetY);

                                if (++this.m_troopSpawnOffset > 3)
                                {
                                    this.m_troopSpawnOffset = 0;
                                }
                            }
                            else if (LogicDataTables.GetGlobals().AllowClanCastleDeployOnObstacles())
                            {
                                int posX = this.m_parent.GetX() + (this.m_parent.GetWidthInTiles() << 9) - 128;
                                int posY = this.m_parent.GetY() + (this.m_parent.GetHeightInTiles() << 8);

                                if (LogicGamePlayUtil.GetNearestValidAttackPos(this.m_parent.GetLevel(), posX, posY, out int outputX, out int outputY))
                                {
                                    character.SetInitialPosition(outputX, outputY);
                                }
                                else
                                {
                                    character.SetInitialPosition(posX, posY);
                                }
                            }
                            else
                            {
                                character.SetInitialPosition(this.m_parent.GetX() + (this.m_parent.GetWidthInTiles() << 9) - 128,
                                                             this.m_parent.GetY() + (this.m_parent.GetHeightInTiles() << 8));
                            }

                            this.m_parent.GetGameObjectManager().AddGameObject(character, -1);
                        }

                        this.m_bunkerSearchTime = LogicDataTables.GetGlobals().GetBunkerSearchTime();
                    }
                }
            }
Exemplo n.º 12
0
        /// <summary>
        ///     Executes this instance.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            for (int i = 0; i < this._unitsCount.Count; i++)
            {
                if (this._unitsCount[i] < 0)
                {
                    return(-1);
                }
            }

            if (LogicDataTables.GetGlobals().EnableTroopDeletion() && level.GetState() == 1 && this._unitsData.Count > 0)
            {
                LogicClientAvatar playerAvatar = level.GetPlayerAvatar();
                Int32             removedUnits = 0;

                for (int i = 0; i < this._unitsData.Count; i++)
                {
                    LogicCombatItemData data = this._unitsData[i];
                    Int32 unitCount          = this._unitsCount[i];

                    if (this._removeType[i] != 0)
                    {
                        Int32 upgLevel = this._unitsUpgLevel[i];

                        if (data.GetCombatItemType() != 0)
                        {
                            if (data.GetCombatItemType() == 1)
                            {
                                playerAvatar.SetAllianceUnitCount(data, upgLevel, LogicMath.Max(0, playerAvatar.GetAllianceUnitCount(data, upgLevel) - unitCount));

                                if (unitCount > 0)
                                {
                                    do
                                    {
                                        playerAvatar.GetChangeListener().AllianceUnitRemoved(data, upgLevel);
                                    } while (--unitCount != 0);
                                }

                                removedUnits |= 2;
                            }
                        }
                        else
                        {
                            LogicBuilding allianceCastle = level.GetGameObjectManagerAt(0).GetAllianceCastle();

                            if (allianceCastle != null)
                            {
                                LogicBunkerComponent bunkerComponent = allianceCastle.GetBunkerComponent();
                                Int32 unitTypeIndex = bunkerComponent.GetUnitTypeIndex(data);

                                if (unitTypeIndex != -1)
                                {
                                    Int32 cnt = bunkerComponent.GetUnitCount(unitTypeIndex);

                                    if (cnt > 0)
                                    {
                                        bunkerComponent.RemoveUnits(data, upgLevel, cnt);
                                        playerAvatar.SetAllianceUnitCount(data, upgLevel, LogicMath.Max(0, playerAvatar.GetAllianceUnitCount(data, upgLevel) - unitCount));

                                        removedUnits |= 1;

                                        if (unitCount > 0)
                                        {
                                            do
                                            {
                                                playerAvatar.GetChangeListener().AllianceUnitRemoved(data, upgLevel);
                                            } while (--unitCount != 0);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (playerAvatar != null && data != null)
                        {
                            playerAvatar.CommodityCountChangeHelper(0, data, -unitCount);
                        }

                        LogicArrayList <LogicComponent> components = level.GetComponentManager().GetComponents(0);

                        for (int j = 0; j < components.Count; j++)
                        {
                            if (unitCount > 0)
                            {
                                LogicUnitStorageComponent storageComponent = (LogicUnitStorageComponent)components[j];
                                Int32 unitTypeIndex = storageComponent.GetUnitTypeIndex(data);

                                if (unitTypeIndex != -1)
                                {
                                    Int32 cnt = storageComponent.GetUnitCount(unitTypeIndex);

                                    if (cnt > 0)
                                    {
                                        cnt = LogicMath.Min(cnt, unitCount);
                                        storageComponent.RemoveUnits(data, cnt);

                                        int type = 2;

                                        if (data.GetCombatItemType() == 0)
                                        {
                                            if (storageComponent.GetParentListener() != null)
                                            {
                                                LogicGameObjectListener listener = storageComponent.GetParentListener();

                                                for (int k = 0; k < cnt; k++)
                                                {
                                                    listener.UnitRemoved(data);
                                                }
                                            }

                                            type = 1;
                                        }

                                        unitCount    -= cnt;
                                        removedUnits |= type;
                                    }
                                }
                            }
                        }
                    }
                }

                switch (removedUnits)
                {
                case 3:
                    if (LogicDataTables.GetGlobals().UseNewTraining())
                    {
                        level.GetGameObjectManager().GetUnitProduction().MergeSlots();
                        level.GetGameObjectManager().GetSpellProduction().MergeSlots();
                    }
                    break;

                case 2:
                    if (LogicDataTables.GetGlobals().UseNewTraining())
                    {
                        level.GetGameObjectManager().GetSpellProduction().MergeSlots();
                    }
                    break;

                case 1:
                    if (LogicDataTables.GetGlobals().UseNewTraining())
                    {
                        level.GetGameObjectManager().GetUnitProduction().MergeSlots();
                    }
                    break;

                default:
                    Debugger.Print("WTF: " + removedUnits);
                    break;
                }
            }

            return(0);
        }
Exemplo n.º 13
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);
        }