using System; using System.Collections; namespace Server.Items { public enum CraftResource { None = 0, Iron = 1, Leathered = 2, Wooden = 3 } public enum CraftResourceType { None, Metal, Leather, Wood } public class CraftAttributeInfo { private int m_WeaponDurability; private int m_WeaponLowerRequirements; private int m_ArmorDurability; private int m_ArmorLowerRequirements; public int WeaponDurability{ get{ return m_WeaponDurability; } set{ m_WeaponDurability = value; } } public int WeaponLowerRequirements{ get{ return m_WeaponLowerRequirements; } set{ m_WeaponLowerRequirements = value; } } public int ArmorDurability{ get{ return m_ArmorDurability; } set{ m_ArmorDurability = value; } } public int ArmorLowerRequirements{ get{ return m_ArmorLowerRequirements; } set{ m_ArmorLowerRequirements = value; } } public CraftAttributeInfo() { } public static readonly CraftAttributeInfo Blank; static CraftAttributeInfo() { Blank = new CraftAttributeInfo(); } } public class CraftResourceInfo { private int m_Hue; private int m_Number; private string m_Name; private CraftAttributeInfo m_AttributeInfo; private CraftResource m_Resource; private Type[] m_ResourceTypes; public int Hue{ get{ return m_Hue; } } public int Number{ get{ return m_Number; } } public string Name{ get{ return m_Name; } } public CraftAttributeInfo AttributeInfo{ get{ return m_AttributeInfo; } } public CraftResource Resource{ get{ return m_Resource; } } public Type[] ResourceTypes{ get{ return m_ResourceTypes; } } public CraftResourceInfo( int hue, int number, string name, CraftAttributeInfo attributeInfo, CraftResource resource, params Type[] resourceTypes ) { m_Hue = hue; m_Number = number; m_Name = name; m_AttributeInfo = attributeInfo; m_Resource = resource; m_ResourceTypes = resourceTypes; for ( int i = 0; i < resourceTypes.Length; ++i ) CraftResources.RegisterType( resourceTypes[i], resource ); } } public class CraftResources { private static CraftResourceInfo[] m_MetalInfo = new CraftResourceInfo[] { new CraftResourceInfo( 0x000, 1053109, "Iron", CraftAttributeInfo.Blank, CraftResource.Iron, typeof( IronIngot ), typeof( IronOre ) ) }; private static CraftResourceInfo[] m_LeatherInfo = new CraftResourceInfo[] { new CraftResourceInfo( 0x000, 1049353, "Leather", CraftAttributeInfo.Blank, CraftResource.Leathered, typeof( Leather ), typeof( Hides ) ) }; private static CraftResourceInfo[] m_WoodInfo = new CraftResourceInfo[] { new CraftResourceInfo( 0x000, 1011542, "Wood", CraftAttributeInfo.Blank, CraftResource.Wooden, typeof( WoodBoard ), typeof( WoodBoard ) ) }; /// /// Returns true if '' is None, Iron, Leathered or Wooden. False if otherwise. /// public static bool IsStandard( CraftResource resource ) { return ( resource == CraftResource.None || resource == CraftResource.Iron || resource == CraftResource.Leathered || resource == CraftResource.Wooden ); } private static Hashtable m_TypeTable; /// /// Registers that '' uses '' so that it can later be queried by /// public static void RegisterType( Type resourceType, CraftResource resource ) { if ( m_TypeTable == null ) m_TypeTable = new Hashtable(); m_TypeTable[resourceType] = resource; } /// /// Returns the value for which '' uses -or- CraftResource.None if an unregistered type was specified. /// public static CraftResource GetFromType( Type resourceType ) { if ( m_TypeTable == null ) return CraftResource.None; object obj = m_TypeTable[resourceType]; if ( !(obj is CraftResource) ) return CraftResource.None; return (CraftResource)obj; } /// /// Returns a instance describing '' -or- null if an invalid resource was specified. /// public static CraftResourceInfo GetInfo( CraftResource resource ) { CraftResourceInfo[] list = null; switch ( GetType( resource ) ) { case CraftResourceType.Metal: list = m_MetalInfo; break; case CraftResourceType.Leather: list = m_LeatherInfo; break; case CraftResourceType.Wood: list = m_WoodInfo; break; } if ( list != null ) { int index = GetIndex( resource ); if ( index >= 0 && index < list.Length ) return list[index]; } return null; } /// /// Returns a value indiciating the type of ''. /// public static CraftResourceType GetType( CraftResource resource ) { if ( resource == CraftResource.Iron ) return CraftResourceType.Metal; if ( resource == CraftResource.Leathered ) return CraftResourceType.Leather; if ( resource == CraftResource.Wooden ) return CraftResourceType.Wood; return CraftResourceType.None; } /// /// Returns the first in the series of resources for which '' belongs. /// public static CraftResource GetStart( CraftResource resource ) { switch ( GetType( resource ) ) { case CraftResourceType.Metal: return CraftResource.Iron; case CraftResourceType.Leather: return CraftResource.Leathered; case CraftResourceType.Wood: return CraftResource.Wooden; } return CraftResource.None; } /// /// Returns the index of '' in the seriest of resources for which it belongs. /// public static int GetIndex( CraftResource resource ) { CraftResource start = GetStart( resource ); if ( start == CraftResource.None ) return 0; return (int)(resource - start); } /// /// Returns the property of '' -or- 0 if an invalid resource was specified. /// public static int GetLocalizationNumber( CraftResource resource ) { CraftResourceInfo info = GetInfo( resource ); return ( info == null ? 0 : info.Number ); } /// /// Returns the property of '' -or- 0 if an invalid resource was specified. /// public static int GetHue( CraftResource resource ) { CraftResourceInfo info = GetInfo( resource ); return ( info == null ? 0 : info.Hue ); } /// /// Returns the property of '' -or- an empty string if the resource specified was invalid. /// public static string GetName( CraftResource resource ) { CraftResourceInfo info = GetInfo( resource ); return ( info == null ? String.Empty : info.Name ); } /// /// Returns the value which represents '' -or- CraftResource.None if unable to convert. /// public static CraftResource GetFromOreInfo( OreInfo info ) { if ( info.Name.IndexOf( "Wood" ) >= 0 ) return CraftResource.Wooden; else if ( info.Name.IndexOf( "Leather" ) >= 0 ) return CraftResource.Leathered; else if ( info.Name.IndexOf( "Iron" ) >= 0 ) return CraftResource.Iron; return CraftResource.None; } /// /// Returns the value which represents '', using '' to help resolve leather OreInfo instances. /// public static CraftResource GetFromOreInfo( OreInfo info, ArmorMaterialType material ) { if ( material == ArmorMaterialType.Studded || material == ArmorMaterialType.Leather ) { return CraftResource.Leathered; } return GetFromOreInfo( info ); } } // NOTE: This class is only for compatability with very old RunUO versions. // No changes to it should be required for custom resources. public class OreInfo { public static readonly OreInfo Iron = new OreInfo( 0, 0x000, "Iron" ); private int m_Level; private int m_Hue; private string m_Name; public OreInfo( int level, int hue, string name ) { m_Level = level; m_Hue = hue; m_Name = name; } public int Level { get { return m_Level; } } public int Hue { get { return m_Hue; } } public string Name { get { return m_Name; } } } }