/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on May-15-2012 07:15:30pm
Filepath: scripts\Engines\donation\DonationItem.cs
Lines of code: 89

Description: 

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


using Server.Items;
using System;
using System.Collections;
using System.Collections.Generic;
using Server;
using Server.Mobiles;
using Server.Prompts;
using Server.Items;
using Server.Gumps;
using Server.Accounting;

namespace Server.DonationSystem
{
	public class DonationItem
	{
		private string m_name;		//name of item
		private Type m_type;			//type of item
		private int m_price;			//price of item
		private int m_itemid=0x232a;	//item ID on gump
		private int m_hue=0;			//hue on gump
		private int m_amount=1;		//amount to give
		
		
		public string Name { get {return m_name; } }
		public Type Type { get {return m_type; } }
		public int Price { get {return m_price; } }
		public int ItemID { get {return m_itemid; } }
		public int Hue { get {return m_hue; } }
		public int Amount { get {return m_amount; } }		
		
	
		public DonationItem(string name, Type type,int price,int itemid,int hue,int amount)
		{
			m_name=name;
			m_type=type;
			m_price=price;
			m_itemid=itemid;
			m_hue=hue;
			m_amount=amount;
		}
	
	
		public DonationItem(string name, Type type,int price,int itemid,int hue) : this(name,type,price,itemid,hue,1)
		{
		}
	
		public DonationItem(string name, Type type,int price,int itemid) : this(name,type,price,itemid,0,1)
		{
		}
	
	
		public void TryGiveItem(Mobile to)
		{
			if(to.Account==null || !(to.Account is Account))return;
			
			if(DonationHandler.GetPoints(to)<m_price)
			{
				to.SendMessage("Sorry, you do not have enough points for this item");
				return;
			}
			
			
			
			Item item = null;
			
			try
			{
				item = Activator.CreateInstance(m_type) as Item;
			}
			catch
			{
				to.SendMessage("Error creating item");
				return;
			}

			
			//deduct points:			
			((Account)to.Account).DonationPoints-=m_price;
			
			//Handle special cases:
			//-------------------
			
			if(item is EtherealMount)
			{
				((EtherealMount)item).IsDonationItem=true;			
			}
			else if(item is BankCheck)
			{
				((BankCheck)item).Worth=m_amount;			
			}
			else if(item is skilldeed)
			{
				((skilldeed)item).SkillBonus=m_amount;			
			}
			else if(item is GargoylesPickaxe)
			{
				((GargoylesPickaxe)item).UsesRemaining=m_amount;		
			}
			else if(item is ReapersAxe)
			{
				((ReapersAxe)item).UsesRemaining=m_amount;		
			}			
			else
			{						
				item.Amount=m_amount;
			}
			
			
			
			//-------------------
			
			//finally, give item:
			
			to.GiveItem(item);
			to.SendMessage(200,"You are given: {0}",m_name);
		}
	}
}