using System;
using Server;
using Server.Mobiles;
using Server.Network;

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

		public abstract int MinRejuv { get; }
		public abstract int MaxRejuv { get; }
		public abstract double Delay { get; }

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

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

		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 void DoRejuv( Mobile from )
		{
			int min = MinRejuv;
			int max = MaxRejuv;

			from.Mana = from.Mana + ( Utility.RandomMinMax( min, max ) );
			from.Stam = from.Stam + ( Utility.RandomMinMax( min, max ) );

			if ( from is PlayerMobile )
			{
				min = (int)(min * Server.Misc.Settings.HitPoints());
				max = (int)(max * Server.Misc.Settings.HitPoints());
			}

			from.Hits = from.Hits + ( Utility.RandomMinMax( min, max ) );
		}

		public override void Drink( Mobile from )
		{
			if ( from.BeginAction( typeof( BaseVigorElixir ) ) )
			{
				DoRejuv( from );

				BasePotion.PlayDrinkEffect( from );

				this.Consume();

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

		private static void ReleaseRejuvenateLock( object state )
		{
			((Mobile)state).EndAction( typeof( BaseVigorElixir ) );
		}
	}
}
