Go Back   RunUO - Ultima Online Emulation > RunUO > Script Support

Script Support Get support for modifying RunUO Scripts, or writing your own!

Reply
 
Thread Tools Display Modes
Old 10-18-2005, 12:45 AM   #1 (permalink)
 
Join Date: Aug 2004
Age: 30
Posts: 546
Default prompting a user to change items name...

This was a problem i had before, but i started a new thread as i've localized the problem, and actuly done the coding, however i'm at a wall, and down to 2 errors. This scripts intended function is to prompt a player to enter a name for an item if the quality would give it a makers mark.

My errors are:

Scripts: Compiling C# scripts...failed (2 errors, 0 warnings)
- Error: Scripts\custom\test hammer\CraftItem.cs: CS1513: (line 1440, column 7)
} expected
- Error: Scripts\custom\test hammer\CraftItem.cs: CS1022: (line 1467, column 2)
Type or namespace definition, or end-of-file expected
Scripts: One or more scripts failed to compile or no script files were found.

I wish just adding } would do it, but its not, thats why i'm stuck. Thx.

Code:
using System;
using Server.Items;

namespace Server.Engines.Craft
{
	public enum ConsumeType
	{
		All, Half, None
	}

	public class CraftItem
	{
		private CraftResCol m_arCraftRes;
		private CraftSkillCol m_arCraftSkill;
		private Type m_Type;

		private string m_GroupNameString;
		private int m_GroupNameNumber;

		private string m_NameString;
		private int m_NameNumber;
		
		private int m_Mana;
		private int m_Hits;
		private int m_Stam;

		private bool m_UseAllRes;

		private bool m_NeedHeat;
		private bool m_NeedOven;

		private bool m_UseSubRes2;

		public CraftItem( Type type, string groupName, string name )
		{
			m_arCraftRes = new CraftResCol();
			m_arCraftSkill = new CraftSkillCol();

			m_Type = type;
			m_GroupNameString = groupName;
			m_NameString = name;
		}

		public CraftItem( Type type, int groupName, int name )
		{
			m_arCraftRes = new CraftResCol();
			m_arCraftSkill = new CraftSkillCol();

			m_Type = type;
			m_GroupNameNumber = groupName;
			m_NameNumber = name;
		}

		public CraftItem( Type type, int groupName, string name )
		{
			m_arCraftRes = new CraftResCol();
			m_arCraftSkill = new CraftSkillCol();

			m_Type = type;
			m_GroupNameNumber = groupName;
			m_NameString = name;
		}

		public void AddRes( Type type, int name, int amount )
		{
			AddRes( type, name, amount, "" );
		}

		public void AddRes( Type type, int name, int amount, int localizedMessage )
		{
			CraftRes craftRes = new CraftRes( type, name, amount, localizedMessage );
			m_arCraftRes.Add( craftRes );
		}

		public void AddRes( Type type, int name, int amount, string strMessage )
		{
			CraftRes craftRes = new CraftRes( type, name, amount, strMessage );
			m_arCraftRes.Add( craftRes );
		}

		public void AddRes( Type type, string name, int amount )
		{
			AddRes( type, name, amount, "" );
		}

		public void AddRes( Type type, string name, int amount, int localizedMessage )
		{
			CraftRes craftRes = new CraftRes( type, name, amount, localizedMessage );
			m_arCraftRes.Add( craftRes );
		}

		public void AddRes( Type type, string name, int amount, string strMessage )
		{
			CraftRes craftRes = new CraftRes( type, name, amount, strMessage );
			m_arCraftRes.Add( craftRes );
		}

		public void AddSkill( SkillName skillToMake, double minSkill, double maxSkill )
		{
			CraftSkill craftSkill = new CraftSkill( skillToMake, minSkill, maxSkill );
			m_arCraftSkill.Add( craftSkill );
		}

		public int Mana
		{
			get { return m_Mana; }
			set { m_Mana = value; }
		}

		public int Hits
		{
			get { return m_Hits; }
			set { m_Hits = value; }
		}

		public int Stam
		{
			get { return m_Stam; }
			set { m_Stam = value; }
		}

		public bool UseSubRes2
		{
			get { return m_UseSubRes2; }
			set { m_UseSubRes2 = value; }
		}

		public bool UseAllRes
		{
			get { return m_UseAllRes; }
			set { m_UseAllRes = value; }
		}

		public bool NeedHeat
		{
			get { return m_NeedHeat; }
			set { m_NeedHeat = value; }
		}

		public bool NeedOven
		{
			get { return m_NeedOven; }
			set { m_NeedOven = value; }
		}
		
		public Type ItemType
		{
			get { return m_Type; }
		}

		public string GroupNameString
		{
			get { return m_GroupNameString; }
		}

		public int GroupNameNumber
		{
			get { return m_GroupNameNumber; }
		}

		public string NameString
		{
			get { return m_NameString; }
		}

		public int NameNumber
		{
			get { return m_NameNumber; }
		}

		public CraftResCol Ressources
		{
			get { return m_arCraftRes; }
		}

		public CraftSkillCol Skills
		{
			get { return m_arCraftSkill; }
		}

		public bool ConsumeAttributes( Mobile from, ref object message, bool consume )
		{
			bool consumMana = false;
			bool consumHits = false;
			bool consumStam = false;

			if ( Hits > 0 && from.Hits < Hits )
			{
				message = "You lack the required hit points to make that.";
				return false;
			}
			else
			{
				consumHits = consume;
			}

			if ( Mana > 0 && from.Mana < Mana )
			{
				message = "You lack the required mana to make that.";
				return false;
			}
			else
			{
				consumMana = consume;
			}

			if ( Stam > 0 && from.Stam < Stam )
			{
				message = "You lack the required stamina to make that.";
				return false;
			}
			else
			{
				consumStam = consume;
			}

			if ( consumMana )
				from.Mana -= Mana;

			if ( consumHits )
				from.Hits -= Hits;

			if ( consumStam )
				from.Stam -= Stam;

			return true;
		}

		private static Type[][] m_TypesTable = new Type[][]
			{
				new Type[]{ typeof( Log ), typeof( Board ) },
				new Type[]{ typeof( Leather ), typeof( Hides ) },
				new Type[]{ typeof( SpinedLeather ), typeof( SpinedHides ) },
				new Type[]{ typeof( HornedLeather ), typeof( HornedHides ) },
				new Type[]{ typeof( BarbedLeather ), typeof( BarbedHides ) },
				new Type[]{ typeof( BlankMap ), typeof( BlankScroll ) },
				new Type[]{ typeof( Cloth ), typeof( UncutCloth ) },
				new Type[]{ typeof( CheeseWheel ), typeof( CheeseWedge ) }
			};

		private static Type[] m_ColoredItemTable = new Type[]
			{
				typeof( BaseWeapon ), typeof( BaseArmor ), typeof( BaseClothing ),
				typeof( BaseJewel ), typeof( DragonBardingDeed )
			};

		private static Type[] m_ColoredResourceTable = new Type[]
			{
				typeof( BaseIngot ), typeof( BaseOre ),
				typeof( BaseLeather ), typeof( BaseHides ),
				typeof( UncutCloth ), typeof( Cloth ),
				typeof( BaseGranite ), typeof( BaseScales )
			};

		public bool RetainsColorFrom( CraftSystem system, Type type )
		{
			if ( system.RetainsColorFrom( this, type ) )
				return true;

			bool inItemTable = false, inResourceTable = false;

			for ( int i = 0; !inItemTable && i < m_ColoredItemTable.Length; ++i )
				inItemTable = ( m_Type == m_ColoredItemTable[i] || m_Type.IsSubclassOf( m_ColoredItemTable[i] ) );

			for ( int i = 0; inItemTable && !inResourceTable && i < m_ColoredResourceTable.Length; ++i )
				inResourceTable = ( type == m_ColoredResourceTable[i] || type.IsSubclassOf( m_ColoredResourceTable[i] ) );

			return ( inItemTable && inResourceTable );
		}

		private static int[] m_HeatSources = new int[]
			{
				0x461, 0x48E, // Sandstone oven/fireplace
				0x92B, 0x96C, // Stone oven/fireplace
				0xDE3, 0xDE9, // Campfire
				0xFAC, 0xFAC, // Firepit
				0x184A, 0x184C, // Heating stand (left)
				0x184E, 0x1850, // Heating stand (right)
				0x398C, 0x399F  // Fire field
			};

		private static int[] m_Ovens = new int[]
			{
				0x461, 0x46F, // Sandstone oven
				0x92B, 0x93F  // Stone oven
			};

		public bool Find( Mobile from, int[] itemIDs )
		{
			Map map = from.Map;

			if ( map == null )
				return false;

			IPooledEnumerable eable = map.GetItemsInRange( from.Location, 2 );

			foreach ( Item item in eable )
			{
				if ( (item.Z + 16) > from.Z && (from.Z + 16) > item.Z && Find( item.ItemID, itemIDs ) )
				{
					eable.Free();
					return true;
				}
			}

			eable.Free();

			for ( int x = -2; x <= 2; ++x )
			{
				for ( int y = -2; y <= 2; ++y )
				{
					int vx = from.X + x;
					int vy = from.Y + y;

					Tile[] tiles = map.Tiles.GetStaticTiles( vx, vy, true );

					for ( int i = 0; i < tiles.Length; ++i )
					{
						int z = tiles[i].Z;
						int id = tiles[i].ID & 0x3FFF;

						if ( (z + 16) > from.Z && (from.Z + 16) > z && Find( id, itemIDs ) )
							return true;
					}
				}
			}

			return false;
		}

		public bool Find( int itemID, int[] itemIDs )
		{
			bool contains = false;

			for ( int i = 0; !contains && i < itemIDs.Length; i += 2 )
				contains = ( itemID >= itemIDs[i] && itemID <= itemIDs[i + 1] );

			return contains;
		}

		public bool IsQuantityType( Type[][] types )
		{
			for ( int i = 0; i < types.Length; ++i )
			{
				Type[] check = types[i];

				for ( int j = 0; j < check.Length; ++j )
				{
					if ( typeof( IHasQuantity ).IsAssignableFrom( check[j] ) )
						return true;
				}
			}

			return false;
		}

