Пример #1
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (level.GetVillageType() == 1)
            {
                LogicGameMode gameMode = level.GetGameMode();

                if (!gameMode.IsInAttackPreparationMode())
                {
                    if (gameMode.GetState() != 5)
                    {
                        return(-9);
                    }
                }

                if (this.m_oldUnitData != null && this.m_newUnitData != null && gameMode.GetCalendar().IsProductionEnabled(this.m_newUnitData))
                {
                    if (!this.m_newUnitData.IsUnlockedForBarrackLevel(playerAvatar.GetVillage2BarrackLevel()))
                    {
                        if (gameMode.GetState() != 7)
                        {
                            return(-7);
                        }
                    }

                    int oldUnitCount   = playerAvatar.GetUnitCountVillage2(this.m_oldUnitData);
                    int oldUnitsInCamp = this.m_oldUnitData.GetUnitsInCamp(playerAvatar.GetUnitUpgradeLevel(this.m_oldUnitData));

                    if (oldUnitCount >= oldUnitsInCamp)
                    {
                        int newUnitCount   = playerAvatar.GetUnitCountVillage2(this.m_newUnitData);
                        int newUnitsInCamp = this.m_newUnitData.GetUnitsInCamp(playerAvatar.GetUnitUpgradeLevel(this.m_newUnitData));

                        playerAvatar.SetUnitCountVillage2(this.m_oldUnitData, oldUnitCount - oldUnitsInCamp);
                        playerAvatar.SetUnitCountVillage2(this.m_newUnitData, newUnitCount + newUnitsInCamp);

                        LogicArrayList <LogicDataSlot> unitsNew = playerAvatar.GetUnitsNewVillage2();

                        for (int i = 0; i < unitsNew.Size(); i++)
                        {
                            LogicDataSlot slot = unitsNew[i];

                            if (slot.GetCount() > 0)
                            {
                                playerAvatar.CommodityCountChangeHelper(8, slot.GetData(), -slot.GetCount());
                            }
                        }

                        return(0);
                    }

                    return(-23);
                }

                return(-7);
            }

            return(-10);
        }
