/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\items\potions\confusion\BaseConfusionBlastPotion.cs
Lines of code: 60
***********************************************************/


using System;
using Server;
using Server.Network;
using System.Collections.Generic;
using Server.Mobiles;

namespace Server.Items
{
	public abstract class BaseConfusionBlastPotion : BasePotion
	{
		private Timer m_Timer;
		
		public abstract int ConfusionRange { get; }
		

		public BaseConfusionBlastPotion( PotionEffect effect ) : base( 0xF06, effect )
		{
			Hue = 1362;
		}

		public BaseConfusionBlastPotion( 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 override void Drink( Mobile from )
		{
			if(UseDelaySystem.CheckContext(from, DelayContextType.ConfusePotion))
			{
				from.LocalOverheadMessage( MessageType.Regular, 0x22, 501789 ); // You must wait before trying again
				return;
			}
			
			UseDelaySystem.AddContext(from,DelayContextType.ConfusePotion,TimeSpan.FromSeconds(40));
			
			DoEffect(from);
		}
		
		
		public void DoEffect(Mobile from)
		{
			this.Consume();
			
			from.Combatant=null;
			Effects.SendLocationParticles( EffectItem.Create( from.Location, from.Map, EffectItem.DefaultDuration ), 0x36B0, 1, 14, 1324, 7, 9915, 0 );
			
			List<Mobile> targets = new List<Mobile>();
		
			foreach ( Mobile m in from.GetMobilesInRange( ConfusionRange ) )
			{
				if ( from != m && from.InLOS( m ) && from.ShouldHarm( m ) )
					targets.Add( m );
			}

			for ( int i = 0; i < targets.Count; ++i )
			{
				Mobile m = targets[i];
				
				Effects.SendLocationParticles( EffectItem.Create( m.Location, m.Map, EffectItem.DefaultDuration ), 0x36B0, 1, 14, 1324, 7, 9915, 0 );
				Effects.PlaySound( m.Location, m.Map, 0x28E );		
				
				m.Combatant=null;
				
				if(m is BaseCreature)((BaseCreature)m).NextReacquireTime=DateTime.Now+TimeSpan.FromSeconds(5+Utility.Random(30));				
			}		
		
		}
		


	}
}