/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\Items\Weapons\Abilities\PsychicAttack.cs
Lines of code: 60
***********************************************************/


using System;
using System.Collections;
using Server.Items;

namespace Server.Items
{
	/// <summary>
	/// Makes mana consuption of target be much higher (like mind rot)
	/// </summary>
	public class PsychicAttack : WeaponAbility
	{
		private static Hashtable m_Registry = new Hashtable();
		public static Hashtable Registry { get { return m_Registry; } }

		public PsychicAttack()
		{
		}

		public override int BaseMana { get { return 25; } }



		public override void OnHit( Mobile attacker, Mobile defender, int damage )
		{
			if( !Validate( attacker ) || !CheckMana( attacker, true ) )
				return;

			ClearCurrentAbility( attacker );

			int effect=(int)((attacker.Str-defender.Int)/5)+10;	
			if(effect<1)effect=1;
			
			StartEffect(defender, (int)((10+Utility.Random(11)) * (defender.Player ? 1.0 : 2.0 )) ,effect);
		}
		
		private static Hashtable m_Table = new Hashtable();
		
		//effect is how much SDI to remove
		public static void StartEffect(Mobile defender,int seconds,int effect)
		{
		if(m_Table.Contains(defender))m_Table.Remove(defender);
		
		m_Table[defender]=effect;
		
		
		new InternalTimer( defender,TimeSpan.FromSeconds(seconds)).Start();
		}
		
		
		public static void StopEffect(Mobile defender)
		{
		if(defender==null)return;
		if(m_Table.Contains(defender))m_Table.Remove(defender);		
		}
		
		public static int GetEffect(Mobile defender)
		{
		if(defender==null)return 0;
		if(m_Table.Contains(defender))return (int)m_Table[defender];
		return 0;		
		}		
		
		
		private class InternalTimer : Timer
		{
			private Mobile m_Defender;
			private DateTime expire;

			public InternalTimer( Mobile defender,TimeSpan duration ): base(TimeSpan.FromSeconds(1),TimeSpan.FromSeconds(4) )	
			{
				m_Defender = defender;
				expire=DateTime.Now+duration;
			}

			protected override void OnTick()
			{
				if(m_Defender==null || !m_Defender.Alive || DateTime.Now>expire)
				{
				StopEffect(m_Defender);
				Stop();
				}
	
			}
		}
		
	}
}