Пример #2
0
        public override int Execute(LogicLevel level)
        {
            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId);

            if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
            {
                LogicBuilding building = (LogicBuilding)gameObject;

                if (this.m_unitData != null)
                {
                    LogicUnitUpgradeComponent unitUpgradeComponent = building.GetUnitUpgradeComponent();

                    if (unitUpgradeComponent != null && unitUpgradeComponent.CanStartUpgrading(this.m_unitData))
                    {
                        LogicClientAvatar playerAvatar = level.GetPlayerAvatar();
                        int upgradeLevel = playerAvatar.GetUnitUpgradeLevel(this.m_unitData);
                        int upgradeCost  = this.m_unitData.GetUpgradeCost(upgradeLevel);
                        LogicResourceData upgradeResourceData = this.m_unitData.GetUpgradeResource(upgradeLevel);

                        if (playerAvatar.HasEnoughResources(upgradeResourceData, upgradeCost, true, this, false))
                        {
                            playerAvatar.CommodityCountChangeHelper(0, upgradeResourceData, -upgradeCost);
                            unitUpgradeComponent.StartUpgrading(this.m_unitData);

                            return(0);
                        }
                    }
                }
            }

            return(-1);
        }
        public override int Execute(LogicLevel level)
        {
            LogicBuilding building = (LogicBuilding)level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId);

            if (!building.IsLocked())
            {
                if (building.GetBuildingData().GetVillageType() == level.GetVillageType())
                {
                    LogicHeroBaseComponent heroBaseComponent = building.GetHeroBaseComponent();

                    if (heroBaseComponent != null && heroBaseComponent.CanStartUpgrading(true))
                    {
                        LogicClientAvatar playerAvatar = level.GetPlayerAvatar();
                        LogicHeroData     heroData     = building.GetBuildingData().GetHeroData();
                        int upgLevel    = playerAvatar.GetUnitUpgradeLevel(heroData);
                        int upgradeCost = heroData.GetUpgradeCost(upgLevel);
                        LogicResourceData upgradeResourceData = heroData.GetUpgradeResource(upgLevel);

                        if (playerAvatar.HasEnoughResources(upgradeResourceData, upgradeCost, true, this, false))
                        {
                            if (level.HasFreeWorkers(this, -1))
                            {
                                playerAvatar.CommodityCountChangeHelper(0, upgradeResourceData, -upgradeCost);
                                heroBaseComponent.StartUpgrading();

                                return(0);
                            }
                        }
                    }

                    return(-1);
                }

                return(-32);
            }

            return(-23);
        }
        /// <summary>
        ///     Trains the unit with new training.
        /// </summary>
        public int NewTrainingUnit(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseNewTraining())
            {
                if (this._unitData != null)
                {
                    LogicUnitProduction unitProduction = this._unitData.GetCombatItemType() == 1
                        ? level.GetGameObjectManager().GetSpellProduction()
                        : level.GetGameObjectManager().GetUnitProduction();

                    if (!unitProduction.IsLocked())
                    {
                        if (this._unitCount > 0)
                        {
                            if (this._unitData.GetDataType() == unitProduction.GetUnitProductionType())
                            {
                                LogicClientAvatar playerAvatar         = level.GetPlayerAvatar();
                                LogicResourceData trainingResourceData = this._unitData.GetTrainingResource();
                                Int32             trainingCost         = level.GetGameMode().GetCalendar().GetUnitTrainingCost(this._unitData, playerAvatar.GetUnitUpgradeLevel(this._unitData));
                                Int32             refundCount          = LogicMath.Max(trainingCost * (this._unitData.GetDataType() != 3
                                                                      ? LogicDataTables.GetGlobals().GetSpellCancelMultiplier()
                                                                      : LogicDataTables.GetGlobals().GetTrainCancelMultiplier()) / 100, 0);

                                while (unitProduction.RemoveUnit(this._unitData, this._slotId))
                                {
                                    playerAvatar.CommodityCountChangeHelper(0, trainingResourceData, refundCount);

                                    if (--this._unitCount <= 0)
                                    {
                                        break;
                                    }
                                }

                                return(0);
                            }
                        }

                        return(-1);
                    }

                    return(-23);
                }

                return(-1);
            }

            return(-99);
        }
        public bool SpeedUpHealth()
        {
            LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

            if (homeOwnerAvatar.IsClientAvatar())
            {
                LogicClientAvatar clientAvatar = (LogicClientAvatar)homeOwnerAvatar;
                int speedUpCost = this.GetSpeedUpHealthCost();

                if (clientAvatar.HasEnoughDiamonds(speedUpCost, true, this.m_parent.GetLevel()))
                {
                    clientAvatar.UseDiamonds(speedUpCost);
                    clientAvatar.GetChangeListener().DiamondPurchaseMade(9, this.m_hero.GetGlobalID(), clientAvatar.GetUnitUpgradeLevel(this.m_hero) + 1, speedUpCost,
                                                                         this.m_parent.GetLevel().GetVillageType());

                    this.SetFullHealth();

                    return(true);
                }
            }

            return(false);
        }
        public bool SpeedUp()
        {
            if (this.m_timer != null)
            {
                int remainingSecs = this.m_timer.GetRemainingSeconds(this.m_parent.GetLevel().GetLogicTime());
                int speedUpCost   = LogicGamePlayUtil.GetSpeedUpCost(remainingSecs, 0, this.m_parent.GetVillageType());

                LogicAvatar homeOwnerAvatar = this.m_parent.GetLevel().GetHomeOwnerAvatar();

                if (homeOwnerAvatar.IsClientAvatar())
                {
                    LogicClientAvatar clientAvatar = (LogicClientAvatar)homeOwnerAvatar;

                    if (clientAvatar.HasEnoughDiamonds(speedUpCost, true, this.m_parent.GetLevel()))
                    {
                        clientAvatar.UseDiamonds(speedUpCost);
                        clientAvatar.GetChangeListener().DiamondPurchaseMade(10, this.m_hero.GetGlobalID(), clientAvatar.GetUnitUpgradeLevel(this.m_hero) + 1, speedUpCost,
                                                                             this.m_parent.GetLevel().GetVillageType());
                        this.FinishUpgrading(true);

                        return(true);
                    }
                }
            }

            return(false);
        }
        public int NewTrainingUnit(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseNewTraining())
            {
                if (this.m_trainCount <= 100)
                {
                    LogicUnitProduction unitProduction = this.m_unitType == 1
                        ? level.GetGameObjectManagerAt(0).GetSpellProduction()
                        : level.GetGameObjectManagerAt(0).GetUnitProduction();

                    if (this.m_trainCount > 0)
                    {
                        if (this.m_unitData != null)
                        {
                            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

                            bool firstLoopExecuted = false;
                            int  trainingCost      = level.GetGameMode().GetCalendar().GetTrainingCost(this.m_unitData, playerAvatar.GetUnitUpgradeLevel(this.m_unitData));

                            for (int i = 0; i < this.m_trainCount; i++)
                            {
                                if (!unitProduction.CanAddUnitToQueue(this.m_unitData, false))
                                {
                                    if (firstLoopExecuted)
                                    {
                                        break;
                                    }

                                    return(-40);
                                }

                                if (!playerAvatar.HasEnoughResources(this.m_unitData.GetTrainingResource(), trainingCost, true, this, false))
                                {
                                    if (firstLoopExecuted)
                                    {
                                        break;
                                    }

                                    return(-30);
                                }

                                playerAvatar.CommodityCountChangeHelper(0, this.m_unitData.GetTrainingResource(), -trainingCost);

                                if (this.m_slotId == -1)
                                {
                                    this.m_slotId = unitProduction.GetSlotCount();
                                }

                                unitProduction.AddUnitToQueue(this.m_unitData, this.m_slotId, false);
                                firstLoopExecuted = true;
                            }

                            return(0);
                        }
                    }

                    return(-50);
                }

                Debugger.Error("LogicTraingUnitCommand - Count is too high");

                return(-20);
            }

            return(-99);
        }
