#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.Players;
using Arthea.Continents.Areas.Characters.Enums;
namespace Arthea.Continents.Areas.Characters
{
/// <summary>
/// Implementation of a character list.
/// </summary>
public class CharList : List<Character>
{
#region [rgn] Methods (6)
// [rgn] Public Methods (6)
/// <summary>
/// Finds the name.
/// </summary>
/// <param name="name">The name.</param>
/// <returns>a character</returns>
public Character FindName(String name)
{
if (!name)
return null;
return Find(delegate(Character ch) { return name.IsPrefixOf(ch.Name); });
}
/// <summary>
/// Finds the player.
/// </summary>
/// <param name="name">The name.</param>
/// <returns>a character</returns>
public Character FindPlayer(String name)
{
foreach (Character ch in this)
{
if (!(ch is Player))
continue;
if (name.IsPrefixOf(ch.Name))
return ch;
}
return null;
}
/// <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()
{
foreach (Character ch in this)
{
if (ch.Hit < ch.MaxHit)
{
int gain = 1;
switch (ch.Position)
{
case Position.Sleeping:
gain += 3;
break;
case Position.Resting:
gain += 2;
break;
}
ch.Hit = ch.Hit + gain;
}
}
}
/// <summary>
/// Writes a line to each character.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="args">The args.</param>
public void WriteLine(string value, params object[] args)
{
foreach (Character ch in this)
{
if (ch is Player)
(ch as Player).WriteLine(value, args);
}
}
/// <summary>
/// Writes a line to each character.
/// </summary>
public void WriteLine()
{
foreach (Character ch in this)
{
if (ch is Player)
ch.WriteLine();
}
}
#endregion [rgn]
}
}