Ejemplo n.º 1
0
        /// <summary>
        /// Gives the 'available' amount inventory + queued
        /// queueSize total amount of queued items indicator for workload
        /// </summary>
        private static int AvailableAmount(IMyProductionBlock productionBlock, VRage.Game.MyDefinitionId materialId, VRage.Game.MyDefinitionBase blueprintDefinition, out int queueSize)
        {
            var queue          = productionBlock.GetQueue();
            var inventory      = productionBlock.OutputInventory;
            var inventoryItems = inventory != null?inventory.GetItems() : null;

            var amount = 0;

            queueSize = 0;
            if (inventoryItems != null)
            {
                foreach (var item in inventoryItems)
                {
                    if (item.Content.TypeId == materialId.TypeId && item.Content.SubtypeId == materialId.SubtypeId)
                    {
                        amount += (int)item.Amount;
                    }
                }
            }

            if (queue != null)
            {
                foreach (var item in queue)
                {
                    queueSize += (int)item.Amount;
                    if (item.Blueprint.Id.Equals(blueprintDefinition.Id))
                    {
                        amount += (int)item.Amount;
                    }
                }
            }

            return(amount);
        }
        /// <summary>
        /// Gives the 'available' amount inventory + queued
        /// queueSize total amount of queued items indicator for workload
        /// </summary>
        private static int AvailableAmount(IMyProductionBlock productionBlock, VRage.Game.MyDefinitionId materialId, VRage.Game.MyDefinitionBase blueprintDefinition, out int queueSize)
        {
            var queue              = productionBlock.GetQueue();
            var inventory          = productionBlock.OutputInventory;
            var tempInventoryItems = new List <VRage.Game.ModAPI.Ingame.MyInventoryItem>();

            if (inventory != null)
            {
                inventory.GetItems(tempInventoryItems);
            }
            var amount = 0;

            queueSize = 0;
            foreach (var item in tempInventoryItems)
            {
                if ((VRage.Game.MyDefinitionId)item.Type == materialId)
                {
                    amount += (int)item.Amount;
                }
            }

            if (queue != null)
            {
                foreach (var item in queue)
                {
                    queueSize += (int)item.Amount;
                    if (item.Blueprint.Id.Equals(blueprintDefinition.Id))
                    {
                        amount += (int)item.Amount;
                    }
                }
            }

            return(amount);
        }