context: using System;
  using Server.Items;
  using Server.Mobiles;
  using Server.Spells;
  
  namespace Server.Engines.Craft
  {
  	public class DefInscription : CraftSystem
  	{
  		public static void Initialize()
  		{
  			m_CraftSystem = new DefInscription();
  		}
  
  		public override SkillName MainSkill { get { return SkillName.Inscribe; } }
  
  		public override int GumpTitleNumber
  		{
  			get { return 1044009; } // <CENTER>INSCRIPTION MENU</CENTER>
  		}
  
  		private static CraftSystem m_CraftSystem;
  
  		public static CraftSystem CraftSystem
  		{
  			get { return m_CraftSystem; }
  		}
  
  		public override CraftECA ECA { get { return CraftECA.ChanceMinusSixtyToFourtyFive; } }
  
  		public override double DefaultChanceAtMin
  		{
  			get { return 0.0; }
  		}
  
  		private DefInscription()
  			: base( 1, 1, 1.25 )
  		{
  		}
  
  		public override int CanCraft( Mobile from, BaseTool tool, Type typeItem )
  		{
  			if ( tool.Deleted || tool.UsesRemaining < 0 )
  				return 1044038; // You have worn out your tool!
  			else if ( !BaseTool.CheckAccessible( tool, from ) )
  				return 1044263; // The tool must be on your person to use.
  
  			if ( typeItem != null )
  			{
  				object o = Activator.CreateInstance( typeItem );
  
  				if ( o is SpellScroll )
  				{
  					SpellScroll scroll = (SpellScroll) o;
  					Spellbook book = Spellbook.Find( from, scroll.SpellID );
  
  					bool hasSpell = ( book != null && book.HasSpell( scroll.SpellID ) );
  
  					scroll.Delete();
  
  					return ( hasSpell ? 0 : 1044253 ); // null : You don't have the components needed to make that.
  				}
  				else if ( o is Item )
  				{
  					( (Item) o ).Delete();
  				}
  			}
  
  			return 0;
  		}
  
  		public override void PlayCraftEffect( Mobile from )
  		{
  			from.PlaySound( 0x249 );
  		}
  
  		private static Type typeofSpellScroll = typeof( SpellScroll );
  
  		public override int PlayEndingEffect( Mobile from, bool failed, bool lostMaterial, bool toolBroken, bool exceptional, bool makersMark, CraftItem item )
  		{
  			if ( toolBroken )
  				from.SendLocalizedMessage( 1044038 ); // You have worn out your tool
  
  			if ( !typeofSpellScroll.IsAssignableFrom( item.ItemType ) ) //  not a scroll
  			{
  				if ( failed )
  				{
  					if ( lostMaterial )
  						return 1044043; // You failed to create the item, and some of your materials are lost.
  					else
  						return 1044157; // You failed to create the item, but no materials were lost.
  				}
  				else
  				{
  					if ( makersMark && exceptional )
  						return 1044156; // You create an exceptional quality item and affix your maker's mark.
  					else if ( exceptional )
  						return 1044155; // You create an exceptional quality item.
  					else
  						return 1044154; // You create the item.
  				}
  			}
  			else
  			{
  				if ( failed )
  					return 501630; // You fail to inscribe the scroll, and the scroll is ruined.
  				else
  					return 501629; // You inscribe the spell and put the scroll in your backpack.
  			}
  		}
  
  		private int m_Circle, m_Mana;
  
  		private enum Reg
  		{
  			BlackPearl,
  			Bloodmoss,
  			Garlic,
  			Ginseng,
  			MandrakeRoot,
  			Nightshade,
  			SulfurousAsh,
  			SpidersSilk
  		}
  
  		private Type[] m_RegTypes = new Type[]
  			{
  				typeof( BlackPearl ),	typeof( Bloodmoss ),
  				typeof( Garlic ),		typeof( Ginseng ),
  				typeof( MandrakeRoot ),	typeof( Nightshade ),
  				typeof( SulfurousAsh ), typeof( SpidersSilk )
  			};
  
  		private void AddSpell( int index, Type type, params Reg[] regs )
  		{
  			double minSkill, maxSkill;
  			int groupCliloc;
  
  			switch ( m_Circle )
  			{
  				default:
  				case 0:
  					minSkill = -25.0;
  					maxSkill = 25.0;
  					groupCliloc = 1111691;
  					break;
  				case 1:
  					minSkill = -10.8;
  					maxSkill = 39.2;
  					groupCliloc = 1111691;
  					break;
  				case 2:
  					minSkill = 03.5;
  					maxSkill = 53.5;
  					groupCliloc = 1111692;
  					break;
  				case 3:
  					minSkill = 17.8;
  					maxSkill = 67.8;
  					groupCliloc = 1111692;
  					break;
  				case 4:
  					minSkill = 32.1;
  					maxSkill = 82.1;
  					groupCliloc = 1111693;
  					break;
  				case 5:
  					minSkill = 46.4;
  					maxSkill = 96.4;
  					groupCliloc = 1111693;
  					break;
  				case 6:
  					minSkill = 60.7;
  					maxSkill = 110.7;
  					groupCliloc = 1111694;
  					break;
  				case 7:
  					minSkill = 75.0;
  					maxSkill = 125.0;
  					groupCliloc = 1111694;
  					break;
  			}
  
  			CraftItem craft = AddCraft( index, type, groupCliloc, 1044380 + index, minSkill, maxSkill, m_RegTypes[(int) regs[0]], 1044353 + (int) regs[0], 1, 1044361 + (int) regs[0] );
  
  			for ( int i = 1; i < regs.Length; ++i )
  				craft.AddRes( m_RegTypes[(int) regs[i]], 1044353 + (int) regs[i], 1, 1044361 + (int) regs[i] );
  
  			craft.AddRes( typeof( BlankScroll ), 1044377, 1, 1044378 );
  			craft.Mana = m_Mana;
  		}
  
  		private void AddNecroSpell( int index, int spell, int mana, double minSkill, Type type, params Type[] regs )
  		{
  			CraftItem craft = AddCraft( index, type, 1061677, 1060509 + spell, minSkill, minSkill + 1.0, regs[0], CraftItem.LabelNumber( regs[0] ), 1, 501627 );
  
  			for ( int i = 1; i < regs.Length; ++i )
  				craft.AddRes( regs[i], CraftItem.LabelNumber( regs[i] ), 1, 501627 );
  
  			craft.AddRes( typeof( BlankScroll ), 1044377, 1, 1044378 );
  			craft.Mana = mana;
  		}
  
  		private void AddMysticismSpell( int index, int spell, int mana, double minSkill, double maxSkill, Type type, params Type[] regs )
  		{
  			CraftItem craft = AddCraft( index, type, 1111671, 1031678 + spell, minSkill, maxSkill, regs[0], CraftItem.LabelNumber( regs[0] ), 1, 501627 );
  
  			for ( int i = 1; i < regs.Length; ++i )
  				craft.AddRes( regs[i], CraftItem.LabelNumber( regs[i] ), 1, 501627 );
  
  			craft.AddRes( typeof( BlankScroll ), 1044377, 1, 1044378 );
  			craft.Mana = mana;
  		}
  
  		public override void InitCraftList()
  		{
  			CraftItem craft = null;
  
  			#region First - Second Circle
  			m_Circle = 0;
  			m_Mana = 4;
  
  			AddSpell( 1, typeof( ReactiveArmorScroll ), Reg.Garlic, Reg.SpidersSilk, Reg.SulfurousAsh );
  			AddSpell( 2, typeof( ClumsyScroll ), Reg.Bloodmoss, Reg.Nightshade );
  			AddSpell( 3, typeof( CreateFoodScroll ), Reg.Garlic, Reg.Ginseng, Reg.MandrakeRoot );
  			AddSpell( 4, typeof( FeeblemindScroll ), Reg.Nightshade, Reg.Ginseng );
  			AddSpell( 5, typeof( HealScroll ), Reg.Garlic, Reg.Ginseng, Reg.SpidersSilk );
  			AddSpell( 6, typeof( MagicArrowScroll ), Reg.SulfurousAsh );
  			AddSpell( 7, typeof( NightSightScroll ), Reg.SpidersSilk, Reg.SulfurousAsh );
  			AddSpell( 8, typeof( WeakenScroll ), Reg.Garlic, Reg.Nightshade );
  
  			m_Circle = 1;
  			m_Mana = 6;
  
  			AddSpell( 9, typeof( AgilityScroll ), Reg.Bloodmoss, Reg.MandrakeRoot );
  			AddSpell( 10, typeof( CunningScroll ), Reg.Nightshade, Reg.MandrakeRoot );
  			AddSpell( 11, typeof( CureScroll ), Reg.Garlic, Reg.Ginseng );
  			AddSpell( 12, typeof( HarmScroll ), Reg.Nightshade, Reg.SpidersSilk );
  			AddSpell( 13, typeof( MagicTrapScroll ), Reg.Garlic, Reg.SpidersSilk, Reg.SulfurousAsh );
  			AddSpell( 14, typeof( MagicUnTrapScroll ), Reg.Bloodmoss, Reg.SulfurousAsh );
  			AddSpell( 15, typeof( ProtectionScroll ), Reg.Garlic, Reg.Ginseng, Reg.SulfurousAsh );
  			AddSpell( 16, typeof( StrengthScroll ), Reg.Nightshade, Reg.MandrakeRoot );
  			#endregion
  
  			#region Third - Fourth Circle
  			m_Circle = 2;
  			m_Mana = 9;
  
  			AddSpell( 17, typeof( BlessScroll ), Reg.Garlic, Reg.MandrakeRoot );
  
gt: 			AddSpell( 18, typeof( FireballScroll ), Reg.BlackPearl );