#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.Continents.Areas;
using Arthea.Continents.Areas.Characters;
using Arthea.Continents.Areas.Items;
using Arthea.Continents.Areas.Rooms;
using Arthea.Environment;
namespace Arthea.Commands.Admin
{
/// <summary>
/// Implementation of goto command.
/// </summary>
public class GotoCommand : Command
{
#region [rgn] Constructors (1)
/// <summary>
/// Initializes a new instance of the <see cref="GotoCommand"/> class.
/// </summary>
public GotoCommand() : base("goto", Levels.Admin)
{
}
#endregion [rgn]
#region [rgn] Methods (2)
// [rgn] Public Methods (1)
/// <summary>
/// Processes the command for a player.
/// </summary>
/// <param name="player">The player.</param>
/// <param name="argument">The argument.</param>
public override void Process(Player player, String argument)
{
uint id;
Area area;
Character ch;
Item item;
if (!argument)
{
player.WriteLine("Goto where? (area,room id,character,item)");
return;
}
String arg = argument.FirstArg();
if (uint.TryParse(arg, out id))
{
if (Lists.Rooms[id] == null)
{
player.WriteLine("No such room.");
return;
}
Goto(player, Lists.Rooms[id]);
}
else if ((area = Lists.Areas.FindName(arg)) != null)
{
if (area.Rooms[area.BaseId] == null)
{
player.WriteLine("That area is unavailable.");
return;
}
Goto(player, area.Rooms[area.BaseId]);
}
else if ((ch = Lists.Characters.FindName(arg)) != null)
{
if (ch.Room == null)
{
player.WriteLine("That person is unavailable.");
return;
}
Goto(player, ch.Room);
}
else if ((item = Lists.Items.FindName(arg)) != null)
{
Room room;
if (item.Room == null)
{
if (item.CarriedBy == null || item.CarriedBy.Room == null)
{
player.WriteLine("That item is unavailable.");
return;
}
else
{
room = item.CarriedBy.Room;
}
}
else
{
room = item.Room;
}
Goto(player, room);
}
else
{
player.WriteLine("No such room, area, character or item.");
return;
}
}
// [rgn] Private Methods (1)
private static void Goto(Player player, Room room)
{
player.Room = room;
LookCommand.Instance.Process(player, string.Empty);
}
#endregion [rgn]
}
}