/
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.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]
    }
}