/**********************************************************
RunUO 2.0 AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by 
Filepath: scripts\Misc\ShrinkTable.cs
Lines of code: 67
***********************************************************/


using System;
using System.IO;
using System.Collections;

namespace Server
{
	public class ShrinkTable
	{
		public const int DefaultItemID = 0x1870; // Yellow virtue stone

		private static Hashtable m_Table;

		public static int Lookup( Mobile m )
		{
			return Lookup( m.Body.BodyID, DefaultItemID );
		}

		public static int Lookup( int body )
		{
			return Lookup( body, DefaultItemID );
		}

		public static int Lookup( Mobile m, int defaultValue )
		{
			return Lookup( m.Body.BodyID, defaultValue );
		}

		public static int Lookup( int body, int defaultValue )
		{
			if ( m_Table == null )
				Load();
				
			int val = 0;

			if ( body >= 0 && m_Table.Contains(body))
				val = (int)m_Table[body];

			if ( val == 0 )
				val = defaultValue;
				
			return val;
		}

		private static void Load()
		{
			string path = Path.Combine( Core.BaseDirectory, "Data/shrink.cfg" );

			m_Table = new Hashtable();
			
			if ( !File.Exists( path ) )
			{
				return;
			}


			using ( StreamReader ip = new StreamReader( path ) )
			{
				string line;

				while ( (line = ip.ReadLine()) != null )
				{
					line = line.Trim();

					if ( line.Length == 0 || line.StartsWith( "#" ) )
						continue;

					try
					{
						string[] split = line.Split( '\t' );

						if ( split.Length >= 2 )
						{
							int body = Utility.ToInt32( split[0] );
							int item = Utility.ToInt32( split[1] );

							if ( body >= 0 )
								m_Table[body] = (int)item;
						}
					}
					catch
					{
					}
				}
			}
		}
	}
}