/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\_custom\items\leviathan artifacts\WaterGem.cs
Lines of code: 99
***********************************************************/


using System;
using Server;
using Server.Network;
using Server.Targeting;
using Server.Items;
using Server.Mobiles;
using Server.Targets;

namespace Server.Items
{

	public class WaterGem : Item
	{
		[Constructable]
		public WaterGem() : this( 1 )
		{
		}

		[Constructable]
		public WaterGem( int amount ) : base( 3881 )
		{
			Weight = 0.1;
			Name = "water gem";
			Hue = 86;
			Amount = amount;
		}

		public override void OnDoubleClick( Mobile from )
		{
			if ( from.InRange( this.GetWorldLocation(), 2 ) )
			{
				from.SendMessage( "Which item do you wish to charge?" );
				from.Target = new InternalTarget( this );
			}
			else
			{
				from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1019045 ); // I can't reach that.
			}
		}

		private class InternalTarget : Target
		{
			private WaterGem m_WaterGem;

			public InternalTarget( WaterGem powder ) : base( -1, false, TargetFlags.None )
			{
				m_WaterGem = powder;
			}

			protected override void OnTarget( Mobile from, object targeted )
			{
				if ( m_WaterGem.Deleted )
					return;

				if ( !from.InRange( m_WaterGem.GetWorldLocation(), 2 ) )
				{
					from.LocalOverheadMessage( MessageType.Regular, 0x3B2, 1019045 ); // I can't reach that.
				}
				else if ( targeted is OracleOfPoseidon)
				{
					OracleOfPoseidon ToBeCharged = targeted as OracleOfPoseidon; 
					
					if (ToBeCharged.UsesRemaining < 10)
					{
					from.SendMessage( "You charge the item" );
					ToBeCharged.UsesRemaining++;
					m_WaterGem.Delete();
					}
					else
					{
					from.SendMessage( "That item is already fully charged" );
					}
				}
				else if ( targeted is MagicKey)
				{
					MagicKey ToBeCharged = targeted as MagicKey; 
					
					if (ToBeCharged.UsesRemaining < 10)
					{
					from.SendMessage( "You charge the item" );
					ToBeCharged.UsesRemaining++;
					m_WaterGem.Delete();
					}
					else
					{
					from.SendMessage( "That item is already fully charged" );
					}
				}				
				else
				{
					from.SendMessage( "That item cannot be charged with a water gem" );
				}
			}
		}

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

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

			writer.WriteEncodedInt( (int) 0 ); // version
		}

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

			int version = reader.ReadEncodedInt();
		}
	}
}