예제 #1
0
        /// <summary>
        /// Writes the inventory of the current Avatar to the specified IMessageContext.
        /// </summary>
        /// <param name="owner">The Avatar in which to retrieve inventory.</param>
        /// <param name="context">The IMessageContext used to send the inventory details to the client.</param>
        public static void Inventory(this IAvatar owner, IAvatar looker, IMessageContext context)
        {
            // If this is an NPC and a merchant then send down the template instances instead of real items.
            IEnumerable <IItem> items = null;

            if (owner is IMerchant)
            {
                // Return the inventory templates for the current NPC.
                items = (owner as IMerchant).GetGoodsAndServices();

                if (looker != null && owner is Merchant)
                {
                    // Set the buy costs for all of the items before sending them down.
                    foreach (var item in items)
                    {
                        Item i = item as Item;
                        if (i != null)
                        {
                            i.BuyCost       = i.GetBuyCost(looker, (owner as Merchant).MarkupPercentage);
                            i.EmblemBuyCost = i.GetEmblemCost(looker);
                        }
                    }

                    // Then send down the sell costs for all of the inventory items the player has.
                    var lookerItems = looker.GetAllChildren().Where(c => c is Item).Select(c => c as Item);
                    foreach (var item in lookerItems)
                    {
                        item.SellCost       = item.GetSellCost(looker, (owner as Merchant).MarkdownPercentage);
                        item.EmblemSellCost = item.GetEmblemCost(owner);
                    }
                }
            }
            else
            {
                items = (from c in owner.GetAllChildren()
                         where (c as IItem) != null
                         select c as IItem);
            }
            if (items != null)
            {
                foreach (var item in items)
                {
                    context.AddRange(item.ToRdl());
                }
            }
        }