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


using System;
using System.Collections;
using Server;
using Server.Spells;

namespace Server.Items
{
	/// <summary>
	/// chain lightning effect arrow
	/// </summary>
	public class LightningArrow : WeaponAbility
	{
		public LightningArrow()
		{
		}

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

		//public override void OnHit( Mobile attacker, Mobile defender, int damage )
		public override bool OnBeforeDamage( Mobile attacker, Mobile defender )
		{
			if ( !Validate( attacker )  )
				return true;

			ClearCurrentAbility( attacker );

			Map map = attacker.Map;

			if ( map == null )
				return true;

			BaseWeapon weapon = attacker.Weapon as BaseWeapon;

			if ( weapon == null )
				return true;

			if ( !CheckMana( attacker, true ) )
				return true;



			ArrayList list = new ArrayList();

			
			foreach ( Mobile m in defender.GetMobilesInRange( 3 ) )
				list.Add( m );

			ArrayList targets = new ArrayList();

			for ( int i = 0; i < list.Count; ++i )
			{
				Mobile m = (Mobile)list[i];

				if ( m != defender && m != attacker && attacker.ShouldHarm(m) )
				{
					if ( m == null || m.Deleted || m.Map != attacker.Map || !m.Alive || !defender.CanSee( m ) || !attacker.CanBeHarmful( m ) )
						continue;

					if ( !attacker.InRange( m, weapon.MaxRange ) )
						continue;

					if ( attacker.InLOS( m ) )
						targets.Add( m );
				}
			}
			
			targets.Add( defender );			

			if ( targets.Count > 0 )
			{

				attacker.RevealingAction();

				if(targets.Count==2)attacker.SendMessage("The lightning arrow strikes a target!"); 
				else if (targets.Count>2) attacker.SendMessage("The lightning arrow strikes {0} targets!",targets.Count); 
				
				for ( int i = 0; i < targets.Count; ++i )
				{
					Mobile m = (Mobile)targets[i];
					m.BoltEffect( 0 );
					AOS.Damage(m, attacker, Utility.Random(6)+15, 0, 0, 0, 0, 100 );  //15-20 damage
					
				    m.SendMessage( "You are struck by the lightning arrow" );
					
					m.PlaySound(1471);
				}
			}
			
		return true;
		}
	}
}