#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.Xml.Serialization;
using Arthea.Affects;
using Arthea.Connections.Players;
using Arthea.Continents.Areas.Characters.Enums;
using Arthea.Creation.Attributes;
using Arthea.Database.Interfaces;
using Arthea.Environment;
using Arthea.Interfaces;
using Arthea.Races;
using Arthea.Scripts;
namespace Arthea.Continents.Areas.Characters
{
/// <summary>
/// Implements a character index as a basis for duplicate characters
/// </summary>
public class CharIndex : Scriptable, Indexed
{
#region [rgn] Fields (16)
private const int defautVitals = 100;
private AffectList affects = new AffectList();
[EditShow] private Area area;
private string description;
[EditShow] private uint id;
private byte level;
private int maxHit = defautVitals;
private int maxMana = defautVitals;
private int maxMove = defautVitals;
private string name;
private Position position = Position.Standing;
private Race race = new HumanRace();
private string roomDescr;
private ScriptList scripts = new ScriptList();
private Sex sex;
private string shortDescr;
#endregion [rgn]
#region [rgn] Constructors (3)
/// <summary>
/// Initializes a new instance of the <see cref="CharIndex"/> class.
/// </summary>
/// <param name="area">The area.</param>
/// <param name="id">The id.</param>
/// <param name="level">The level.</param>
/// <param name="name">The name.</param>
/// <param name="shortDescr">The short descr.</param>
/// <param name="roomDescr">The room descr.</param>
public CharIndex(Area area, uint id, byte level, string name, string shortDescr, string roomDescr)
{
this.area = area;
this.id = id;
this.level = level;
this.name = name;
this.shortDescr = shortDescr;
this.roomDescr = roomDescr;
}
/// <summary>
/// Initializes a new instance of the <see cref="CharIndex"/> class.
/// </summary>
/// <param name="level">The level.</param>
/// <param name="name">The name.</param>
public CharIndex(byte level, string name)
{
this.level = level;
this.name = name;
}
/// <summary>
/// Initializes a new instance of the <see cref="CharIndex"/> class.
/// </summary>
public CharIndex()
{
}
#endregion [rgn]
#region [rgn] Properties (17)
/// <summary>
/// Gets or sets the affects.
/// </summary>
/// <value>The affects.</value>
public AffectList Affects
{
get { return affects; }
set { affects = value; }
}
/// <summary>
/// Gets or sets the area.
/// </summary>
/// <value>The area.</value>
[XmlIgnore]
public Area Area
{
get { return area; }
set { area = value; }
}
/// <summary>
/// Gets or sets the description.
/// </summary>
/// <value>The description.</value>
public string Description
{
get { return description; }
set { description = value; }
}
/// <summary>
/// Gets or sets the level.
/// </summary>
/// <value>The level.</value>
public byte Level
{
get { return level; }
set { level = value; }
}
/// <summary>
/// Gets or sets the max hit.
/// </summary>
/// <value>The max hit.</value>
public int MaxHit
{
get { return maxHit; }
set { maxHit = value; }
}
/// <summary>
/// Gets or sets the max mana.
/// </summary>
/// <value>The max mana.</value>
public int MaxMana
{
get { return maxMana; }
set { maxMana = value; }
}
/// <summary>
/// Gets or sets the max move.
/// </summary>
/// <value>The max move.</value>
public int MaxMove
{
get { return maxMove; }
set { maxMove = value; }
}
/// <summary>
/// Gets or sets the position.
/// </summary>
/// <value>The position.</value>
public Position Position
{
get { return position; }
set { position = value; }
}
/// <summary>
/// Gets or sets the race.
/// </summary>
/// <value>The race.</value>
[XmlIgnore]
public Race Race
{
get { return race; }
set { race = value; }
}
/// <summary>
/// Gets or sets the room descr.
/// </summary>
/// <value>The room descr.</value>
public string RoomDescr
{
get { return roomDescr; }
set { roomDescr = value; }
}
/// <summary>
/// Gets or sets the scripts.
/// </summary>
/// <value>The scripts.</value>
public ScriptList Scripts
{
get { return scripts; }
set { scripts = value; }
}
/// <summary>
/// Gets or sets the sex.
/// </summary>
/// <value>The sex.</value>
public Sex Sex
{
get { return sex; }
set { sex = value; }
}
/// <summary>
/// Gets the size.
/// </summary>
/// <value>The size.</value>
public Size Size
{
get { return race == null ? Size.Medium : race.Size; }
}
/// <summary>
/// Gets or sets the race as a string.
/// </summary>
/// <value>The race as a string.</value>
[XmlElement("Race")]
public string XmlRace
{
get { return race.Name; }
set { race = Lists.Races.FindName(value); }
}
#region Indexed Members
/// <summary>
/// Gets or sets the id.
/// </summary>
/// <value>The id.</value>
public uint Id
{
get { return id; }
set { id = value; }
}
#endregion
#region Scriptable Members
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
public string Name
{
get { return name; }
set { name = value; }
}
/// <summary>
/// Gets or sets the short descr.
/// </summary>
/// <value>The short descr.</value>
public string ShortDescr
{
get { return shortDescr; }
set { shortDescr = value; }
}
#endregion
#endregion [rgn]
#region [rgn] Methods (4)
// [rgn] Public Methods (4)
/// <summary>
/// Attaches this instance to applicable lists.
/// </summary>
public void Attach()
{
if (area != null)
area.Characters.Add(this);
Lists.CharIndexes.Add(this);
foreach (Script script in scripts)
{
script.Code.Attach();
}
}
/// <summary>
/// Creates an instance for editing by a player.
/// </summary>
/// <param name="player">The player.</param>
/// <param name="argument">The argument.</param>
public static void Create(Player player, String argument)
{
uint id = player.Room.Area.GetNextCharId();
if (id == 0)
{
player.WriteLine("No more characters available in this area.");
return;
}
CharIndex index = new CharIndex();
index.Name = index.ShortDescr = argument;
index.RoomDescr = string.Format("{0} is here.", index.Name);
index.Area = player.Room.Area;
index.Id = id;
index.Attach();
player.WriteLine("Character created.");
player.Connection.Edit(index);
}
/// <summary>
/// Releases this instance from applicable lists.
/// </summary>
public void Release()
{
if (area != null)
area.Characters.Remove(this);
Lists.CharIndexes.Remove(this);
}
/// <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 id.ToString();
}
#endregion [rgn]
#region Scriptable Members
/// <summary>
/// Creates a script of proper type.
/// </summary>
/// <returns></returns>
public Script CreateScript(ScriptCode code, String trigger)
{
return new CharScript(code, trigger);
}
#endregion
}
}