#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; using System.Reflection; using Arthea.Continents.Areas.Characters; using Arthea.Continents.Areas.Items; using Arthea.Continents.Areas.Rooms; using Arthea.Environment; using Arthea.Interfaces; namespace Arthea.Scripts { /// <summary> /// Implementation of a room script. /// </summary> public class RoomScript : Script { #region [rgn] Constructors (2) /// <summary> /// Initializes a new instance of the <see cref="RoomScript"/> class. /// </summary> /// <param name="code">The code.</param> /// <param name="trigger">The trigger.</param> public RoomScript(ScriptCode code, string trigger) : base(code, trigger) { } /// <summary> /// Initializes a new instance of the <see cref="RoomScript"/> class. /// </summary> public RoomScript() { } #endregion [rgn] #region [rgn] Methods (4) // [rgn] Public Methods (3) /// <summary> /// Loads a character. /// </summary> /// <param name="from">From.</param> /// <param name="argument">The argument.</param> public void CLoad(Room from, String argument) { uint id; CharIndex index; if (!uint.TryParse(argument, out id) || (index = Lists.CharIndexes[id]) == null) { Log.Bug("CharScript.CLoad: Invalid argument (script {0})", Code.Id); return; } Character vict = new Character(index); vict.Attach(); from.Characters.Add(vict); } /// <summary> /// Echoes the specified room. /// </summary> /// <param name="room">The room.</param> /// <param name="argument">The argument.</param> public void Echo(Room room, String argument) { room.WriteLine(argument); } /// <summary> /// Loads an item to the room. /// </summary> /// <param name="room">The room.</param> /// <param name="argument">The argument.</param> public void ILoad(Room room, String argument) { uint id; ItemIndex index; if (!uint.TryParse(argument, out id) || (index = Lists.ItemIndexes[id]) == null) { Log.Bug("RoomScript.ILoad: Invalid argument (script {0})", Code.Id); return; } Item item = new Item(index); item.Attach(); room.Items.Add(item); } // [rgn] Protected Methods (1) /// <summary> /// Interprets a script command. /// </summary> /// <param name="from">The object with the script.</param> /// <param name="cmd">The command (method name).</param> /// <param name="argument">The argument.</param> /// <returns>true if a command was interpreted</returns> protected override bool InterpretCommand(Scriptable from, String cmd, String argument) { MethodInfo method = GetType().GetMethod(cmd, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public, null, new Type[] {typeof (Room), typeof (String)}, null); if (method == null) return false; method.Invoke(this, new object[] {from, argument}); return true; } #endregion [rgn] } }