		public int ConsumeQuantity( Container cont, Type[][] types, int[] amounts )
		{
			if ( types.Length != amounts.Length )
				throw new ArgumentException();

			Item[][] items = new Item[types.Length][];
			int[] totals = new int[types.Length];

			for ( int i = 0; i < types.Length; ++i )
			{
				items[i] = cont.FindItemsByType( types[i], true );

				for ( int j = 0; j < items[i].Length; ++j )
				{
					IHasQuantity hq = items[i][j] as IHasQuantity;

					if ( hq == null )
					{
						totals[i] += items[i][j].Amount;
					}
					else
					{
						if ( hq is BaseBeverage && ((BaseBeverage)hq).Content != BeverageType.Water )
							continue;

						totals[i] += hq.Quantity;
					}
				}

				if ( totals[i] < amounts[i] )
					return i;
			}

			for ( int i = 0; i < types.Length; ++i )
			{
				int need = amounts[i];

				for ( int j = 0; j < items[i].Length; ++j )
				{
					Item item = items[i][j];
					IHasQuantity hq = item as IHasQuantity;

					if ( hq == null )
					{
						int theirAmount = item.Amount;

						if ( theirAmount < need )
						{
							item.Delete();
							need -= theirAmount;
						}
						else
						{
							item.Consume( need );
							break;
						}
					}
					else
					{
						if ( hq is BaseBeverage && ((BaseBeverage)hq).Content != BeverageType.Water )
							continue;

						int theirAmount = hq.Quantity;

						if ( theirAmount < need )
						{
							hq.Quantity -= theirAmount;
							need -= theirAmount;
						}
						else
						{
							hq.Quantity -= need;
							break;
						}
					}
				}
			}

			return -1;
		}

		public int GetQuantity( Container cont, Type[] types )
		{
			Item[] items = cont.FindItemsByType( types, true );

			int amount = 0;

			for ( int i = 0; i < items.Length; ++i )
			{
				IHasQuantity hq = items[i] as IHasQuantity;

				if ( hq == null )
				{
					amount += items[i].Amount;
				}
				else
				{
					if ( hq is BaseBeverage && ((BaseBeverage)hq).Content != BeverageType.Water )
						continue;

					amount += hq.Quantity;
				}
			}

			return amount;
		}

		public bool ConsumeRes( Mobile from, Type typeRes, CraftSystem craftSystem, ref int resHue, ref int maxAmount, ConsumeType consumeType, ref object message )
		{
			Container ourPack = from.Backpack;

			if ( ourPack == null )
				return false;

			if ( m_NeedHeat && !Find( from, m_HeatSources ) )
			{
				message = 1044487; // You must be near a fire source to cook.
				return false;
			}

			if ( m_NeedOven && !Find( from, m_Ovens ) )
			{
				message = 1044493; // You must be near an oven to bake that.
				return false;
			}

			Type[][] types = new Type[m_arCraftRes.Count][];
			int[] amounts = new int[m_arCraftRes.Count];

			maxAmount = int.MaxValue;

			CraftSubResCol resCol = ( m_UseSubRes2 ? craftSystem.CraftSubRes2 : craftSystem.CraftSubRes );

			for ( int i = 0; i < types.Length; ++i )
			{
				CraftRes craftRes = m_arCraftRes.GetAt( i );
				Type baseType = craftRes.ItemType;

				// Resource Mutation
				if ( (baseType == resCol.ResType) && ( typeRes != null ) )
				{
					baseType = typeRes;

					CraftSubRes subResource = resCol.SearchFor( baseType );

					if ( subResource != null && from.Skills[craftSystem.MainSkill].Base < subResource.RequiredSkill )
					{
						message = subResource.Message;
						return false;
					}
				}
				// ******************

				for ( int j = 0; types[i] == null && j < m_TypesTable.Length; ++j )
				{
					if ( m_TypesTable[j][0] == baseType )
						types[i] = m_TypesTable[j];
				}

				if ( types[i] == null )
					types[i] = new Type[]{ baseType };

				/*if ( !retainedColor && RetainsColorFrom( craftSystem, baseType ) )
				{
					retainedColor = true;
					Item resItem = ourPack.FindItemByType( types[i] );

					if ( resItem != null )
						resHue = resItem.Hue;
				}*/

				amounts[i] = craftRes.Amount;

				// For stackable items that can ben crafted more than one at a time
				if ( UseAllRes )
				{
					int tempAmount = ourPack.GetAmount( types[i] );
					tempAmount /= amounts[i];
					if ( tempAmount < maxAmount )
					{
						maxAmount = tempAmount;

						if ( maxAmount == 0 )
						{
							CraftRes res = m_arCraftRes.GetAt( i );

							if ( res.MessageNumber > 0 )
								message = res.MessageNumber;
							else if ( res.MessageString != null && res.MessageString != String.Empty )
								message = res.NameString;
							else
								message = 502925; // You don't have the resources required to make that item.

							return false;
						}
					}
				}
				// ****************************
			}

			// We adjust the amount of each resource to consume the max posible
			if ( UseAllRes )
			{
				for ( int i = 0; i < amounts.Length; ++i )
					amounts[i] *= maxAmount;
			}
			else
				maxAmount = -1;

			Item consumeExtra = null;

			if ( m_NameNumber == 1041267 )
			{
				// Runebooks are a special case, they need a blank recall rune

				Item[] runes = ourPack.FindItemsByType( typeof( RecallRune ) );

				for ( int i = 0; i < runes.Length; ++i )
				{
					RecallRune rune = runes[i] as RecallRune;

					if ( rune != null && !rune.Marked )
					{
						consumeExtra = rune;
						break;
					}
				}

				if ( consumeExtra == null )
				{
					message = 1044253; // You don't have the components needed to make that.
					return false;
				}
			}
			
			int index = 0;

			// Consume ALL
			if ( consumeType == ConsumeType.All )
			{
				m_ResHue = 0; m_ResAmount = 0; m_System = craftSystem;

				if ( IsQuantityType( types ) )
					index = ConsumeQuantity( ourPack, types, amounts );
				else
					index = ourPack.ConsumeTotalGrouped( types, amounts, true, new OnItemConsumed( OnResourceConsumed ), new CheckItemGroup( CheckHueGrouping ) );

				resHue = m_ResHue;
			}

			// Consume Half ( for use all resource craft type )
			else if ( consumeType == ConsumeType.Half )
			{
				for ( int i = 0; i < amounts.Length; i++ )
				{
					amounts[i] /= 2;

					if ( amounts[i] < 1 )
						amounts[i] = 1;
				}

				m_ResHue = 0; m_ResAmount = 0; m_System = craftSystem;

				if ( IsQuantityType( types ) )
					index = ConsumeQuantity( ourPack, types, amounts );
				else
					index = ourPack.ConsumeTotalGrouped( types, amounts, true, new OnItemConsumed( OnResourceConsumed ), new CheckItemGroup( CheckHueGrouping ) );

				resHue = m_ResHue;
			}

			else // ConstumeType.None ( it's basicaly used to know if the crafter has enough resource before starting the process )
			{
				index = -1;

				if ( IsQuantityType( types ) )
				{
					for ( int i = 0; i < types.Length; i++ )
					{
						if ( GetQuantity( ourPack, types[i] ) < amounts[i] )
						{
							index = i;
							break;
						}
					}
				}
				else
				{
					for ( int i = 0; i < types.Length; i++ )
					{
						if ( ourPack.GetBestGroupAmount( types[i], true, new CheckItemGroup( CheckHueGrouping ) ) < amounts[i] )
						{
							index = i;
							break;
						}
					}
				}
			}

			if ( index == -1 )
			{
				if ( consumeType != ConsumeType.None )
					if ( consumeExtra != null )
						consumeExtra.Delete();

				return true;
			}
			else
			{
				CraftRes res = m_arCraftRes.GetAt( index );

				if ( res.MessageNumber > 0 )
					message = res.MessageNumber;
				else if ( res.MessageString != null && res.MessageString != String.Empty )
					message = res.NameString;
				else
					message = 502925; // You don't have the resources required to make that item.

				return false;
			}
		}

		private int m_ResHue;
		private int m_ResAmount;
		private CraftSystem m_System;

		private void OnResourceConsumed( Item item, int amount )
		{
			if ( !RetainsColorFrom( m_System, item.GetType() ) )
				return;

			if ( amount >= m_ResAmount )
			{
				m_ResHue = item.Hue;
				m_ResAmount = amount;
			}
		}

		private int CheckHueGrouping( Item a, Item b )
		{
			return b.Hue.CompareTo( a.Hue );
		}

		public double GetExceptionalChance( CraftSystem system, double chance, Mobile from )
		{
			switch ( system.ECA )
			{
				default:
				case CraftECA.ChanceMinusSixty: return chance - 0.6;
				case CraftECA.FiftyPercentChanceMinusTenPercent: return (chance * 0.5) - 0.1;
				case CraftECA.ChanceMinusSixtyToFourtyFive:
				{
					double offset = 0.60 - ((from.Skills[system.MainSkill].Value - 95.0) * 0.03);

					if ( offset < 0.45 )
						offset = 0.45;
					else if ( offset > 0.60 )
						offset = 0.60;

					return chance - offset;
				}
			}
		}

		public bool CheckSkills( Mobile from, Type typeRes, CraftSystem craftSystem, ref int quality, ref bool allRequiredSkills )
		{
			return CheckSkills( from, typeRes, craftSystem, ref quality, ref allRequiredSkills, true );
		}

		public bool CheckSkills( Mobile from, Type typeRes, CraftSystem craftSystem, ref int quality, ref bool allRequiredSkills, bool gainSkills )
		{
			double chance = GetSuccessChance( from, typeRes, craftSystem, gainSkills, ref allRequiredSkills );

			if ( GetExceptionalChance( craftSystem, chance, from ) >= Utility.RandomDouble() )
				quality = 2;

			return ( chance >= Utility.RandomDouble() );
		}

