/
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.Abilities.Spells;
using Arthea.Abilities.Spells.Enums;
using Arthea.Connections.Players;
using Arthea.Environment;

namespace Arthea.Commands
{
    /// <summary>
    /// Implements a cast command.
    /// </summary>
    public class CastCommand : Command
    {
        #region [rgn] Constructors (1)

        /// <summary>
        /// Initializes a new instance of the <see cref="CastCommand"/> class.
        /// </summary>
        public CastCommand() : base("cast", "casts a spell")
        {
        }

        #endregion [rgn]

        #region [rgn] Methods (1)

        // [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)
        {
            if (!argument)
            {
                player.WriteLine("Cast what?");
                return;
            }

            String arg = argument.FirstArg();

            Spell spell = Lists.Abilities.FindSpell(arg);

            if (spell == null)
            {
                player.WriteLine("No such spell.");
                return;
            }

            if (spell.Level[player.Class] == 0 || player.Learned[Name] == 0
                || spell.Level[player.Class] > player.Level)
            {
                player.WriteLine("You don't know how to cast that.");
                return;
            }

            object obj = null;

            switch (spell.Target)
            {
                case SpellTarget.Offensive:
                    obj = player.Room.Characters.FindName(argument);
                    if (obj == null)
                    {
                        player.WriteLine("They aren't here.");
                        return;
                    }
                    break;
                case SpellTarget.Defensive:
                    obj = player.Room.Characters.FindName(argument);
                    if (obj == null)
                    {
                        player.WriteLine("They aren't here.");
                        return;
                    }
                    break;
                case SpellTarget.Ignore:
                    break;
                case SpellTarget.Self:
                    obj = player;
                    break;
                case SpellTarget.Item:
                    obj = player.Carrying.FindName(argument);
                    if (obj == null) obj = player.Room.Items.FindName(argument);

                    if (obj == null)
                    {
                        player.WriteLine("You can't find that item.");
                        return;
                    }
                    break;
            }

            if (spell.Mana > player.Mana)
            {
                player.WriteLine("You don't have enough mana.");
                return;
            }

            player.Mana -= spell.Mana;


            spell.Process(player, obj);

            player.Connection.Wait = spell.WaitTime;
        }

        #endregion [rgn]
    }
}