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