/**********************************************************
RunUO AoV C# script file
Official Age of Valor Script :: www.uovalor.com
Last modified by Red Squirrel on Jan-01-2012 10:09:16pm
Filepath: scripts\Misc\ObjectConverter.cs
Lines of code: 89

Description: 

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


using System;
using Server.Mobiles;
using Server.Items;
using Server.Regions;
using Server.Multis;

namespace Server.Misc
{
	public static class ObjectConverter
	{
	
		//These functions are used to convert an item to another type.  This can be used to do global artifact exchanges, for example.
	
	
		public static void ConvertItem(Item src,Item dest,bool keephue)
		{
			Debugger.Write("convertitem","Converting {0} to {1}",src,dest);
			
			//set all parameters:			
			
			dest.MoveToWorld(src.Location,src.Map);
			dest.Amount = src.Amount;			
			dest.Movable = src.Movable;
			dest.Visible = src.Visible;
			dest.Direction = src.Direction;
			dest.Insured = src.Insured;	
			
			if(src.LootType == LootType.Blessed)dest.LootType=LootType.Blessed;						
			if(keephue)dest.Hue = src.Hue;
			
			
			
			if(src.Parent is Mobile)//if the item is on a mobile, just put it in it's backpack
			{
				Mobile m = src.Parent as Mobile;
				
				if(m.Backpack!=null)
				{
					m.Backpack.DropItem(dest);
				}
				else //hopefully this never happens, but as a failsafe, put it at their feet... either way it's probalby lost
				{
					dest.Parent=null;
					dest.MoveToWorld(m.Location,m.Map);
				}
			
			}
			else if(src.Parent is VendorBackpack)
			{
				VendorBackpack bp = src.Parent as VendorBackpack;
				if(bp.Parent is PlayerVendor)
				{
					PlayerVendor vendor = bp.Parent as PlayerVendor;
					vendor.Owner.BankBox.DropItem(dest);				
				}
				else
				{
					bp.DropItem(dest);
				}
			}
			else if(src.Parent is Container)
			{
				Container cont = src.Parent as Container;
				
				cont.DropItem(dest);
			}
			else 
			{
				dest.Parent=src.Parent;
			}
			
			
			//if it's a container ensure we dump the contents to the new one!
			if(src is Container)
			{				
				Container cont = src as Container;
				
				if(dest is Container)
				{				
					cont.MoveItemsToOtherContainer((Container)dest);
				}
				else
				{
					Bag bag = new Bag();
					bag.DropItem(dest);
					ConvertItem(src,bag);
				}
			}
			
			
			//Do region check to see see if this item is on a house, if yes we need to ensure it is in the lock down list:

		
			Region reg = Region.Find( src.GetWorldLocation(), src.Map );
			
			if (reg is HouseRegion)
			{
				BaseHouse house = ((HouseRegion)reg).House;				
				
				if(house!=null)
				{
					if(house.IsLockedDown( src ))
					{					
						house.SetLockdown( dest, true );
					}
				}			
			
			}
		
		
			//finally, put source item in the delete queue to be deleted later
			src.Delete();
		}
		
		
		public static void ConvertItem(Item src,Item dest)
		{
			ConvertItem(src,dest, true);
		}
		
		
		/*
		public static void ConvertMobile(Mobile src, Mobile dest)
		{
			dest.MoveToWorld(src.Location,src.Map);
			
			
			//check if tamed, if yes ensure owner and stuff is set properly, and also the name:
			
			if(src.Tamed)
			{
			
			
			
			}
		
		
		
		
		
		}*/
	
	
	}












}