コード例 #1
0
        /// <summary>
        /// Instantiates an item using static information.
        /// </summary>
        /// <param name="owner">The owner of this item</param>
        /// <param name="lot">The lot of this item</param>
        /// <param name="inventory">The inventory to add the item to, if left empty, this item will be left unmanaged</param>
        /// <param name="count">The count of the item to add</param>
        /// <param name="slot">The slot to add the item to</param>
        /// <param name="extraInfo">Optional LDD to set on the item</param>
        /// <param name="objectId">Explicit object Id for this item, generally only used for player instance items</param>
        /// <param name="rootItem">The root item this item is based on</param>
        /// <param name="isEquipped">Whether the game object has this item equipped or not</param>
        /// <param name="isBound">Whether the game object has bound this item or not</param>
        /// <param name="lootType">Where this item came from</param>
        /// <remarks>Note that <c>Start</c> still needs to be called on the item to be registered properly in the world.</remarks>
        /// <returns>The instantiated item or <c>null</c> if no slot could be acquired or if the item couldn't be added to the inventory</returns>
        public static async Task <Item> Instantiate(GameObject owner, Lot lot,
                                                    Inventory inventory, uint count, uint slot = default, LegoDataDictionary extraInfo = default,
                                                    ObjectId objectId = default, Item rootItem = default, bool isEquipped = false, bool isBound = false, LootType lootType = LootType.None)
        {
            // Try to find the slot at which this item should be inserted if no explicit slot is provided
            if (inventory != default && slot == default)
            {
                try
                {
                    slot = inventory.ClaimSlot();
                }
                catch (InventoryFullException)
                {
                    return(null);
                }
            }

            var itemTemplate      = (await ClientCache.FindAsync <Core.Client.Objects>(lot));
            var itemRegistryEntry = (await ClientCache.FindAllAsync <ComponentsRegistry>(lot)).FirstOrDefault(
                r => r.Componenttype == (int)ComponentId.ItemComponent
                );

            if (itemRegistryEntry == default)
            {
                return(default);