コード例 #1
0
        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);
                    }
                }
            }
        }
コード例 #2
0
        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);
        }