Пример #8
0
        public override int Execute(LogicLevel level)
        {
            LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

            if (playerAvatar != null)
            {
                if (this.m_unitData != null)
                {
                    if (this.m_unitData.GetVillageType() == 0)
                    {
                        if (!this.m_unitData.IsDonationDisabled())
                        {
                            bool containsUnit = false;
                            int  upgLevel     = playerAvatar.GetUnitUpgradeLevel(this.m_unitData);

                            LogicUnitProductionComponent unitProductionComponent = null;

                            if (this.m_quickDonate)
                            {
                                int cost = this.m_unitData.GetDonateCost();

                                if (!playerAvatar.HasEnoughDiamonds(cost, true, level) || !LogicDataTables.GetGlobals().EnableQuickDonateWar())
                                {
                                    playerAvatar.GetChangeListener().WarDonateFailed(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate);
                                    return(0);
                                }
                            }
                            else
                            {
                                LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);

                                if (LogicDataTables.GetGlobals().UseNewTraining())
                                {
                                    LogicUnitProduction unitProduction  = gameObjectManager.GetUnitProduction();
                                    LogicUnitProduction spellProduction = gameObjectManager.GetSpellProduction();

                                    if (unitProduction.GetWaitingForSpaceUnitCount(this.m_unitData) > 0)
                                    {
                                        if (unitProduction.GetUnitProductionType() == this.m_unitData.GetDataType())
                                        {
                                            containsUnit = true;
                                        }
                                    }

                                    if (spellProduction.GetWaitingForSpaceUnitCount(this.m_unitData) > 0)
                                    {
                                        if (spellProduction.GetUnitProductionType() == this.m_unitData.GetDataType())
                                        {
                                            containsUnit = true;
                                        }
                                    }
                                }
                                else
                                {
                                    for (int i = 0, c = gameObjectManager.GetNumGameObjects(); i < c; i++)
                                    {
                                        LogicGameObject gameObject = gameObjectManager.GetGameObjectByIndex(i);

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

                                            if (component != null)
                                            {
                                                unitProductionComponent = component;

                                                if (component.ContainsUnit(this.m_unitData))
                                                {
                                                    if (component.GetRemainingSeconds() == 0 && component.GetCurrentlyTrainedUnit() == this.m_unitData)
                                                    {
                                                        containsUnit = true;
                                                    }
                                                }
                                                else
                                                {
                                                    unitProductionComponent = null;
                                                }
                                            }
                                        }
                                    }
                                }

                                if (!containsUnit)
                                {
                                    if (playerAvatar.GetUnitCount(this.m_unitData) <= 0)
                                    {
                                        playerAvatar.GetChangeListener().WarDonateFailed(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate);
                                        return(0);
                                    }
                                }
                            }

                            if (this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                            {
                                playerAvatar.XpGainHelper(this.m_unitData.GetHousingSpace() * LogicDataTables.GetGlobals().GetDarkSpellDonationXP());
                                level.GetAchievementManager().AlianceSpellDonated((LogicSpellData)this.m_unitData);
                            }
                            else
                            {
                                playerAvatar.XpGainHelper(((LogicCharacterData)this.m_unitData).GetDonateXP());
                                level.GetAchievementManager().AlianceUnitDonated((LogicCharacterData)this.m_unitData);
                            }

                            playerAvatar.GetChangeListener().WarDonateOk(this.m_unitData, upgLevel, this.m_streamId, this.m_quickDonate);

                            if (this.m_quickDonate)
                            {
                                int cost = this.m_unitData.GetDonateCost();

                                playerAvatar.UseDiamonds(cost);
                                playerAvatar.GetChangeListener().DiamondPurchaseMade(12, this.m_unitData.GetGlobalID(), 0, cost, level.GetVillageType());

                                if (level.GetState() == 1 || level.GetState() == 3 &&
                                    this.m_unitData.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                {
                                    // TODO: Finish this.
                                }
                            }
                            else
                            {
                                if (!containsUnit)
                                {
                                    playerAvatar.CommodityCountChangeHelper(0, this.m_unitData, -1);
                                }

                                LogicResourceData trainingResource = this.m_unitData.GetTrainingResource();
                                int trainingCost = level.GetGameMode().GetCalendar().GetTrainingCost(this.m_unitData, upgLevel);
                                int refund       = playerAvatar.GetTroopDonationRefund() * trainingCost / 100;

                                playerAvatar.CommodityCountChangeHelper(0, trainingResource, LogicMath.Max(refund, 0));

                                if (level.GetState() == 1 || level.GetState() == 3)
                                {
                                    if (containsUnit)
                                    {
                                        if (LogicDataTables.GetGlobals().UseNewTraining())
                                        {
                                            LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);
                                            LogicUnitProduction    unitProduction    = this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER
                                                ? gameObjectManager.GetSpellProduction()
                                                : gameObjectManager.GetUnitProduction();

                                            unitProduction.RemoveTrainedUnit(this.m_unitData);
                                        }

                                        if (this.m_unitData.GetCombatItemType() == LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER)
                                        {
                                            LogicBuilding productionHouse = null;

                                            if (unitProductionComponent != null)
                                            {
                                                productionHouse = (LogicBuilding)unitProductionComponent.GetParent();
                                            }
                                            else
                                            {
                                                if (LogicDataTables.GetGlobals().UseTroopWalksOutFromTraining())
                                                {
                                                    LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);
                                                    int gameObjectCount = gameObjectManager.GetNumGameObjects();

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

                                                        if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                                                        {
                                                            LogicBuilding tmpBuilding = (LogicBuilding)gameObject;
                                                            LogicUnitProductionComponent tmpComponent = tmpBuilding.GetUnitProductionComponent();

                                                            if (tmpComponent != null)
                                                            {
                                                                if (tmpComponent.GetProductionType() == this.m_unitData.GetCombatItemType())
                                                                {
                                                                    if (tmpBuilding.GetBuildingData().GetProducesUnitsOfType() == this.m_unitData.GetUnitOfType() &&
                                                                        !tmpBuilding.IsUpgrading() &&
                                                                        !tmpBuilding.IsConstructing())
                                                                    {
                                                                        if (this.m_unitData.IsUnlockedForProductionHouseLevel(tmpBuilding.GetUpgradeLevel()))
                                                                        {
                                                                            if (productionHouse != null)
                                                                            {
                                                                                int seed = playerAvatar.GetExpPoints();

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

                                            if (productionHouse != null)
                                            {
                                                // TODO: Implement listener.
                                            }
                                        }
                                    }
                                    else
                                    {
                                        LogicArrayList <LogicComponent> components = level.GetComponentManagerAt(0).GetComponents(LogicComponentType.UNIT_STORAGE);

                                        for (int i = 0; i < components.Size(); i++)
                                        {
                                            LogicUnitStorageComponent unitStorageComponent = (LogicUnitStorageComponent)components[i];
                                            int idx = unitStorageComponent.GetUnitTypeIndex(this.m_unitData);

                                            if (idx != -1)
                                            {
                                                if (unitStorageComponent.GetUnitCount(idx) > 0)
                                                {
                                                    unitStorageComponent.RemoveUnits(this.m_unitData, 1);

                                                    if (LogicDataTables.GetGlobals().UseNewTraining())
                                                    {
                                                        LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(0);
                                                        LogicUnitProduction    unitProduction    = this.m_unitData.GetCombatItemType() != LogicCombatItemData.COMBAT_ITEM_TYPE_CHARACTER
                                                            ? gameObjectManager.GetSpellProduction()
                                                            : gameObjectManager.GetUnitProduction();

                                                        unitProduction.MergeSlots();
                                                        unitProduction.UnitRemoved();
                                                    }

                                                    break;
                                                }
                                            }
                                        }
                                    }

                                    // TODO: Finish this.
                                }
                            }

                            return(0);
                        }

                        return(-91);
                    }

                    return(-45);
                }
            }

            return(0);
        }
Пример #9
0
        public override int Execute(LogicLevel level)
        {
            if (level.GetVillageType() == 1)
            {
                if (this.m_gameObjectId != 0)
                {
                    LogicGameObjectManager gameObjectManager = level.GetGameObjectManagerAt(1);
                    LogicGameObject        gameObject        = gameObjectManager.GetGameObjectByID(this.m_gameObjectId);

                    if (gameObject != null && gameObject.GetGameObjectType() == LogicGameObjectType.BUILDING)
                    {
                        LogicBuilding building = (LogicBuilding)gameObject;

                        if (this.m_unitData != null && level.GetGameMode().GetCalendar().IsProductionEnabled(this.m_unitData))
                        {
                            if (this.m_unitData.GetVillageType() == 1)
                            {
                                LogicVillage2UnitComponent village2UnitComponent = building.GetVillage2UnitComponent();

                                if (village2UnitComponent != null)
                                {
                                    if (this.m_unitData.IsUnlockedForProductionHouseLevel(gameObjectManager.GetHighestBuildingLevel(this.m_unitData.GetProductionHouseData(), true))
                                        )
                                    {
                                        LogicClientAvatar playerAvatar  = level.GetPlayerAvatar();
                                        LogicResourceData trainResource = this.m_unitData.GetTrainingResource();
                                        int trainCost = this.m_unitData.GetTrainingCost(playerAvatar.GetUnitUpgradeLevel(this.m_unitData));

                                        if (playerAvatar.HasEnoughResources(trainResource, trainCost, true, this, false))
                                        {
                                            village2UnitComponent.TrainUnit(this.m_unitData);
                                            playerAvatar.CommodityCountChangeHelper(0, trainResource, -trainCost);
                                        }

                                        return(0);
                                    }

                                    return(-7);
                                }

                                return(-4);
                            }

                            return(-8);
                        }
                    }

                    return(-5);
                }

                return(-1);
            }

            return(-10);
        }
        public override int Execute(LogicLevel level)
        {
            if (level.IsReadyForAttack())
            {
                if (this.m_data != null && !level.IsAttackerHeroPlaced(this.m_data))
                {
                    if (level.GetVillageType() == this.m_data.GetVillageType())
                    {
                        int tileX = this.m_x >> 9;
                        int tileY = this.m_y >> 9;

                        if (level.GetTileMap().GetTile(tileX, tileY) != null)
                        {
                            if (level.GetTileMap().IsPassablePathFinder(this.m_x >> 8, this.m_y >> 8))
                            {
                                if (level.GetTileMap().IsValidAttackPos(tileX, tileY))
                                {
                                    LogicClientAvatar playerAvatar = level.GetPlayerAvatar();

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

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

                                            int health   = playerAvatar.GetHeroHealth(this.m_data);
                                            int upgLevel = playerAvatar.GetUnitUpgradeLevel(this.m_data);

                                            level.SetAttackerHeroPlaced(this.m_data,
                                                                        LogicPlaceHeroCommand.PlaceHero(this.m_data, level, this.m_x, this.m_y,
                                                                                                        this.m_data.GetHeroHitpoints(health, upgLevel), upgLevel));

                                            return(0);
                                        }
                                    }

                                    return(-5);
                                }

                                return(-4);
                            }

                            return(-2);
                        }

                        return(-3);
                    }

                    return(-23);
                }

                return(-5);
            }

            return(-1);
        }