/
etc/
lib/
src/Abilities/
src/Abilities/Skills/
src/Abilities/Spells/
src/Abilities/Spells/Enums/
src/Affects/
src/ArtheaConsole/
src/ArtheaConsole/Properties/
src/ArtheaGUI/Properties/
src/Clans/Enums/
src/Commands/Communication/
src/Commands/ItemCommands/
src/Connections/
src/Connections/Colors/
src/Connections/Enums/
src/Connections/Players/
src/Connections/Players/Enums/
src/Continents/
src/Continents/Areas/
src/Continents/Areas/Characters/
src/Continents/Areas/Characters/Enums/
src/Continents/Areas/Items/
src/Continents/Areas/Items/Enums/
src/Continents/Areas/Rooms/
src/Continents/Areas/Rooms/Enums/
src/Continents/Areas/Rooms/Exits/
src/Creation/
src/Creation/Attributes/
src/Creation/Interfaces/
src/Database/
src/Database/Interfaces/
src/Environment/
src/Properties/
src/Scripts/Enums/
src/Scripts/Interfaces/
#region Arthea License

/***********************************************************************
*  Arthea MUD by R. Jennings (2007)      http://arthea.googlecode.com/ *
*  By using this code you comply with the Artistic and GPLv2 Licenses. *
***********************************************************************/

#endregion

using System.Collections.Generic;
using Arthea.Connections.Colors;
using Arthea.Connections.Players;
using Arthea.Continents.Areas.Items.Enums;

namespace Arthea.Continents.Areas.Items
{
    /// <summary>
    /// Implementation of a item list.
    /// </summary>
    public class ItemList : List<Item>
    {
        #region [rgn] Methods (5)

        // [rgn] Public Methods (5)

        /// <summary>
        /// Finds the name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns>an item</returns>
        public Item FindName(String name)
        {
            if (!name)
                return null;

            return Find(delegate(Item item) { return name.IsPrefixOf(item.Name); });
        }

        /// <summary>
        /// Finds the wear loc.
        /// </summary>
        /// <param name="wear">The wear.</param>
        /// <returns>an item</returns>
        public Item FindWearLoc(WearLocation wear)
        {
            return Find(delegate(Item item) { return item.WearLoc == wear; });
        }

        /// <summary>
        /// Shows to player.
        /// </summary>
        /// <param name="player">The player.</param>
        /// <param name="fShort">if set to <c>true</c> to display short description.</param>
        public void ShowToPlayer(Player player, bool fShort)
        {
            Dictionary<string, int> iShow = new Dictionary<string, int>();

            foreach (Item item in this)
            {
                if (item.WearLoc != WearLocation.None)
                    continue;

                string pstr = (fShort ? item.ShortDescr : item.RoomDescr);

                if (iShow.ContainsKey(pstr))
                {
                    iShow[pstr]++;
                    continue;
                }

                iShow.Add(pstr, 1);
            }

            foreach (KeyValuePair<string, int> entry in iShow)
            {
                if (entry.Value != 1)
                {
                    player.Write("({0}) ", entry.Value);
                }

                player.WriteLine(CustomColor.Items + "{0}~X", entry.Key);
            }
        }

        /// <summary>
        /// Returns a <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
        /// </returns>
        public override string ToString()
        {
            return Count.ToString();
        }

        /// <summary>
        /// Updates this instance.
        /// </summary>
        public void Update()
        {
        }

        #endregion [rgn]
    }
}