/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Jan-02-2010 02:31:59pm
Filepath: scripts\Mobiles\Animals\Mounts\Ethereals.cs
Lines of code: 708
***********************************************************/


using System;
using Server.Mobiles;
using Server.Items;
using Server.Spells;
using Server.Engines.VeteranRewards;

namespace Server.Mobiles
{
	public class EtherealMount : Item, IMount, IMountItem, Engines.VeteranRewards.IRewardItem
	{
		private int m_MountedID;
		private int m_RegularID;
		private Mobile m_Rider;
		private bool m_IsRewardItem;
		private bool m_IsDonationItem;

		[CommandProperty( AccessLevel.GameMaster )]
		public bool IsRewardItem
		{
			get{ return m_IsRewardItem; }
			set{ m_IsRewardItem = value;Modify(); }
		}
		
		public override string DefaultName
		{
			get { return "Ethereal Mount"; }
		}		

		public override double DefaultWeight
		{
			get { return 1.0; }
		}
		
		public virtual bool CanRideOnWater{ get { return false; }}		

		[CommandProperty( AccessLevel.GameMaster, AccessLevel.Administrator )]
		public bool IsDonationItem
		{
			get { return m_IsDonationItem; }
			set { m_IsDonationItem = value; InvalidateProperties(); Modify();}
		}

		[Constructable]
		public EtherealMount( int itemID, int mountID ) : base( itemID )
		{
			m_MountedID = mountID;
			m_RegularID = itemID;
			m_Rider = null;

			Layer = Layer.Invalid;

			LootType = LootType.Blessed;
		}

		public override void GetProperties( ObjectPropertyList list )
		{
			base.GetProperties( list );

			
			
			if( m_IsDonationItem )
			{
			list.Add(1060658,"Donation Ethereal \t{0}","7.5 sec slower cast time if not a 9mo. Veteran");
			
		//		list.Add( "Donation Ethereal" );
		//		list.Add( "7.5 sec slower cast time if not a 9mo. Veteran" );
			}
		}
		
