#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]
}
}