/// <summary>
        ///     Executes this command.
        /// </summary>
        public override int Execute(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseNewTraining())
            {
                if (level.GetVillageType() == 0)
                {
                    LogicClientAvatar   playerAvatar   = level.GetPlayerAvatar();
                    LogicUnitProduction unitProduction = this._productionType == 1
                        ? level.GetGameObjectManager().GetSpellProduction()
                        : level.GetGameObjectManager().GetUnitProduction();

                    if (unitProduction.CanBeBoosted())
                    {
                        int cost = unitProduction.GetBoostCost();

                        if (playerAvatar.HasEnoughDiamonds(cost, true, level))
                        {
                            playerAvatar.UseDiamonds(cost);
                            unitProduction.Boost();

                            return(0);
                        }

                        return(-2);
                    }

                    return(-1);
                }

                return(-32);
            }

            return(-99);
        }
        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);
                    }
                }
            }
        }
        public override int Execute(LogicLevel level)
        {
            if (level.GetVillageType() == 0)
            {
                LogicUnitProduction unitProduction = null;

                switch (this.m_index)
                {
                case 1:
                    unitProduction = level.GetGameObjectManagerAt(0).GetUnitProduction();
                    break;

                case 2:
                    unitProduction = level.GetGameObjectManagerAt(0).GetSpellProduction();
                    break;
                }

                if (unitProduction == null)
                {
                    return(-1);
                }

                unitProduction.SetLocked(this.m_disabled);

                return(0);
            }

            return(-32);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Trains the unit with new training.
        /// </summary>
        public int NewTrainingUnit(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseNewTraining())
            {
                LogicUnitProduction unitProduction = this._spellProduction ? level.GetGameObjectManager().GetSpellProduction() : level.GetGameObjectManager().GetUnitProduction();
                LogicClientAvatar   playerAvatar   = level.GetPlayerAvatar();
                Int32 remainingSecs = unitProduction.GetTotalRemainingSeconds();
                Int32 speedUpCost   = LogicGamePlayUtil.GetSpeedUpCost(remainingSecs, this._spellProduction ? 1 : 4, level.GetVillageType());

                if (!level.GetMissionManager().IsTutorialFinished())
                {
                    if (speedUpCost > 0 && LogicDataTables.GetGlobals().GetTutorialTrainingSpeedUpCost() > 0)
                    {
                        speedUpCost = LogicDataTables.GetGlobals().GetTutorialTrainingSpeedUpCost();
                    }
                }

                if (playerAvatar.HasEnoughDiamonds(speedUpCost, true, level))
                {
                    playerAvatar.UseDiamonds(speedUpCost);
                    unitProduction.SpeedUp();

                    return(0);
                }

                return(-1);
            }

            return(-99);
        }
        public int SpeedUpNewTrainingUnit(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseNewTraining())
            {
                LogicUnitProduction unitProduction = this.m_spellProduction ? level.GetGameObjectManager().GetSpellProduction() : level.GetGameObjectManager().GetUnitProduction();
                LogicClientAvatar   playerAvatar   = level.GetPlayerAvatar();

                int remainingSecs = unitProduction.GetTotalRemainingSeconds();
                int speedUpCost   = LogicGamePlayUtil.GetSpeedUpCost(remainingSecs, this.m_spellProduction ? 1 : 4, level.GetVillageType());

                if (!level.GetMissionManager().IsTutorialFinished())
                {
                    if (speedUpCost > 0 && LogicDataTables.GetGlobals().GetTutorialTrainingSpeedUpCost() >= 0)
                    {
                        speedUpCost = LogicDataTables.GetGlobals().GetTutorialTrainingSpeedUpCost();
                    }
                }

                if (playerAvatar.HasEnoughDiamonds(speedUpCost, true, level))
                {
                    playerAvatar.UseDiamonds(speedUpCost);
                    unitProduction.SpeedUp();
                    playerAvatar.GetChangeListener().DiamondPurchaseMade(unitProduction.GetUnitProductionType() == LogicDataType.CHARACTER ? 2 : 7, 0, 0, speedUpCost, level.GetVillageType());

                    return(0);
                }

                return(-1);
            }

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

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

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

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

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

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

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

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

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

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

                return(requiredSpellHousingSpace <= freeSpellHousingSpace);
            }

            return(false);
        }
        /// <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 override int Execute(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseNewTraining())
            {
                if (!LogicDataTables.GetGlobals().UseDragInTraining() &&
                    !LogicDataTables.GetGlobals().UseDragInTrainingFix() &&
                    !LogicDataTables.GetGlobals().UseDragInTrainingFix2())
                {
                    return(-51);
                }

                LogicUnitProduction unitProduction = this.m_spellProduction ? level.GetGameObjectManager().GetSpellProduction() : level.GetGameObjectManager().GetUnitProduction();

                if (unitProduction.GetSlotCount() > this.m_slotIdx)
                {
                    if (unitProduction.GetSlotCount() >= this.m_dragIdx)
                    {
                        if (this.m_slotIdx >= 0)
                        {
                            if (this.m_dragIdx >= 0)
                            {
                                return(unitProduction.DragSlot(this.m_slotIdx, this.m_dragIdx) ? 0 : -5);
                            }

                            return(-4);
                        }

                        return(-3);
                    }

                    return(-2);
                }

                return(-1);
            }

            return(-50);
        }
Exemplo n.º 9
0
        public override int Execute(LogicLevel level)
        {
            if (LogicDataTables.GetGlobals().UseNewTraining())
            {
                LogicUnitProduction unitProduction = this.m_gameObjectId == -2
                    ? level.GetGameObjectManager().GetUnitProduction()
                    : this.m_gameObjectId == -1
                        ? level.GetGameObjectManager().GetSpellProduction()
                        : null;

                if (unitProduction != null)
                {
                    unitProduction.SetBoostPause(false);
                    this.UpdateProductionHouseListeners(level);
                }

                return(0);
            }

            LogicGameObject gameObject = level.GetGameObjectManager().GetGameObjectByID(this.m_gameObjectId);

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

                if (building.CanStopBoost())
                {
                    building.SetBoostPause(false);
                    building.GetListener().RefreshState();

                    return(0);
                }
            }

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