		public double GetSuccessChance( Mobile from, Type typeRes, CraftSystem craftSystem, bool gainSkills, ref bool allRequiredSkills )
		{
			double minMainSkill = 0.0;
			double maxMainSkill = 0.0;
			double valMainSkill = 0.0;

			allRequiredSkills = true;

			for ( int i = 0; i < m_arCraftSkill.Count; i++)
			{
				CraftSkill craftSkill = m_arCraftSkill.GetAt(i);

				double minSkill = craftSkill.MinSkill;
				double maxSkill = craftSkill.MaxSkill;
				double valSkill = from.Skills[craftSkill.SkillToMake].Value;

				if ( valSkill < minSkill )
					allRequiredSkills = false;

				if ( craftSkill.SkillToMake == craftSystem.MainSkill )
				{
					minMainSkill = minSkill;
					maxMainSkill = maxSkill;
					valMainSkill = valSkill;
				}

				if ( gainSkills ) // This is a passive check. Success chance is entirely dependant on the main skill
					from.CheckSkill( craftSkill.SkillToMake, minSkill, maxSkill );
			}

			double chance;

			if ( allRequiredSkills )
				chance = craftSystem.GetChanceAtMin( this ) + ((valMainSkill - minMainSkill) / (maxMainSkill - minMainSkill) * (1.0 - craftSystem.GetChanceAtMin( this )));
			else
				chance = 0.0;

			if ( allRequiredSkills && valMainSkill == maxMainSkill )
				chance = 1.0;

			return chance;
		}

		public void Craft( Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool )
		{
			if ( from.BeginAction( typeof( CraftSystem ) ) )
			{
				bool allRequiredSkills = true;
				double chance = GetSuccessChance( from, typeRes, craftSystem, false, ref allRequiredSkills );

				if ( allRequiredSkills && chance >= 0.0 )
				{
					int badCraft = craftSystem.CanCraft( from, tool, m_Type );

					if ( badCraft <= 0 )
					{
						int resHue = 0;
						int maxAmount = 0;
						object message = null;

						if ( ConsumeRes( from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.None, ref message ) )
						{
							message = null;

							if ( ConsumeAttributes( from, ref message, false ) )
							{
								CraftContext context = craftSystem.GetContext( from );

								if ( context != null )
									context.OnMade( this );

								int iMin = craftSystem.MinCraftEffect;
								int iMax = ( craftSystem.MaxCraftEffect - iMin ) + 1;
								int iRandom = Utility.Random( iMax );
								iRandom += iMin + 1;
								new InternalTimer( from, craftSystem, this, typeRes, tool, iRandom ).Start();
							}
							else
							{
								from.EndAction( typeof( CraftSystem ) );
								from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
							}
						}
						else
						{
							from.EndAction( typeof( CraftSystem ) );
							from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
						}
					}
					else
					{
						from.EndAction( typeof( CraftSystem ) );
						from.SendGump( new CraftGump( from, craftSystem, tool, badCraft ) );
					}
				}
				else
				{
					from.EndAction( typeof( CraftSystem ) );
					from.SendGump( new CraftGump( from, craftSystem, tool, 1044153 ) ); // You don't have the required skills to attempt this item.
				}
			}
			else
			{
				from.SendLocalizedMessage( 500119 ); // You must wait to perform another action
			}
		}

		public void CompleteCraft( int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool )
		{
			int badCraft = craftSystem.CanCraft( from, tool, m_Type );

			if ( badCraft > 0 )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, badCraft ) );
				else
					from.SendLocalizedMessage( badCraft );