		[CommandProperty( AccessLevel.GameMaster )]
		public int MountedID
		{
			get
			{
				return m_MountedID;
			}
			set
			{
				if ( m_MountedID != value )
				{
					m_MountedID = value;

					if ( m_Rider != null )
						ItemID = value;
					Modify();
				}
			}
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public int RegularID
		{
			get
			{
				return m_RegularID;
			}
			set
			{
				if ( m_RegularID != value )
				{
					m_RegularID = value;

					if ( m_Rider == null )
						ItemID = value;
					Modify();
				}
			}
		}

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

		public override bool DisplayLootType{ get{ return false; } }

		public virtual int FollowerSlots{ get{ return 1; } }

		public void RemoveFollowers()
		{
			if ( m_Rider != null )
				m_Rider.Followers -= FollowerSlots;

			if ( m_Rider != null && m_Rider.Followers < 0 )
				m_Rider.Followers = 0;
		}

		public void AddFollowers()
		{
			if ( m_Rider != null )
				m_Rider.Followers += FollowerSlots;
		}

		public virtual bool Validate( Mobile from )
		{
			if ( !IsChildOf( from.Backpack ) )
			{
				from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
				return false;
			}
			else if ( m_IsRewardItem && !Engines.VeteranRewards.RewardSystem.CheckIsUsableBy( from, this, null ) )
			{
				// CheckIsUsableBy sends the message
				return false;
			}
			else if ( !BaseMount.CheckMountAllowed( from, true ) )
			{
				// CheckMountAllowed sends the message
				return false;
			}
			else if ( from.Mounted )
			{
				from.SendLocalizedMessage( 1005583 ); // Please dismount first.
				return false;
			}
			else if ( from.IsBodyMod && !from.Body.IsHuman )
			{
				from.SendLocalizedMessage( 1061628 ); // You can't do that while polymorphed.
				return false;
			}
			else if ( from.HasTrade )
			{
				from.SendLocalizedMessage( 1042317, "", 0x41 ); // You may not ride at this time
				return false;
			}
			else if ( (from.Followers + FollowerSlots) > from.FollowersMax )
			{
				from.SendLocalizedMessage( 1049679 ); // You have too many followers to summon your mount.
				return false;
			}
			else if ( !Multis.DesignContext.Check( from ) )
			{
				// Check sends the message
				return false;
			}
			else if(from.Region !=null && !from.Region.OnMount(from))
			{
				from.SendMessage("You cannot mount here");
				return false;
			}

			return true;
		}

		public override void OnDoubleClick( Mobile from )
		{
			if ( Validate( from ) )
				new EtherealSpell( this, from ).Cast();
		}

		public override void Serialize( GenericWriter writer )
		{
			base.Serialize( writer );

			writer.Write( (int) 3 ); // version

			writer.Write( m_IsDonationItem );
			writer.Write( (bool) m_IsRewardItem );

			writer.Write( (int)m_MountedID );
			writer.Write( (int)m_RegularID );
			writer.Write( m_Rider );
		}

		public override void Deserialize( GenericReader reader )
		{
			base.Deserialize( reader );
			LootType = LootType.Blessed;

			int version = reader.ReadInt();

			switch ( version )
			{
				case 3:
				{
					m_IsDonationItem = reader.ReadBool();
					goto case 2;
				}
				case 2:
				{
					m_IsRewardItem = reader.ReadBool();
					goto case 0;
				}
				case 1: reader.ReadInt(); goto case 0;
				case 0:
				{
					m_MountedID = reader.ReadInt();
					m_RegularID = reader.ReadInt();
					m_Rider = reader.ReadMobile();

					if ( m_MountedID == 0x3EA2 )
						m_MountedID = 0x3EAA;

					break;
				}
			}

			AddFollowers();

			if ( version < 3 && Weight == 0 )
				Weight = -1;
		}

		public override DeathMoveResult OnParentDeath( Mobile parent )
		{
			Rider = null;//get off, move to pack

			return DeathMoveResult.RemainEquiped;
		}

		public static void Dismount( Mobile m )
		{
			IMount mount = m.Mount;

			if ( mount != null )
				mount.Rider = null;
		}

		[CommandProperty( AccessLevel.GameMaster )]
		public Mobile Rider
		{
			get
			{
				return m_Rider;
			}
			set
			{
				if ( value != m_Rider )
				{
					if ( value == null )
					{
						Internalize();
						UnmountMe();

						RemoveFollowers();
						m_Rider = value;
					}
					else
					{
						if ( m_Rider != null )
							Dismount( m_Rider );

						Dismount( value );

						RemoveFollowers();
						m_Rider = value;
						AddFollowers();

						MountMe();
					}
				}
			}
		}

		public void UnmountMe()
		{
			Container bp = m_Rider.Backpack;

			ItemID = m_RegularID;
			Layer = Layer.Invalid;
			Movable = true;

			if ( Hue == 0x4001 )
				Hue = 0;

			if ( bp != null )
			{
				bp.DropItem( this );
			}
			else
			{
				Point3D loc = m_Rider.Location;
				Map map = m_Rider.Map;

				if ( map == null || map == Map.Internal )
				{
					loc = m_Rider.LogoutLocation;
					map = m_Rider.LogoutMap;
				}

				MoveToWorld( loc, map );
			}
		}

		public void MountMe()
		{
			ItemID = m_MountedID;
			Layer = Layer.Mount;
			Movable = false;

			if ( Hue == 0 )
				Hue = 0x4001;

			ProcessDelta();
			m_Rider.ProcessDelta();
			m_Rider.EquipItem( this );
			m_Rider.ProcessDelta();
			ProcessDelta();
		}

		public IMount Mount
		{
			get
			{
				return this;
			}
		}

		public static void StopMounting( Mobile mob )
		{
			if ( mob.Spell is EtherealSpell )
				((EtherealSpell)mob.Spell).Stop();
		}

		public void OnRiderDamaged( int amount, Mobile from, bool willKill )
		{
		}

		private class EtherealSpell : Spell
		{
			private static SpellInfo m_Info = new SpellInfo( "Ethereal Mount", "", SpellCircle.Second, 230 );

			private EtherealMount m_Mount;
			private Mobile m_Rider;

			public EtherealSpell( EtherealMount mount, Mobile rider ) : base( rider, null, m_Info )
			{
				m_Rider = rider;
				m_Mount = mount;
			}

			public override bool ClearHandsOnCast{ get{ return false; } }
			public override bool RevealOnCast{ get{ return false; } }

			public override TimeSpan GetCastRecovery()
			{
				return TimeSpan.Zero;
			}

			public override TimeSpan GetCastDelay()
			{
				return TimeSpan.FromSeconds( ( (m_Mount.IsDonationItem && RewardSystem.GetRewardLevel( m_Rider ) < 3 )? 12.5 : 5.0 ) );
			}

			public override int GetMana()
			{
				return 0;
			}

			public override bool ConsumeReagents()
			{
				return true;
			}

			public override bool CheckFizzle()
			{
				return true;
			}

			private bool m_Stop;

			public void Stop()
			{
				m_Stop = true;
				Disturb( DisturbType.Hurt, false, false );
			}

			public override bool CheckDisturb( DisturbType type, bool checkFirst, bool resistable )
			{
				if ( type == DisturbType.EquipRequest || type == DisturbType.UseRequest/* || type == DisturbType.Hurt*/ )
					return false;

				return true;
			}

			public override void DoHurtFizzle()
			{
				if ( !m_Stop )
					base.DoHurtFizzle();
			}

			public override void DoFizzle()
			{
				if ( !m_Stop )
					base.DoFizzle();
			}

			public override void OnDisturb( DisturbType type, bool message )
			{
				if ( message && !m_Stop )
					Caster.SendLocalizedMessage( 1049455 ); // You have been disrupted while attempting to summon your ethereal mount!

				//m_Mount.UnmountMe();
			}

			public override void OnCast()
			{
				if ( !m_Mount.Deleted && m_Mount.Rider == null && m_Mount.Validate( m_Rider ) )
					m_Mount.Rider = m_Rider;

				FinishSequence();
			}
		}
	}

