예제 #1
0
        /// <summary>
        /// Add items of the definition id specified.
        ///
        /// If Id is an item, simply add the items.
        /// If Id is a tag, add a random item with that tag.
        /// If Id is loot table, add results of that loot table.
        /// </summary>
        /// <param name="inventory"></param>
        /// <param name="id"></param>
        /// <param name="amount"></param>
        /// <returns>True if item added, false if item didn't fit</returns>
        public static bool AddItemsFuzzyOrLoot(this MyInventoryBase inventory, MyDefinitionId id, int amount = 1)
        {
            var result = true;

            if (id.TypeId == typeof(MyObjectBuilder_LootTableDefinition))
            {
                var lootTableDefinition = MyDefinitionManager.Get <MyLootTableDefinition>(id);
                for (var i = 0; i < amount; i++)
                {
                    inventory.GenerateContent(lootTableDefinition);
                }
            }
            else if (id.TypeId == typeof(MyObjectBuilder_ItemTagDefinition))
            {
                result = inventory.AddItemsWithTag(id.SubtypeId, amount, true);
            }
            else
            {
                result = inventory.AddItems(id, amount);
            }

            return(result);
        }