context: using System;
  using System.Collections;
  using System.Collections.Generic;
  using Server.Multis;
  using Server.Mobiles;
  using Server.Network;
  using Server.ContextMenus;
  using Server.Spells;
  using Server.Targeting;
  using Server.Misc;
  
  namespace Server.Items
  {
  	public class RelRune : Item
  	{
  		[Constructable]
  		public RelRune() : base( 0x1F14 )
  		{
  			Weight = 0.2;  // ?
  			Name = "Rel Rune";
  			Hue = 999;
  		}
  
  		public override void OnDoubleClick( Mobile from ) 
  		{
  			double minSkill = 70.0;
  		 
  			PlayerMobile pm = from as PlayerMobile;
  		
  			if ( !IsChildOf( from.Backpack ) )
  			{
  				from.SendLocalizedMessage( 1042001 ); // That must be in your pack for you to use it.
  			}
  
  			else if ( pm == null || from.Skills[SkillName.Inscribe].Base < 70.0 )
  			{
  				from.SendMessage( "You are not skilled enough to attempt this enhancement." );
  			}
  
  		        else if( from.InRange( this.GetWorldLocation(), 1 ) ) 
  		        {
  				double maxSkill = minSkill + 40.0;
  
  				if ( !from.CheckSkill( SkillName.Inscribe, minSkill, maxSkill ) )
  				{
  					from.SendMessage( "The rune shatters, releasing the magic energy." );
  					from.PlaySound( 65 );
  					from.PlaySound( 0x1F8 );
  					Delete();
  					return;
  				}
  				else
  				{
  					from.SendMessage( "Select the item to enhance." );
  					from.Target = new InternalTarget( this );
  				}
  		        } 
  
  		        else 
  		        { 
  		        	from.SendLocalizedMessage( 500446 ); // That is too far away. 
  		        } 
  		} 
  		
  		private class InternalTarget : Target 
  		{
  			private RelRune m_RelRune;
  
  			public InternalTarget( RelRune runeaug ) : base( 1, false, TargetFlags.None )
  			{
  				m_RelRune = runeaug;
  			}
  
  		 	protected override void OnTarget( Mobile from, object targeted ) 
  		 	{ 
  				int scalar;
  				double mageSkill = from.Skills[SkillName.Inscribe].Value;
  
  				if ( mageSkill >= 100.0 )
  					scalar = 3;
  				else if ( mageSkill >= 90.0 )
  					scalar = 2;
  				else
  					scalar = 1;
  
  			    	if ( targeted is BaseWeapon ) 
  				{ 
  			       		BaseWeapon Weapon = targeted as BaseWeapon; 
  
  					if ( !from.InRange( ((Item)targeted).GetWorldLocation(), 1 ) ) 
  					{ 
  			          		from.SendLocalizedMessage( 500446 ); // That is too far away. 
  		       			}
  
  					else if (( ((Item)targeted).Parent != null ) && ( ((Item)targeted).Parent is Mobile ) ) 
  			       		{ 
  			          		from.SendMessage( "You cannot enhance that in it's current location." ); 
  		       			}
  
  					else
  		       			{
  						int DestroyChance = Utility.Random( 5 );
  
  						if ( DestroyChance > 0 ) // Success
  						{
  							int augment = ( ( Utility.Random( 3 ) ) * scalar ) + 1;
  
  							Weapon.WeaponAttributes.SelfRepair += augment; from.SendMessage( "The Rel Rune enhances your weapon." );
  
  				                  	from.PlaySound( 0x1F5 );
  			        	          	m_RelRune.Delete();
  			          		}
  
  						else // Fail
  						{
  					  		from.SendMessage( "You have failed to enhance the weapon!" );
  							from.SendMessage( "The weapon is damaged beyond repair!" );
  							from.PlaySound( 42 );
  						  	Weapon.Delete();
  							m_RelRune.Delete();
  				  		}
  					}
  				}
  
  			    	else if ( targeted is BaseArmor ) 
  				{ 
  			       		BaseArmor Armor = targeted as BaseArmor; 
  
  					if ( !from.InRange( ((Item)targeted).GetWorldLocation(), 1 ) ) 
  					{ 
  			          		from.SendLocalizedMessage( 500446 ); // That is too far away. 
  		       			}
  
  					else if (( ((Item)targeted).Parent != null ) && ( ((Item)targeted).Parent is Mobile ) ) 
  			       		{ 
  			          		from.SendMessage( "You cannot enhance that in it's current location." ); 
  		       			}
  
  		       			else
  		       			{
  						int DestroyChance = Utility.Random( 5 );
  		               	  
  						if ( DestroyChance > 0 ) // Success
  						{
  							int augment = ( ( Utility.Random( 3 ) ) * scalar ) + 1;
  							int augmentper = ( ( Utility.Random( 5 ) ) * scalar ) + 5;
  
  							Armor.ArmorAttributes.SelfRepair += augment; from.SendMessage( "The Rel Rune enhances your armor." );
  
  				                  	from.PlaySound( 0x1F5 );
  			        	          	m_RelRune.Delete();
  			          		}
  
  						else // Fail
  						{
  					  		from.SendMessage( "You have failed to enhance the armor!" );
  							from.SendMessage( "The armor is damaged beyond repair!" );
  							from.PlaySound( 42 );
  							Armor.Delete();
  							m_RelRune.Delete();
  				  		}
  					}
  				}
  
  			    	else if ( targeted is BaseShield ) 
  				{ 
  			       		BaseShield Shield = targeted as BaseShield; 
  
  					if ( !from.InRange( ((Item)targeted).GetWorldLocation(), 1 ) ) 
  					{ 
  			          		from.SendLocalizedMessage( 500446 ); // That is too far away. 
  		       			}
  
  					else if (( ((Item)targeted).Parent != null ) && ( ((Item)targeted).Parent is Mobile ) ) 
  			       		{ 
  			          		from.SendMessage( "You cannot enhance that in it's current location." ); 
  		       			}
  
  					else
  		       			{
  						int DestroyChance = Utility.Random( 5 );
  		               	  
  						if ( DestroyChance > 0 ) // Success
  						{
  							int augment = ( ( Utility.Random( 3 ) ) * scalar ) + 1;
  							int augmentper = ( ( Utility.Random( 5 ) ) * scalar ) + 5;
  
  								Shield.ArmorAttributes.SelfRepair += augment; from.SendMessage( "The Rel Rune enhances your shield." );
  
  				                  	from.PlaySound( 0x1F5 );
  			        	          	m_RelRune.Delete();
  			          		}
  
  						else // Fail
  						{
  					  		from.SendMessage( "You have failed to enhance the shield!" );
  							from.SendMessage( "The shield is damaged beyond repair!" );
  							from.PlaySound( 42 );
  						  	Shield.Delete();
  							m_RelRune.Delete();
  				  		}
  					}
  				}
  
  		    		else 
  		    		{ 
  
gt: 		       			from.SendMessage( "You cannot enhance that." );