				return;
			}

			int checkResHue = 0, checkMaxAmount = 0;
			object checkMessage = null;

			// Not enough resource to craft it
			if ( !ConsumeRes( from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage ) )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, checkMessage ) );
				else if ( checkMessage is int && (int)checkMessage > 0 )
					from.SendLocalizedMessage( (int)checkMessage );
				else if ( checkMessage is string )
					from.SendMessage( (string)checkMessage );

				return;
			}
			else if ( !ConsumeAttributes( from, ref checkMessage, false ) )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, checkMessage ) );
				else if ( checkMessage is int && (int)checkMessage > 0 )
					from.SendLocalizedMessage( (int)checkMessage );
				else if ( checkMessage is string )
					from.SendMessage( (string)checkMessage );

				return;
			}

			bool toolBroken = false;

			int ignored = 1;
			int endquality = 1;

			bool allRequiredSkills = true;

			if ( CheckSkills( from, typeRes, craftSystem, ref ignored, ref allRequiredSkills ) )
			{
				// Resource
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if ( !ConsumeRes( from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message ) )
				{
					if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
						from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
					else if ( message is int && (int)message > 0 )
						from.SendLocalizedMessage( (int)message );
					else if ( message is string )
						from.SendMessage( (string)message );

					return;
				}
				else if ( !ConsumeAttributes( from, ref message, true ) )
				{
					if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
						from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
					else if ( message is int && (int)message > 0 )
						from.SendLocalizedMessage( (int)message );
					else if ( message is string )
						from.SendMessage( (string)message );

					return;
				}

				tool.UsesRemaining--;

				if ( tool.UsesRemaining < 1 )
					toolBroken = true;

				if ( toolBroken )
					tool.Delete();

				Item item = Activator.CreateInstance( ItemType ) as Item;

				if ( item != null )
				{
					if ( item is BaseWeapon )
					{
						BaseWeapon weapon = ( BaseWeapon )item;
						weapon.Quality = (WeaponQuality)quality;
						endquality = quality;

						if ( makersMark )
							weapon.Crafter = from;

						weapon.PlayerConstructed = true;

						if ( Core.AOS )
						{
							Type resourceType = typeRes;

							if ( resourceType == null )
								resourceType = Ressources.GetAt( 0 ).ItemType;

							weapon.Resource = CraftResources.GetFromType( resourceType );

							CraftContext context = craftSystem.GetContext( from );

							if ( context != null && context.DoNotColor )
								weapon.Hue = 0;

							if ( tool is BaseRunicTool )
								((BaseRunicTool)tool).ApplyAttributesTo( weapon );

							if ( quality == 2 )
							{
								if ( weapon.Attributes.WeaponDamage > 35 )
									weapon.Attributes.WeaponDamage -= 20;
								else
									weapon.Attributes.WeaponDamage = 15;
							}
						}
						else if ( tool is BaseRunicTool )
						{
							Type resourceType = typeRes;

							if ( resourceType == null )
								resourceType = Ressources.GetAt( 0 ).ItemType;

							CraftResource thisResource = CraftResources.GetFromType( resourceType );

							if ( thisResource == ((BaseRunicTool)tool).Resource )
							{
								weapon.Resource = thisResource;

								CraftContext context = craftSystem.GetContext( from );

								if ( context != null && context.DoNotColor )
									weapon.Hue = 0;

								switch ( thisResource )
								{
									case CraftResource.DullCopper:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Durable;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Accurate;
										break;
									}
									case CraftResource.ShadowIron:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Durable;
										weapon.DamageLevel = WeaponDamageLevel.Ruin;
										break;
									}
									case CraftResource.Copper:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Fortified;
										weapon.DamageLevel = WeaponDamageLevel.Ruin;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Surpassingly;
										break;
									}
									case CraftResource.Bronze:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Fortified;
										weapon.DamageLevel = WeaponDamageLevel.Might;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Surpassingly;
										break;
									}
									case CraftResource.Gold:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Indestructible;
										weapon.DamageLevel = WeaponDamageLevel.Force;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Eminently;
										break;
									}
									case CraftResource.Agapite:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Indestructible;
										weapon.DamageLevel = WeaponDamageLevel.Power;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Eminently;
										break;
									}
									case CraftResource.Verite:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Indestructible;
										weapon.DamageLevel = WeaponDamageLevel.Power;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Exceedingly;
										break;
									}
									case CraftResource.Valorite:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Indestructible;
										weapon.DamageLevel = WeaponDamageLevel.Vanq;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Supremely;
										break;
									}
								}
							}
						}
					}
					else if ( item is BaseArmor )
					{
						BaseArmor armor = ( BaseArmor )item;
						armor.Quality = (ArmorQuality)quality;
						endquality = quality;

						if ( makersMark )
							armor.Crafter = from;

						Type resourceType = typeRes;

						if ( resourceType == null )
							resourceType = Ressources.GetAt( 0 ).ItemType;

						armor.Resource = CraftResources.GetFromType( resourceType );
						armor.PlayerConstructed = true;

						CraftContext context = craftSystem.GetContext( from );

						if ( context != null && context.DoNotColor )
							armor.Hue = 0;

						if ( quality == 2 )
							armor.DistributeBonuses( (tool is BaseRunicTool ? 6 : 14) );

						if ( Core.AOS && tool is BaseRunicTool )
							((BaseRunicTool)tool).ApplyAttributesTo( armor );
					}
					else if ( item is DragonBardingDeed )
					{
						DragonBardingDeed deed = (DragonBardingDeed)item;

						deed.Exceptional = ( quality >= 2 );
						endquality = quality;

						if ( makersMark )
							deed.Crafter = from;

						Type resourceType = typeRes;

						if ( resourceType == null )
							resourceType = Ressources.GetAt( 0 ).ItemType;

						deed.Resource = CraftResources.GetFromType( resourceType );

						CraftContext context = craftSystem.GetContext( from );

						if ( context != null && context.DoNotColor )
							deed.Hue = 0;
					}
					else if ( item is BaseInstrument )
					{
						BaseInstrument instrument = (BaseInstrument)item;

						instrument.Quality = (InstrumentQuality)quality;
						endquality = quality;

						if ( makersMark )
							instrument.Crafter = from;
					}
					else if ( item is BaseJewel )
					{
						BaseJewel jewel = (BaseJewel)item;

						Type resourceType = typeRes;

						if ( resourceType == null )
							resourceType = Ressources.GetAt( 0 ).ItemType;

						jewel.Resource = CraftResources.GetFromType( resourceType );

						if ( 1 < Ressources.Count )
						{
							resourceType = Ressources.GetAt( 1 ).ItemType;

							if ( resourceType == typeof( StarSapphire ) )
								jewel.GemType = GemType.StarSapphire;
							else if ( resourceType == typeof( Emerald ) )
								jewel.GemType = GemType.Emerald;
							else if ( resourceType == typeof( Sapphire ) )
								jewel.GemType = GemType.Sapphire;
							else if ( resourceType == typeof( Ruby ) )
								jewel.GemType = GemType.Ruby;
							else if ( resourceType == typeof( Citrine ) )
								jewel.GemType = GemType.Citrine;
							else if ( resourceType == typeof( Amethyst ) )
								jewel.GemType = GemType.Amethyst;
							else if ( resourceType == typeof( Tourmaline ) )
								jewel.GemType = GemType.Tourmaline;
							else if ( resourceType == typeof( Amber ) )
								jewel.GemType = GemType.Amber;
							else if ( resourceType == typeof( Diamond ) )
								jewel.GemType = GemType.Diamond;
						}
					}
					else if ( item is BaseClothing )
					{
						BaseClothing clothing = (BaseClothing)item;
						clothing.Quality = (ClothingQuality)quality;
						endquality = quality;

						if ( makersMark )
							clothing.Crafter = from;

						clothing.PlayerConstructed = true;

						if ( item is BaseShoes )
						{
							BaseShoes shoes = (BaseShoes)item;

							if ( shoes.Resource != CraftResource.None )
							{
								Type resourceType = typeRes;

								if ( resourceType == null )
									resourceType = Ressources.GetAt( 0 ).ItemType;

								shoes.Resource = CraftResources.GetFromType( resourceType );

								CraftContext context = craftSystem.GetContext( from );

								if ( context != null && context.DoNotColor )
									shoes.Hue = 0;
							}
							else
							{
								shoes.Hue = resHue;
							}
						}
						else
						{
							clothing.Hue = resHue;
						}
					}
					else if ( item is MapItem )
					{
						((MapItem)item).CraftInit( from );
					}
					else if ( item is LockableContainer )
					{
						if ( from.CheckSkill( SkillName.Tinkering, -5.0, 15.0 ) )
						{
							LockableContainer cont = (LockableContainer)item;

							from.SendLocalizedMessage( 500636 ); // Your tinker skill was sufficient to make the item lockable.

							Key key = new Key( KeyType.Copper, Key.RandomValue() );

							cont.KeyValue = key.KeyValue;
							cont.DropItem( key );

							double tinkering = from.Skills[SkillName.Tinkering].Value;
							int level = (int)(tinkering * 0.8);

							cont.RequiredSkill = level - 4;
							cont.LockLevel = level - 14;
							cont.MaxLockLevel = level + 35;

							if ( cont.LockLevel == 0 )
								cont.LockLevel = -1;
							else if ( cont.LockLevel > 95 )
								cont.LockLevel = 95;

							if ( cont.RequiredSkill > 95 )
								cont.RequiredSkill = 95;

							if ( cont.MaxLockLevel > 95 )
								cont.MaxLockLevel = 95;
						}
						else
						{
							from.SendLocalizedMessage( 500637 ); // Your tinker skill was insufficient to make the item lockable.
						}
					}
					else if ( item is Runebook )
					{
						int charges = 5 + quality + (int)(from.Skills[SkillName.Inscribe].Value / 30);
						endquality = quality;

						if ( charges > 10 )
							charges = 10;

						((Runebook)item).MaxCharges = charges;
					}
					else if ( item.Hue == 0 )
					{
						item.Hue = resHue;
					}

					if ( maxAmount > 0 )
						item.Amount = maxAmount;

					// **********************************************

					if ( craftSystem is DefAlchemy && item is BasePotion )
					{
						BasePotion pot = (BasePotion)item;

						Container pack = from.Backpack;

						if ( pack != null )
						{
							Item[] kegs = pack.FindItemsByType( typeof( PotionKeg ), true );

							for ( int i = 0; i < kegs.Length; ++i )
							{
								PotionKeg keg = kegs[i] as PotionKeg;

								if ( keg == null )
									continue;

								if ( keg.Held <= 0 || keg.Held >= 100 )
									continue;

								if ( keg.Type != pot.PotionEffect )
									continue;

								++keg.Held;
								item.Delete();
								item = new Bottle();

								endquality = -1; // signal placed in keg

								break;
							}
						}
					}

					from.AddToBackpack( item );

					//from.PlaySound( 0x57 );
				}

				int num = craftSystem.PlayEndingEffect( from, false, true, toolBroken, endquality, makersMark, this );

				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, num ) );
				else if ( num > 0 )
					from.SendLocalizedMessage( num );
			}
			else if ( !allRequiredSkills )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, 1044153 ) );
				else
					from.SendLocalizedMessage( 1044153 ); // You don't have the required skills to attempt this item.
			}
			else
			{
				ConsumeType consumeType = ( UseAllRes ? ConsumeType.Half : ConsumeType.All );
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if ( !ConsumeRes( from, typeRes, craftSystem, ref resHue, ref maxAmount, consumeType, ref message ) )
				{
					if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
						from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
					else if ( message is int && (int)message > 0 )
						from.SendLocalizedMessage( (int)message );
					else if ( message is string )
						from.SendMessage( (string)message );

					return;
				}

				tool.UsesRemaining--;

				if ( tool.UsesRemaining < 1 )
					toolBroken = true;

				if ( toolBroken )
					tool.Delete();

				// SkillCheck failed.
				int num = craftSystem.PlayEndingEffect( from, true, true, toolBroken, endquality, false, this );

				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, num ) );
				else if ( num > 0 )
					from.SendLocalizedMessage( num );
			}
		}

		private class InternalTimer : Timer
		{
			private Mobile m_From;
			private int m_iCount;
			private int m_iCountMax;
			private CraftItem m_CraftItem;
			private CraftSystem m_CraftSystem;
			private Type m_TypeRes;
			private BaseTool m_Tool;

			public InternalTimer( Mobile from, CraftSystem craftSystem, CraftItem craftItem, Type typeRes, BaseTool tool, int iCountMax ) : base( TimeSpan.Zero, TimeSpan.FromSeconds( craftSystem.Delay ), iCountMax )
			{
				m_From = from;
				m_CraftItem = craftItem;
				m_iCount = 0;
				m_iCountMax = iCountMax;
				m_CraftSystem = craftSystem;
				m_TypeRes = typeRes;
				m_Tool = tool;
			}

			private static Type[] m_MarkableTypes = new Type[]
				{
					typeof( BaseArmor ),
					typeof( BaseWeapon ),
					typeof( BaseClothing ),
					typeof( DragonBardingDeed )
				};

			protected override void OnTick()
			{
				m_iCount++;

				m_From.DisruptiveAction();

				if ( m_iCount < m_iCountMax )
				{
					m_CraftSystem.PlayCraftEffect( m_From );
				}
				else
				{
					m_From.EndAction( typeof( CraftSystem ) );

					int badCraft = m_CraftSystem.CanCraft( m_From, m_Tool, m_CraftItem.m_Type );

					if ( badCraft > 0 )
					{
						if ( m_Tool != null && !m_Tool.Deleted && m_Tool.UsesRemaining > 0 )
							m_From.SendGump( new CraftGump( m_From, m_CraftSystem, m_Tool, badCraft ) );
						else
							m_From.SendLocalizedMessage( badCraft );

						return;
					}

					int quality = 1;
					bool allRequiredSkills = true;

					m_CraftItem.CheckSkills( m_From, m_TypeRes, m_CraftSystem, ref quality, ref allRequiredSkills, false );

					CraftContext context = m_CraftSystem.GetContext( m_From );

					if ( context == null )
						return;

					bool makersMark = false;

					if ( quality == 2 && m_From.Skills[m_CraftSystem.MainSkill].Base >= 100.0 )
					{
						for ( int i = 0; !makersMark && i < m_MarkableTypes.Length; ++i )
							makersMark = ( m_MarkableTypes[i].IsAssignableFrom( m_CraftItem.ItemType ) );
						
						bool isValid = true;
						if ( (name = m_CraftItem.Name) == null )
						{
						m_From.SendMessage( "Enter the name you wish to call this item" );
						m_from.Prompt = new NameChangePrompt(from, m_CraftItem);
						}
					}					
					
					if ( makersMark && context.MarkOption == CraftMarkOption.PromptForMark )
					{
						m_From.SendGump( new QueryMakersMarkGump( quality, m_From, m_CraftItem, m_CraftSystem, m_TypeRes, m_Tool ) );
						
						bool isValid = true;
						if ( (name = m_CraftItem.Name) == null )
						{
						m_From.SendMessage( "Enter the name you wish to call this item" );
						
						}
					}
					else
					{
						if ( context.MarkOption == CraftMarkOption.DoNotMark )
							makersMark = false;

						m_CraftItem.CompleteCraft( quality, makersMark, m_From, m_CraftSystem, m_TypeRes, m_Tool );
					}
					
								public class NameChangePrompt : Prompt
	{
		private Item m_Item;
		public NameChangePrompt( Mobile from, Item item )
		{
			m_Item = item;
			from.SendMessage("What would you like to change your name to (2-16 characters)?");
		}

		public override void OnResponse( Mobile from, string text )
		{

			text = text.Trim();
			if (!NameVerification.Validate( text, 2, 16, true, false, true, 1, NameVerification.SpaceDashPeriodQuote ))
				from.SendLocalizedMessage( "Names must contain 2-16 alphabetic characters." );
			else
			{
				from.Name = text;
				m_Item.Delete();
			}
		}
	}
				}
			}
		}
	}
}
Memnoch is offline   Reply With Quote
Old 10-18-2005, 01:05 AM   #2 (permalink)
Forum Expert
 
Khaz's Avatar
 
Join Date: Mar 2003
Location: where I belong
Posts: 1,784
Default

You've got some crazy bracket stuff happening at the end of the file there, and it's going to remain illegible until that gets fixed. Line everything up, match brackets, etc.
__________________
"Misfortune shows those who are not really friends." -Aristotle
"A multitude of words is no proof of a prudent mind." -Thales
Khaz is offline   Reply With Quote
Old 10-18-2005, 08:29 AM   #3 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Holy farked up bracket batman!
Phantom is offline   Reply With Quote
Old 10-18-2005, 10:53 AM   #4 (permalink)
 
Join Date: May 2005
Location: Maine
Posts: 783
Default SharpDevelop!