	public class EtherealHorse : EtherealMount
	{
		public override int LabelNumber{ get{ return 1041298; } } // Ethereal Horse Statuette

		[Constructable]
		public EtherealHorse() : base( 0x20DD, 0x3EAA )
		{
		}

		public EtherealHorse( 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 class EtherealLlama : EtherealMount
	{
		public override int LabelNumber{ get{ return 1041300; } } // Ethereal Llama Statuette

		[Constructable]
		public EtherealLlama() : base( 0x20F6, 0x3EAB )
		{
		}

		public EtherealLlama( 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 class EtherealOstard : EtherealMount
	{
		public override int LabelNumber{ get{ return 1041299; } } // Ethereal Ostard Statuette

		[Constructable]
		public EtherealOstard() : base( 0x2135, 0x3EAC )
		{
		}

		public EtherealOstard( 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 class EtherealRidgeback : EtherealMount
	{
		public override int LabelNumber{ get{ return 1049747; } } // Ethereal Ridgeback Statuette

		[Constructable]
		public EtherealRidgeback() : base( 0x2615, 0x3E9A )
		{
		}

		public EtherealRidgeback( 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 class EtherealUnicorn : EtherealMount
	{
		public override int LabelNumber{ get{ return 1049745; } } // Ethereal Unicorn Statuette

		[Constructable]
		public EtherealUnicorn() : base( 0x25CE, 0x3E9B )
		{
		}

		public EtherealUnicorn( 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 class EtherealBeetle : EtherealMount
	{
		public override int LabelNumber{ get{ return 1049748; } } // Ethereal Beetle Statuette

		[Constructable]
		public EtherealBeetle() : base( 0x260F, 0x3E97 )
		{
		}

		public EtherealBeetle( 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 class EtherealKirin : EtherealMount
	{
		public override int LabelNumber{ get{ return 1049746; } } // Ethereal Ki-Rin Statuette

		[Constructable]
		public EtherealKirin() : base( 0x25A0, 0x3E9C )
		{
		}

		public EtherealKirin( 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();

			if ( Name == "an ethereal kirin" )
				Name = null;
		}
	}

	//start ethy
	public class EtherealSwampDragon : EtherealMount
	{
		public override int LabelNumber{ get{ return 1049749; } } // Ethereal Swamp Dragon Statuette

		[Constructable]
		public EtherealSwampDragon() : base( 0x2619, 0x3E98 )
		{
		}

		public EtherealSwampDragon( 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();

		}
	}
	//end ethy
	
	
	
	//start ethy
	public class EtherealCharger : EtherealMount
	{
		public override string DefaultName{ get{ return "Ethereal Charger of the Fallen Statuette"; } }

		[Constructable]
		public EtherealCharger() : base( 11676, 16018 ) //item id, mounted id
		{
		}

		public EtherealCharger( 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();
     	}
	}
	//end ethy	
	
	
	//start ethy
	public class EtherealCusidhe : EtherealMount
	{
		public override string DefaultName{ get{ return "Ethereal Cu Sidhe Statuette"; } }

		[Constructable]
		public EtherealCusidhe() : base( 11670, 16017 ) //item id, mounted id
		{
		}

		public EtherealCusidhe( 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();
     	}
	}
	//end ethy		

	
	//start ethy
	public class EtherealHiryu : EtherealMount
	{
		public override string DefaultName{ get{ return "Ethereal Hiryu Statuette"; } }

		[Constructable]
		public EtherealHiryu() : base( 10090, 16020 ) //item id, mounted id
		{
		}

		public EtherealHiryu( 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();
     	}
	}
	//end ethy	
	
	
	//start ethy
	public class EtherealHellsteed : EtherealMount
	{
		public override string DefaultName{ get{ return "Ethereal Hell Steed Statuette"; } }

		[Constructable]
		public EtherealHellsteed() : base( 9751, 16059 ) //item id, mounted id
		{
		}

		public EtherealHellsteed( 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();
     	}
	}
	//end ethy		
	

	//start ethy
	public class EtherealZostrich : EtherealMount
	{
		public override string DefaultName{ get{ return "Ethereal Zostrich Statuette"; } }

		[Constructable]
		public EtherealZostrich() : base( 8502, 16036 ) //item id, mounted id
		{
		}

		public EtherealZostrich( 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();
     	}
	}
	//end ethy		
	
	//start ethy
	public class EtherealReptalon : EtherealMount
	{
		public override string DefaultName{ get{ return "Ethereal Reptalon Statuette"; } }

		[Constructable]
		public EtherealReptalon() : base(11669, 16016 ) //item id, mounted id
		{
		}

		public EtherealReptalon( 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();
     	}
	}
	//end ethy		
	
	
	//start ethy
	public class EtherealSeahorse : EtherealMount
	{
		public override string DefaultName{ get{ return "Ethereal Sea Horse Statuette"; } }

		[Constructable]
		public EtherealSeahorse() : base(9658,16051 ) //item id, mounted id
		{
		}
		
		public override bool CanRideOnWater{ get { return true; }}
		
		public override bool Validate( Mobile from )
		{
			if(from.Region.IsPartOf("Doom") || from.Region.IsPartOf(typeof(Regions.HouseRegion)))
			{
			from.SendMessage("You cannot mount a seahorse here!");			
			return false;
			}

		return base.Validate(from);
		}		

		public EtherealSeahorse( 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();
     	}
	}
	//end ethy		
	
	
	//start ethy
	public class EtherealPolarBear : EtherealMount
	{
		public override string DefaultName{ get{ return "Ethereal Polar Bear Statuette"; } }

		[Constructable]
		public EtherealPolarBear() : base(0x20E1, 0x3EC5  ) //item id, mounted id
		{
		}

		public EtherealPolarBear( 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();
     	}
	}
	//end ethy		
	
	
	
	
}