/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Feb-01-2009 08:18:27pm
Filepath: scripts\_custom\events and scenarios\super bowl\FootBall.cs
Lines of code: 81
***********************************************************/


using System;
using System.Collections;
using Server;
using Server.Items;
using Server.Gumps;
using Server.Mobiles;
using Server.Targeting;
using Server.Network;

namespace Server.Items
{
	public class FootBall : Item
	{
			
	
		[Constructable]
		public FootBall() : base( 2481 )
		{
			Weight=1;
			Name="a football";
		}		
	

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

		public override void OnDoubleClick( Mobile from )
		{
			if(from==null)return;
			if ( !IsChildOf( from ) )return;
			
			from.Target = new InternalTarget(from,this);		
		}
		
		public void Throw(Mobile from,Mobile to)
		{		
			if(from==null || to==null || to.Backpack==null)return;
			
			Effects.SendMovingEffect( from, to,ItemID, 18,1,false,false,0,0 );			
			
			if(Utility.Random(200)<to.Dex) 
			{
				to.SendMessage("{0} Throws you the ball and you catch it!",from.Name);
				from.SendMessage("{0} catches the ball",to.Name);
				to.Backpack.DropItem(this);
			}
			else
			{
				to.SendMessage("{0} Throws you the ball and you fail to catch it!",from.Name);
				from.SendMessage("{0} fails at catching the ball",to.Name);
				this.MoveToWorld(to.Location,to.Map);
			}				
		}
		
		public override bool OnMoveOver( Mobile m )
		{		
			if(m!=null && m is FootballPlayer && m.Backpack!=null)m.Backpack.DropItem(this);
			return true;
		}
		
		
		private class InternalTarget : Target
		{
			private FootBall m_Owner;
			private Mobile m_Thrower;

			public InternalTarget( Mobile thrower,FootBall owner ) : base( 25, false, TargetFlags.None )
			{
				m_Owner = owner;
				m_Thrower=thrower;
				m_Thrower.SendMessage("Select player to throw at");
			}
			

			protected override void OnTarget( Mobile from, object o )
			{
				if(o is Mobile)
				{
					Mobile to = (Mobile)o;
					m_Owner.Throw(from,to);				
				}
				else from.SendMessage("Foul!");
			}

		}
		

		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();			
		}

	}

}