I would get a syntax highlighting fancy code editor. I use sharpdevelop (http://www.icsharpcode.net/OpenSource/SD/Default.aspx), and it REALLY helps with matching up your curly braces, which (as told above) is exactly what your problem is. Each opening { needs a corresponding closing }. Too many, or too few, and your code won't werk.
Arvoreen is offline   Reply With Quote
Old 10-18-2005, 01:16 PM   #5 (permalink)
Forum Expert
 
Vorspire's Avatar
 
Join Date: Jan 2005
Location: Newcastle, United Kingdom
Age: 21
Posts: 2,298
Send a message via ICQ to Vorspire Send a message via MSN to Vorspire Send a message via Skype™ to Vorspire
Default

the editor i use is great.. if you scroll right down to the very last closing bracket (EOF), delete it and replace it.. the whole script's code will become perfectly aligned..

if you do it at the bottom of any method.. it will align that method too

really handy.. Visual Studio .Net 2003
Vorspire is offline   Reply With Quote
Old 10-18-2005, 02:31 PM   #6 (permalink)
 
Join Date: Aug 2004
Age: 30
Posts: 546
Default

Quote:
Originally Posted by Arvoreen
I would get a syntax highlighting fancy code editor. I use sharpdevelop (http://www.icsharpcode.net/OpenSource/SD/Default.aspx), and it REALLY helps with matching up your curly braces, which (as told above) is exactly what your problem is. Each opening { needs a corresponding closing }. Too many, or too few, and your code won't werk.
Yes i have this too, but when i did a check (a quick one) i didnt happen to see any opens without closes. I'll check late tonight after work and see if i can find it.
Memnoch is offline   Reply With Quote
Old 10-19-2005, 11:48 AM   #7 (permalink)
 
Join Date: Dec 2004
Age: 26
Posts: 58
Default

I put it in VS 2003 and got all the bracket issues cleared. heres what i have

Code:
using System;
using Server.Items;

namespace Server.Engines.Craft
{
	public enum ConsumeType
	{
		All, Half, None
	}

	public class CraftItem
	{
		private CraftResCol m_arCraftRes;
		private CraftSkillCol m_arCraftSkill;
		private Type m_Type;

		private string m_GroupNameString;
		private int m_GroupNameNumber;

		private string m_NameString;
		private int m_NameNumber;
		
		private int m_Mana;
		private int m_Hits;
		private int m_Stam;

		private bool m_UseAllRes;

		private bool m_NeedHeat;
		private bool m_NeedOven;

		private bool m_UseSubRes2;

		public CraftItem( Type type, string groupName, string name )
		{
			m_arCraftRes = new CraftResCol();
			m_arCraftSkill = new CraftSkillCol();

			m_Type = type;
			m_GroupNameString = groupName;
			m_NameString = name;
		}

		public CraftItem( Type type, int groupName, int name )
		{
			m_arCraftRes = new CraftResCol();
			m_arCraftSkill = new CraftSkillCol();

			m_Type = type;
			m_GroupNameNumber = groupName;
			m_NameNumber = name;
		}

		public CraftItem( Type type, int groupName, string name )
		{
			m_arCraftRes = new CraftResCol();
			m_arCraftSkill = new CraftSkillCol();

			m_Type = type;
			m_GroupNameNumber = groupName;
			m_NameString = name;
		}

		public void AddRes( Type type, int name, int amount )
		{
			AddRes( type, name, amount, "" );
		}

		public void AddRes( Type type, int name, int amount, int localizedMessage )
		{
			CraftRes craftRes = new CraftRes( type, name, amount, localizedMessage );
			m_arCraftRes.Add( craftRes );
		}

		public void AddRes( Type type, int name, int amount, string strMessage )
		{
			CraftRes craftRes = new CraftRes( type, name, amount, strMessage );
			m_arCraftRes.Add( craftRes );
		}

		public void AddRes( Type type, string name, int amount )
		{
			AddRes( type, name, amount, "" );
		}

		public void AddRes( Type type, string name, int amount, int localizedMessage )
		{
			CraftRes craftRes = new CraftRes( type, name, amount, localizedMessage );
			m_arCraftRes.Add( craftRes );
		}

		public void AddRes( Type type, string name, int amount, string strMessage )
		{
			CraftRes craftRes = new CraftRes( type, name, amount, strMessage );
			m_arCraftRes.Add( craftRes );
		}

		public void AddSkill( SkillName skillToMake, double minSkill, double maxSkill )
		{
			CraftSkill craftSkill = new CraftSkill( skillToMake, minSkill, maxSkill );
			m_arCraftSkill.Add( craftSkill );
		}

		public int Mana
		{
			get { return m_Mana; }
			set { m_Mana = value; }
		}

		public int Hits
		{
			get { return m_Hits; }
			set { m_Hits = value; }
		}

		public int Stam
		{
			get { return m_Stam; }
			set { m_Stam = value; }
		}

		public bool UseSubRes2
		{
			get { return m_UseSubRes2; }
			set { m_UseSubRes2 = value; }
		}

		public bool UseAllRes
		{
			get { return m_UseAllRes; }
			set { m_UseAllRes = value; }
		}

		public bool NeedHeat
		{
			get { return m_NeedHeat; }
			set { m_NeedHeat = value; }
		}

		public bool NeedOven
		{
			get { return m_NeedOven; }
			set { m_NeedOven = value; }
		}
		
		public Type ItemType
		{
			get { return m_Type; }
		}

		public string GroupNameString
		{
			get { return m_GroupNameString; }
		}

		public int GroupNameNumber
		{
			get { return m_GroupNameNumber; }
		}

		public string NameString
		{
			get { return m_NameString; }
		}

		public int NameNumber
		{
			get { return m_NameNumber; }
		}

		public CraftResCol Ressources
		{
			get { return m_arCraftRes; }
		}

		public CraftSkillCol Skills
		{
			get { return m_arCraftSkill; }
		}

		public bool ConsumeAttributes( Mobile from, ref object message, bool consume )
		{
			bool consumMana = false;
			bool consumHits = false;
			bool consumStam = false;

			if ( Hits > 0 && from.Hits < Hits )
			{
				message = "You lack the required hit points to make that.";
				return false;
			}
			else
			{
				consumHits = consume;
			}

			if ( Mana > 0 && from.Mana < Mana )
			{
				message = "You lack the required mana to make that.";
				return false;
			}
			else
			{
				consumMana = consume;
			}

			if ( Stam > 0 && from.Stam < Stam )
			{
				message = "You lack the required stamina to make that.";
				return false;
			}
			else
			{
				consumStam = consume;
			}

			if ( consumMana )
				from.Mana -= Mana;

			if ( consumHits )
				from.Hits -= Hits;

			if ( consumStam )
				from.Stam -= Stam;

			return true;
		}

		private static Type[][] m_TypesTable = new Type[][]
			{
				new Type[]{ typeof( Log ), typeof( Board ) },
				new Type[]{ typeof( Leather ), typeof( Hides ) },
				new Type[]{ typeof( SpinedLeather ), typeof( SpinedHides ) },
				new Type[]{ typeof( HornedLeather ), typeof( HornedHides ) },
				new Type[]{ typeof( BarbedLeather ), typeof( BarbedHides ) },
				new Type[]{ typeof( BlankMap ), typeof( BlankScroll ) },
				new Type[]{ typeof( Cloth ), typeof( UncutCloth ) },
				new Type[]{ typeof( CheeseWheel ), typeof( CheeseWedge ) }
			};

		private static Type[] m_ColoredItemTable = new Type[]
			{
				typeof( BaseWeapon ), typeof( BaseArmor ), typeof( BaseClothing ),
				typeof( BaseJewel ), typeof( DragonBardingDeed )
			};

		private static Type[] m_ColoredResourceTable = new Type[]
			{
				typeof( BaseIngot ), typeof( BaseOre ),
				typeof( BaseLeather ), typeof( BaseHides ),
				typeof( UncutCloth ), typeof( Cloth ),
				typeof( BaseGranite ), typeof( BaseScales )
			};

		public bool RetainsColorFrom( CraftSystem system, Type type )
		{
			if ( system.RetainsColorFrom( this, type ) )
				return true;

			bool inItemTable = false, inResourceTable = false;

			for ( int i = 0; !inItemTable && i < m_ColoredItemTable.Length; ++i )
				inItemTable = ( m_Type == m_ColoredItemTable[i] || m_Type.IsSubclassOf( m_ColoredItemTable[i] ) );

			for ( int i = 0; inItemTable && !inResourceTable && i < m_ColoredResourceTable.Length; ++i )
				inResourceTable = ( type == m_ColoredResourceTable[i] || type.IsSubclassOf( m_ColoredResourceTable[i] ) );

			return ( inItemTable && inResourceTable );
		}

		private static int[] m_HeatSources = new int[]
			{
				0x461, 0x48E, // Sandstone oven/fireplace
				0x92B, 0x96C, // Stone oven/fireplace
				0xDE3, 0xDE9, // Campfire
				0xFAC, 0xFAC, // Firepit
				0x184A, 0x184C, // Heating stand (left)
				0x184E, 0x1850, // Heating stand (right)
				0x398C, 0x399F  // Fire field
			};

		private static int[] m_Ovens = new int[]
			{
				0x461, 0x46F, // Sandstone oven
				0x92B, 0x93F  // Stone oven
			};

		public bool Find( Mobile from, int[] itemIDs )
		{
			Map map = from.Map;

			if ( map == null )
				return false;

			IPooledEnumerable eable = map.GetItemsInRange( from.Location, 2 );

			foreach ( Item item in eable )
			{
				if ( (item.Z + 16) > from.Z && (from.Z + 16) > item.Z && Find( item.ItemID, itemIDs ) )
				{
					eable.Free();
					return true;
				}
			}

			eable.Free();

			for ( int x = -2; x <= 2; ++x )
			{
				for ( int y = -2; y <= 2; ++y )
				{
					int vx = from.X + x;
					int vy = from.Y + y;

					Tile[] tiles = map.Tiles.GetStaticTiles( vx, vy, true );

					for ( int i = 0; i < tiles.Length; ++i )
					{
						int z = tiles[i].Z;
						int id = tiles[i].ID & 0x3FFF;

						if ( (z + 16) > from.Z && (from.Z + 16) > z && Find( id, itemIDs ) )
							return true;
					}
				}
			}

			return false;
		}

		public bool Find( int itemID, int[] itemIDs )
		{
			bool contains = false;

			for ( int i = 0; !contains && i < itemIDs.Length; i += 2 )
				contains = ( itemID >= itemIDs[i] && itemID <= itemIDs[i + 1] );

			return contains;
		}

		public bool IsQuantityType( Type[][] types )
		{
			for ( int i = 0; i < types.Length; ++i )
			{
				Type[] check = types[i];

				for ( int j = 0; j < check.Length; ++j )
				{
					if ( typeof( IHasQuantity ).IsAssignableFrom( check[j] ) )
						return true;
				}
			}

			return false;
		}

		public int ConsumeQuantity( Container cont, Type[][] types, int[] amounts )
		{
			if ( types.Length != amounts.Length )
				throw new ArgumentException();

			Item[][] items = new Item[types.Length][];
			int[] totals = new int[types.Length];

			for ( int i = 0; i < types.Length; ++i )
			{
				items[i] = cont.FindItemsByType( types[i], true );

				for ( int j = 0; j < items[i].Length; ++j )
				{
					IHasQuantity hq = items[i][j] as IHasQuantity;

					if ( hq == null )
					{
						totals[i] += items[i][j].Amount;
					}
					else
					{
						if ( hq is BaseBeverage && ((BaseBeverage)hq).Content != BeverageType.Water )
							continue;

						totals[i] += hq.Quantity;
					}
				}

				if ( totals[i] < amounts[i] )
					return i;
			}

			for ( int i = 0; i < types.Length; ++i )
			{
				int need = amounts[i];

				for ( int j = 0; j < items[i].Length; ++j )
				{
					Item item = items[i][j];
					IHasQuantity hq = item as IHasQuantity;

					if ( hq == null )
					{
						int theirAmount = item.Amount;

						if ( theirAmount < need )
						{
							item.Delete();
							need -= theirAmount;
						}
						else
						{
							item.Consume( need );
							break;
						}
					}
					else
					{
						if ( hq is BaseBeverage && ((BaseBeverage)hq).Content != BeverageType.Water )
							continue;

						int theirAmount = hq.Quantity;

						if ( theirAmount < need )
						{
							hq.Quantity -= theirAmount;
							need -= theirAmount;
						}
						else
						{
							hq.Quantity -= need;
							break;
						}
					}
				}
			}

			return -1;
		}

		public int GetQuantity( Container cont, Type[] types )
		{
			Item[] items = cont.FindItemsByType( types, true );

			int amount = 0;

			for ( int i = 0; i < items.Length; ++i )
			{
				IHasQuantity hq = items[i] as IHasQuantity;

				if ( hq == null )
				{
					amount += items[i].Amount;
				}
				else
				{
					if ( hq is BaseBeverage && ((BaseBeverage)hq).Content != BeverageType.Water )
						continue;

					amount += hq.Quantity;
				}
			}

			return amount;
		}

		public bool ConsumeRes( Mobile from, Type typeRes, CraftSystem craftSystem, ref int resHue, ref int maxAmount, ConsumeType consumeType, ref object message )
		{
			Container ourPack = from.Backpack;

			if ( ourPack == null )
				return false;

			if ( m_NeedHeat && !Find( from, m_HeatSources ) )
			{
				message = 1044487; // You must be near a fire source to cook.
				return false;
			}

			if ( m_NeedOven && !Find( from, m_Ovens ) )
			{
				message = 1044493; // You must be near an oven to bake that.
				return false;
			}

			Type[][] types = new Type[m_arCraftRes.Count][];
			int[] amounts = new int[m_arCraftRes.Count];

			maxAmount = int.MaxValue;

			CraftSubResCol resCol = ( m_UseSubRes2 ? craftSystem.CraftSubRes2 : craftSystem.CraftSubRes );

			for ( int i = 0; i < types.Length; ++i )
			{
				CraftRes craftRes = m_arCraftRes.GetAt( i );
				Type baseType = craftRes.ItemType;

				// Resource Mutation
				if ( (baseType == resCol.ResType) && ( typeRes != null ) )
				{
					baseType = typeRes;

					CraftSubRes subResource = resCol.SearchFor( baseType );

					if ( subResource != null && from.Skills[craftSystem.MainSkill].Base < subResource.RequiredSkill )
					{
						message = subResource.Message;
						return false;
					}
				}
				// ******************

				for ( int j = 0; types[i] == null && j < m_TypesTable.Length; ++j )
				{
					if ( m_TypesTable[j][0] == baseType )
						types[i] = m_TypesTable[j];
				}

				if ( types[i] == null )
					types[i] = new Type[]{ baseType };

				/*if ( !retainedColor && RetainsColorFrom( craftSystem, baseType ) )
				{
					retainedColor = true;
					Item resItem = ourPack.FindItemByType( types[i] );

					if ( resItem != null )
						resHue = resItem.Hue;
				}*/

				amounts[i] = craftRes.Amount;

				// For stackable items that can ben crafted more than one at a time
				if ( UseAllRes )
				{
					int tempAmount = ourPack.GetAmount( types[i] );
					tempAmount /= amounts[i];
					if ( tempAmount < maxAmount )
					{
						maxAmount = tempAmount;

						if ( maxAmount == 0 )
						{
							CraftRes res = m_arCraftRes.GetAt( i );

							if ( res.MessageNumber > 0 )
								message = res.MessageNumber;
							else if ( res.MessageString != null && res.MessageString != String.Empty )
								message = res.NameString;
							else
								message = 502925; // You don't have the resources required to make that item.

							return false;
						}
					}
				}
				// ****************************
			}

			// We adjust the amount of each resource to consume the max posible
			if ( UseAllRes )
			{
				for ( int i = 0; i < amounts.Length; ++i )
					amounts[i] *= maxAmount;
			}
			else
				maxAmount = -1;

			Item consumeExtra = null;

			if ( m_NameNumber == 1041267 )
			{
				// Runebooks are a special case, they need a blank recall rune

				Item[] runes = ourPack.FindItemsByType( typeof( RecallRune ) );

				for ( int i = 0; i < runes.Length; ++i )
				{
					RecallRune rune = runes[i] as RecallRune;

					if ( rune != null && !rune.Marked )
					{
						consumeExtra = rune;
						break;
					}
				}

				if ( consumeExtra == null )
				{
					message = 1044253; // You don't have the components needed to make that.
					return false;
				}
			}
			
			int index = 0;

			// Consume ALL
			if ( consumeType == ConsumeType.All )
			{
				m_ResHue = 0; m_ResAmount = 0; m_System = craftSystem;

				if ( IsQuantityType( types ) )
					index = ConsumeQuantity( ourPack, types, amounts );
				else
					index = ourPack.ConsumeTotalGrouped( types, amounts, true, new OnItemConsumed( OnResourceConsumed ), new CheckItemGroup( CheckHueGrouping ) );

				resHue = m_ResHue;
			}

				// Consume Half ( for use all resource craft type )
			else if ( consumeType == ConsumeType.Half )
			{
				for ( int i = 0; i < amounts.Length; i++ )
				{
					amounts[i] /= 2;

					if ( amounts[i] < 1 )
						amounts[i] = 1;
				}

				m_ResHue = 0; m_ResAmount = 0; m_System = craftSystem;

				if ( IsQuantityType( types ) )
					index = ConsumeQuantity( ourPack, types, amounts );
				else
					index = ourPack.ConsumeTotalGrouped( types, amounts, true, new OnItemConsumed( OnResourceConsumed ), new CheckItemGroup( CheckHueGrouping ) );

				resHue = m_ResHue;
			}

			else // ConstumeType.None ( it's basicaly used to know if the crafter has enough resource before starting the process )
			{
				index = -1;

				if ( IsQuantityType( types ) )
				{
					for ( int i = 0; i < types.Length; i++ )
					{
						if ( GetQuantity( ourPack, types[i] ) < amounts[i] )
						{
							index = i;
							break;
						}
					}
				}
				else
				{
					for ( int i = 0; i < types.Length; i++ )
					{
						if ( ourPack.GetBestGroupAmount( types[i], true, new CheckItemGroup( CheckHueGrouping ) ) < amounts[i] )
						{
							index = i;
							break;
						}
					}
				}
			}

			if ( index == -1 )
			{
				if ( consumeType != ConsumeType.None )
					if ( consumeExtra != null )
						consumeExtra.Delete();

				return true;
			}
			else
			{
				CraftRes res = m_arCraftRes.GetAt( index );

				if ( res.MessageNumber > 0 )
					message = res.MessageNumber;
				else if ( res.MessageString != null && res.MessageString != String.Empty )
					message = res.NameString;
				else
					message = 502925; // You don't have the resources required to make that item.

				return false;
			}
		}

		private int m_ResHue;
		private int m_ResAmount;
		private CraftSystem m_System;

		private void OnResourceConsumed( Item item, int amount )
		{
			if ( !RetainsColorFrom( m_System, item.GetType() ) )
				return;

			if ( amount >= m_ResAmount )
			{
				m_ResHue = item.Hue;
				m_ResAmount = amount;
			}
		}

		private int CheckHueGrouping( Item a, Item b )
		{
			return b.Hue.CompareTo( a.Hue );
		}

		public double GetExceptionalChance( CraftSystem system, double chance, Mobile from )
		{
			switch ( system.ECA )
			{
				default:
				case CraftECA.ChanceMinusSixty: return chance - 0.6;
				case CraftECA.FiftyPercentChanceMinusTenPercent: return (chance * 0.5) - 0.1;
				case CraftECA.ChanceMinusSixtyToFourtyFive:
				{
					double offset = 0.60 - ((from.Skills[system.MainSkill].Value - 95.0) * 0.03);

					if ( offset < 0.45 )
						offset = 0.45;
					else if ( offset > 0.60 )
						offset = 0.60;

					return chance - offset;
				}
			}
		}

		public bool CheckSkills( Mobile from, Type typeRes, CraftSystem craftSystem, ref int quality, ref bool allRequiredSkills )
		{
			return CheckSkills( from, typeRes, craftSystem, ref quality, ref allRequiredSkills, true );
		}

		public bool CheckSkills( Mobile from, Type typeRes, CraftSystem craftSystem, ref int quality, ref bool allRequiredSkills, bool gainSkills )
		{
			double chance = GetSuccessChance( from, typeRes, craftSystem, gainSkills, ref allRequiredSkills );

			if ( GetExceptionalChance( craftSystem, chance, from ) >= Utility.RandomDouble() )
				quality = 2;

			return ( chance >= Utility.RandomDouble() );
		}

		public double GetSuccessChance( Mobile from, Type typeRes, CraftSystem craftSystem, bool gainSkills, ref bool allRequiredSkills )
		{
			double minMainSkill = 0.0;
			double maxMainSkill = 0.0;
			double valMainSkill = 0.0;

			allRequiredSkills = true;

			for ( int i = 0; i < m_arCraftSkill.Count; i++)
			{
				CraftSkill craftSkill = m_arCraftSkill.GetAt(i);

				double minSkill = craftSkill.MinSkill;
				double maxSkill = craftSkill.MaxSkill;
				double valSkill = from.Skills[craftSkill.SkillToMake].Value;

				if ( valSkill < minSkill )
					allRequiredSkills = false;

				if ( craftSkill.SkillToMake == craftSystem.MainSkill )
				{
					minMainSkill = minSkill;
					maxMainSkill = maxSkill;
					valMainSkill = valSkill;
				}

				if ( gainSkills ) // This is a passive check. Success chance is entirely dependant on the main skill
					from.CheckSkill( craftSkill.SkillToMake, minSkill, maxSkill );
			}

			double chance;

			if ( allRequiredSkills )
				chance = craftSystem.GetChanceAtMin( this ) + ((valMainSkill - minMainSkill) / (maxMainSkill - minMainSkill) * (1.0 - craftSystem.GetChanceAtMin( this )));
			else
				chance = 0.0;

			if ( allRequiredSkills && valMainSkill == maxMainSkill )
				chance = 1.0;

			return chance;
		}

		public void Craft( Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool )
		{
			if ( from.BeginAction( typeof( CraftSystem ) ) )
			{
				bool allRequiredSkills = true;
				double chance = GetSuccessChance( from, typeRes, craftSystem, false, ref allRequiredSkills );

				if ( allRequiredSkills && chance >= 0.0 )
				{
					int badCraft = craftSystem.CanCraft( from, tool, m_Type );

					if ( badCraft <= 0 )
					{
						int resHue = 0;
						int maxAmount = 0;
						object message = null;

						if ( ConsumeRes( from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.None, ref message ) )
						{
							message = null;

							if ( ConsumeAttributes( from, ref message, false ) )
							{
								CraftContext context = craftSystem.GetContext( from );

								if ( context != null )
									context.OnMade( this );

								int iMin = craftSystem.MinCraftEffect;
								int iMax = ( craftSystem.MaxCraftEffect - iMin ) + 1;
								int iRandom = Utility.Random( iMax );
								iRandom += iMin + 1;
								new InternalTimer( from, craftSystem, this, typeRes, tool, iRandom ).Start();
							}
							else
							{
								from.EndAction( typeof( CraftSystem ) );
								from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
							}
						}
						else
						{
							from.EndAction( typeof( CraftSystem ) );
							from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
						}
					}
					else
					{
						from.EndAction( typeof( CraftSystem ) );
						from.SendGump( new CraftGump( from, craftSystem, tool, badCraft ) );
					}
				}
				else
				{
					from.EndAction( typeof( CraftSystem ) );
					from.SendGump( new CraftGump( from, craftSystem, tool, 1044153 ) ); // You don't have the required skills to attempt this item.
				}
			}
			else
			{
				from.SendLocalizedMessage( 500119 ); // You must wait to perform another action
			}
		}

		public void CompleteCraft( int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool )
		{
			int badCraft = craftSystem.CanCraft( from, tool, m_Type );

			if ( badCraft > 0 )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, badCraft ) );
				else
					from.SendLocalizedMessage( badCraft );

				return;
			}

			int checkResHue = 0, checkMaxAmount = 0;
			object checkMessage = null;

			// Not enough resource to craft it
			if ( !ConsumeRes( from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage ) )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, checkMessage ) );
				else if ( checkMessage is int && (int)checkMessage > 0 )
					from.SendLocalizedMessage( (int)checkMessage );
				else if ( checkMessage is string )
					from.SendMessage( (string)checkMessage );

				return;
			}
			else if ( !ConsumeAttributes( from, ref checkMessage, false ) )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, checkMessage ) );
				else if ( checkMessage is int && (int)checkMessage > 0 )
					from.SendLocalizedMessage( (int)checkMessage );
				else if ( checkMessage is string )
					from.SendMessage( (string)checkMessage );

				return;
			}

			bool toolBroken = false;

			int ignored = 1;
			int endquality = 1;

			bool allRequiredSkills = true;

			if ( CheckSkills( from, typeRes, craftSystem, ref ignored, ref allRequiredSkills ) )
			{
				// Resource
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if ( !ConsumeRes( from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message ) )
				{
					if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
						from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
					else if ( message is int && (int)message > 0 )
						from.SendLocalizedMessage( (int)message );
					else if ( message is string )
						from.SendMessage( (string)message );

					return;
				}
				else if ( !ConsumeAttributes( from, ref message, true ) )
				{
					if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
						from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
					else if ( message is int && (int)message > 0 )
						from.SendLocalizedMessage( (int)message );
					else if ( message is string )
						from.SendMessage( (string)message );

					return;
				}

				tool.UsesRemaining--;

				if ( tool.UsesRemaining < 1 )
					toolBroken = true;

				if ( toolBroken )
					tool.Delete();

				Item item = Activator.CreateInstance( ItemType ) as Item;

				if ( item != null )
				{
					if ( item is BaseWeapon )
					{
						BaseWeapon weapon = ( BaseWeapon )item;
						weapon.Quality = (WeaponQuality)quality;
						endquality = quality;

						if ( makersMark )
							weapon.Crafter = from;

						weapon.PlayerConstructed = true;

						if ( Core.AOS )
						{
							Type resourceType = typeRes;

							if ( resourceType == null )
								resourceType = Ressources.GetAt( 0 ).ItemType;

							weapon.Resource = CraftResources.GetFromType( resourceType );

							CraftContext context = craftSystem.GetContext( from );

							if ( context != null && context.DoNotColor )
								weapon.Hue = 0;

							if ( tool is BaseRunicTool )
								((BaseRunicTool)tool).ApplyAttributesTo( weapon );

							if ( quality == 2 )
							{
								if ( weapon.Attributes.WeaponDamage > 35 )
									weapon.Attributes.WeaponDamage -= 20;
								else
									weapon.Attributes.WeaponDamage = 15;
							}
						}
						else if ( tool is BaseRunicTool )
						{
							Type resourceType = typeRes;

							if ( resourceType == null )
								resourceType = Ressources.GetAt( 0 ).ItemType;

							CraftResource thisResource = CraftResources.GetFromType( resourceType );

							if ( thisResource == ((BaseRunicTool)tool).Resource )
							{
								weapon.Resource = thisResource;

								CraftContext context = craftSystem.GetContext( from );

								if ( context != null && context.DoNotColor )
									weapon.Hue = 0;

								switch ( thisResource )
								{
									case CraftResource.DullCopper:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Durable;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Accurate;
										break;
									}
									case CraftResource.ShadowIron:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Durable;
										weapon.DamageLevel = WeaponDamageLevel.Ruin;
										break;
									}
									case CraftResource.Copper:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Fortified;
										weapon.DamageLevel = WeaponDamageLevel.Ruin;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Surpassingly;
										break;
									}
									case CraftResource.Bronze:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Fortified;
										weapon.DamageLevel = WeaponDamageLevel.Might;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Surpassingly;
										break;
									}
									case CraftResource.Gold:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Indestructible;
										weapon.DamageLevel = WeaponDamageLevel.Force;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Eminently;
										break;
									}
									case CraftResource.Agapite:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Indestructible;
										weapon.DamageLevel = WeaponDamageLevel.Power;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Eminently;
										break;
									}
									case CraftResource.Verite:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Indestructible;
										weapon.DamageLevel = WeaponDamageLevel.Power;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Exceedingly;
										break;
									}
									case CraftResource.Valorite:
									{
										weapon.Identified = true;
										weapon.DurabilityLevel = WeaponDurabilityLevel.Indestructible;
										weapon.DamageLevel = WeaponDamageLevel.Vanq;
										weapon.AccuracyLevel = WeaponAccuracyLevel.Supremely;
										break;
									}
								}
							}
						}
					}
					else if ( item is BaseArmor )
					{
						BaseArmor armor = ( BaseArmor )item;
						armor.Quality = (ArmorQuality)quality;
						endquality = quality;

						if ( makersMark )
							armor.Crafter = from;

						Type resourceType = typeRes;

						if ( resourceType == null )
							resourceType = Ressources.GetAt( 0 ).ItemType;

						armor.Resource = CraftResources.GetFromType( resourceType );
						armor.PlayerConstructed = true;

						CraftContext context = craftSystem.GetContext( from );

						if ( context != null && context.DoNotColor )
							armor.Hue = 0;

						if ( quality == 2 )
							armor.DistributeBonuses( (tool is BaseRunicTool ? 6 : 14) );

						if ( Core.AOS && tool is BaseRunicTool )
							((BaseRunicTool)tool).ApplyAttributesTo( armor );
					}
					else if ( item is DragonBardingDeed )
					{
						DragonBardingDeed deed = (DragonBardingDeed)item;

						deed.Exceptional = ( quality >= 2 );
						endquality = quality;

						if ( makersMark )
							deed.Crafter = from;

						Type resourceType = typeRes;

						if ( resourceType == null )
							resourceType = Ressources.GetAt( 0 ).ItemType;

						deed.Resource = CraftResources.GetFromType( resourceType );

						CraftContext context = craftSystem.GetContext( from );

						if ( context != null && context.DoNotColor )
							deed.Hue = 0;
					}
					else if ( item is BaseInstrument )
					{
						BaseInstrument instrument = (BaseInstrument)item;

						instrument.Quality = (InstrumentQuality)quality;
						endquality = quality;

						if ( makersMark )
							instrument.Crafter = from;
					}
					else if ( item is BaseJewel )
					{
						BaseJewel jewel = (BaseJewel)item;

						Type resourceType = typeRes;

						if ( resourceType == null )
							resourceType = Ressources.GetAt( 0 ).ItemType;

						jewel.Resource = CraftResources.GetFromType( resourceType );

						if ( 1 < Ressources.Count )
						{
							resourceType = Ressources.GetAt( 1 ).ItemType;

							if ( resourceType == typeof( StarSapphire ) )
								jewel.GemType = GemType.StarSapphire;
							else if ( resourceType == typeof( Emerald ) )
								jewel.GemType = GemType.Emerald;
							else if ( resourceType == typeof( Sapphire ) )
								jewel.GemType = GemType.Sapphire;
							else if ( resourceType == typeof( Ruby ) )
								jewel.GemType = GemType.Ruby;
							else if ( resourceType == typeof( Citrine ) )
								jewel.GemType = GemType.Citrine;
							else if ( resourceType == typeof( Amethyst ) )
								jewel.GemType = GemType.Amethyst;
							else if ( resourceType == typeof( Tourmaline ) )
								jewel.GemType = GemType.Tourmaline;
							else if ( resourceType == typeof( Amber ) )
								jewel.GemType = GemType.Amber;
							else if ( resourceType == typeof( Diamond ) )
								jewel.GemType = GemType.Diamond;
						}
					}
					else if ( item is BaseClothing )
					{
						BaseClothing clothing = (BaseClothing)item;
						clothing.Quality = (ClothingQuality)quality;
						endquality = quality;

						if ( makersMark )
							clothing.Crafter = from;

						clothing.PlayerConstructed = true;

						if ( item is BaseShoes )
						{
							BaseShoes shoes = (BaseShoes)item;

							if ( shoes.Resource != CraftResource.None )
							{
								Type resourceType = typeRes;

								if ( resourceType == null )
									resourceType = Ressources.GetAt( 0 ).ItemType;

								shoes.Resource = CraftResources.GetFromType( resourceType );

								CraftContext context = craftSystem.GetContext( from );

								if ( context != null && context.DoNotColor )
									shoes.Hue = 0;
							}
							else
							{
								shoes.Hue = resHue;
							}
						}
						else
						{
							clothing.Hue = resHue;
						}
					}
					else if ( item is MapItem )
					{
						((MapItem)item).CraftInit( from );
					}
					else if ( item is LockableContainer )
					{
						if ( from.CheckSkill( SkillName.Tinkering, -5.0, 15.0 ) )
						{
							LockableContainer cont = (LockableContainer)item;

							from.SendLocalizedMessage( 500636 ); // Your tinker skill was sufficient to make the item lockable.

							Key key = new Key( KeyType.Copper, Key.RandomValue() );

							cont.KeyValue = key.KeyValue;
							cont.DropItem( key );

							double tinkering = from.Skills[SkillName.Tinkering].Value;
							int level = (int)(tinkering * 0.8);

							cont.RequiredSkill = level - 4;
							cont.LockLevel = level - 14;
							cont.MaxLockLevel = level + 35;

							if ( cont.LockLevel == 0 )
								cont.LockLevel = -1;
							else if ( cont.LockLevel > 95 )
								cont.LockLevel = 95;

							if ( cont.RequiredSkill > 95 )
								cont.RequiredSkill = 95;

							if ( cont.MaxLockLevel > 95 )
								cont.MaxLockLevel = 95;
						}
						else
						{
							from.SendLocalizedMessage( 500637 ); // Your tinker skill was insufficient to make the item lockable.
						}
					}
					else if ( item is Runebook )
					{
						int charges = 5 + quality + (int)(from.Skills[SkillName.Inscribe].Value / 30);
						endquality = quality;

						if ( charges > 10 )
							charges = 10;

						((Runebook)item).MaxCharges = charges;
					}
					else if ( item.Hue == 0 )
					{
						item.Hue = resHue;
					}

					if ( maxAmount > 0 )
						item.Amount = maxAmount;

					// **********************************************

					if ( craftSystem is DefAlchemy && item is BasePotion )
					{
						BasePotion pot = (BasePotion)item;

						Container pack = from.Backpack;

						if ( pack != null )
						{
							Item[] kegs = pack.FindItemsByType( typeof( PotionKeg ), true );

							for ( int i = 0; i < kegs.Length; ++i )
							{
								PotionKeg keg = kegs[i] as PotionKeg;

								if ( keg == null )
									continue;

								if ( keg.Held <= 0 || keg.Held >= 100 )
									continue;

								if ( keg.Type != pot.PotionEffect )
									continue;

								++keg.Held;
								item.Delete();
								item = new Bottle();

								endquality = -1; // signal placed in keg

								break;
							}
						}
					}

					from.AddToBackpack( item );

					//from.PlaySound( 0x57 );
				}

				int num = craftSystem.PlayEndingEffect( from, false, true, toolBroken, endquality, makersMark, this );

				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, num ) );
				else if ( num > 0 )
					from.SendLocalizedMessage( num );
			}
			else if ( !allRequiredSkills )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, 1044153 ) );
				else
					from.SendLocalizedMessage( 1044153 ); // You don't have the required skills to attempt this item.
			}
			else
			{
				ConsumeType consumeType = ( UseAllRes ? ConsumeType.Half : ConsumeType.All );
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if ( !ConsumeRes( from, typeRes, craftSystem, ref resHue, ref maxAmount, consumeType, ref message ) )
				{
					if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
						from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
					else if ( message is int && (int)message > 0 )
						from.SendLocalizedMessage( (int)message );
					else if ( message is string )
						from.SendMessage( (string)message );

					return;
				}

				tool.UsesRemaining--;

				if ( tool.UsesRemaining < 1 )
					toolBroken = true;

				if ( toolBroken )
					tool.Delete();

				// SkillCheck failed.
				int num = craftSystem.PlayEndingEffect( from, true, true, toolBroken, endquality, false, this );

				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, num ) );
				else if ( num > 0 )
					from.SendLocalizedMessage( num );
			}
		}

		private class InternalTimer : Timer
		{
			private Mobile m_From;
			private int m_iCount;
			private int m_iCountMax;
			private CraftItem m_CraftItem;
			private CraftSystem m_CraftSystem;
			private Type m_TypeRes;
			private BaseTool m_Tool;

			public InternalTimer( Mobile from, CraftSystem craftSystem, CraftItem craftItem, Type typeRes, BaseTool tool, int iCountMax ) : base( TimeSpan.Zero, TimeSpan.FromSeconds( craftSystem.Delay ), iCountMax )
			{
				m_From = from;
				m_CraftItem = craftItem;
				m_iCount = 0;
				m_iCountMax = iCountMax;
				m_CraftSystem = craftSystem;
				m_TypeRes = typeRes;
				m_Tool = tool;
			}

			private static Type[] m_MarkableTypes = new Type[]
				{
					typeof( BaseArmor ),
					typeof( BaseWeapon ),
					typeof( BaseClothing ),
					typeof( DragonBardingDeed )
				};

			protected override void OnTick()
			{
				m_iCount++;

				m_From.DisruptiveAction();

				if ( m_iCount < m_iCountMax )
				{
					m_CraftSystem.PlayCraftEffect( m_From );
				}
				else
				{
					m_From.EndAction( typeof( CraftSystem ) );

					int badCraft = m_CraftSystem.CanCraft( m_From, m_Tool, m_CraftItem.m_Type );

					if ( badCraft > 0 )
					{
						if ( m_Tool != null && !m_Tool.Deleted && m_Tool.UsesRemaining > 0 )
							m_From.SendGump( new CraftGump( m_From, m_CraftSystem, m_Tool, badCraft ) );
						else
							m_From.SendLocalizedMessage( badCraft );

						return;
					}

					int quality = 1;
					bool allRequiredSkills = true;

					m_CraftItem.CheckSkills( m_From, m_TypeRes, m_CraftSystem, ref quality, ref allRequiredSkills, false );

					CraftContext context = m_CraftSystem.GetContext( m_From );

					if ( context == null )
						return;

					bool makersMark = false;

					if ( quality == 2 && m_From.Skills[m_CraftSystem.MainSkill].Base >= 100.0 )
					{
						for ( int i = 0; !makersMark && i < m_MarkableTypes.Length; ++i )
							makersMark = ( m_MarkableTypes[i].IsAssignableFrom( m_CraftItem.ItemType ) );
						
						bool isValid = true;
						if ( (name = m_CraftItem.Name) == null )
						{
							m_From.SendMessage( "Enter the name you wish to call this item" );
							m_from.Prompt = new NameChangePrompt(from, m_CraftItem);
						}
					}					
					
					if ( makersMark && context.MarkOption == CraftMarkOption.PromptForMark )
					{
						m_From.SendGump( new QueryMakersMarkGump( quality, m_From, m_CraftItem, m_CraftSystem, m_TypeRes, m_Tool ) );
						
						bool isValid = true;
						if ( (name = m_CraftItem.Name) == null )
						{
							m_From.SendMessage( "Enter the name you wish to call this item" );
						
						}
					}
					else
					{
						if ( context.MarkOption == CraftMarkOption.DoNotMark )
							makersMark = false;

						m_CraftItem.CompleteCraft( quality, makersMark, m_From, m_CraftSystem, m_TypeRes, m_Tool );
					}
				}
			}
			public class NameChangePrompt : Prompt
			{
				private Item m_Item;
				public NameChangePrompt( Mobile from, Item item )
				{
					m_Item = item;
					from.SendMessage("What would you like to change your name to (2-16 characters)?");
				}

				public override void OnResponse( Mobile from, string text )
				{

					text = text.Trim();
					if (!NameVerification.Validate( text, 2, 16, true, false, true, 1, NameVerification.SpaceDashPeriodQuote ))
						from.SendLocalizedMessage( "Names must contain 2-16 alphabetic characters." );
					else
					{
						from.Name = text;
						m_Item.Delete();
					}
				}
			}
		}
	}
}
dont know if it will work or not but my bracket errors are gone.
FrostBarge is offline   Reply With Quote
Old 10-19-2005, 12:59 PM   #8 (permalink)
 
Join Date: Aug 2004
Age: 30
Posts: 546
Default

Thank you, easy fix i know, but it saved me alot of time. I highly suggest if you enjoy writing scripts dont get a 2nd job, it really cuts into the time you have to code
Memnoch is offline   Reply With Quote
Old 10-20-2005, 12:54 PM   #9 (permalink)
 
Join Date: Aug 2004
Age: 30
Posts: 546
Default

Yes, all bracket issues are fixed, however i now have the fun of finding out how many errors i have created in editing and adding to the script So far most look like easy fixes, just didnt have the time to sit down and make the changes lastnight. Thx again for your help
Memnoch is offline   Reply With Quote