using System;
using Server;
using Server.Network;

namespace Server.Items
{
	public abstract class BaseManaElixir : BasePotion
	{
		public override int Hue{ get { return 0x43C; } }

		public abstract int MinMana { get; }
		public abstract int MaxMana { get; }
		public abstract double Delay { get; }

		public BaseManaElixir( PotionEffect effect ) : base( 0x180F, effect )
		{
		}

		public BaseManaElixir( Serial serial ) : base( serial )
		{
		}

		public void DoMana( Mobile from )
		{
			from.Mana = from.Mana + ( Utility.RandomMinMax( MinMana, MaxMana ) );
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );
			writer.Write( (int) 0 ); // version
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			int version = reader.ReadInt();
		}

		public override void Drink( Mobile from )
		{
			if ( from.Mana < from.ManaMax )
			{
				if ( from.BeginAction( typeof( BaseManaElixir ) ) )
				{
					DoMana( from );

					BasePotion.PlayDrinkEffect( from );

					this.Consume();

					Timer.DelayCall( TimeSpan.FromSeconds( Delay ), new TimerStateCallback( ReleaseManaLock ), from );
				}
				else
					from.LocalOverheadMessage( MessageType.Regular, 0x22, true, "You must wait 10 seconds before using another mana potion." );

			}
			else
				from.SendMessage( "You decide against drinking this potion, as you are already at full mana." );
		}

		private static void ReleaseManaLock( object state )
		{
			((Mobile)state).EndAction( typeof( BaseManaElixir ) );
		}
	}
}
