/
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 Arthea.Connections.Players;
using Arthea.Creation;
using Arthea.Creation.Attributes;
using Arthea.Database.Interfaces;
using Arthea.Environment;
using Arthea.Interfaces;

namespace Arthea.Scripts
{
    /// <summary>
    /// Implementation of a script's code.
    /// </summary>
    public class ScriptCode : CustomEditType, Indexed
    {
        #region [rgn] Fields (3)

        private string description;
        private uint id;
        [TextEdit] private string text;

        #endregion [rgn]

        #region [rgn] Constructors (2)

        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptCode"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        public ScriptCode(uint id)
        {
            this.id = id;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ScriptCode"/> class.
        /// </summary>
        public ScriptCode()
        {
        }

        #endregion [rgn]

        #region [rgn] Properties (3)

        /// <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 code.
        /// </summary>
        /// <value>The code.</value>
        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        /// <value>The id.</value>
        public uint Id
        {
            get { return id; }
            set { id = value; }
        }

        #endregion [rgn]

        #region [rgn] Methods (4)

        // [rgn] Public Methods (4)

        /// <summary>
        /// Attaches this instance.
        /// </summary>
        public void Attach()
        {
            Lists.Scripts.Add(this);
        }

        /// <summary>
        /// Gets the next available id.
        /// </summary>
        /// <returns>a uint</returns>
        public static uint GetNextId()
        {
            uint count = (uint) Lists.Scripts.Count;

            while (Lists.Scripts.ContainsKey(count))
                count++;

            return count + 1;
        }

        /// <summary>
        /// Releases this instance.
        /// </summary>
        public void Release()
        {
            Lists.Scripts.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 CustomEditType Members

        /// <summary>
        /// Allows custom editing of this type by player.
        /// </summary>
        /// <param name="player">The player.</param>
        /// <param name="editor">The editor values.</param>
        /// <param name="argument">The argument.</param>
        public void CustomEdit(Player player, OlcField editor, String argument)
        {
            player.Connection.Edit(this);
        }

        #endregion
    }
}