示例#1
0
        public bool CanAddUnitToQueue(LogicCombatItemData data, bool ignoreCapacity)
        {
            if (data != null)
            {
                if (data.GetDataType() == this.m_unitProductionType)
                {
                    LogicGameObjectManager gameObjectManager = this.m_level.GetGameObjectManagerAt(0);
                    LogicBuilding          productionHouse   = gameObjectManager.GetHighestBuilding(data.GetProductionHouseData());

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

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

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

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

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

            return(false);
        }