#include "../netwaker_member/NetWakerClientInc.h"
#include "../../mainproc/GameMain.h"
#include "ItemClipboard.h"

CItemClipboard*				g_pItemClipboard	= NULL;

// ----------------------------------------------------------------------------
CItemClipboard::CItemClipboard(CInterface* object)
: CInterfaceBase(object)
{
	m_frame				= NULL;	

	Clear();

	g_pItemClipboard	= this;
}

// ----------------------------------------------------------------------------
CItemClipboard::~CItemClipboard()
{
	g_pItemClipboard	= NULL;
}

// ----------------------------------------------------------------------------
void CItemClipboard::RegisterFunc()
{
	lua_State* L = GetLuaStateWorld();
	if (L)
	{
	}
}

// ----------------------------------------------------------------------------
void CItemClipboard::Update(float elapsedTime)
{
	RoleDataEx* role = CNetGlobal::RoleData();
	ItemFieldStruct* item = NULL;

	switch(m_type)
	{
	case eItem_Type_Bag:
		if ( (item = role->GetBodyItem(m_bag.pos)) != NULL )
			item->Pos = EM_ItemState_CliDisabled;
		break;

	case eItem_Type_Bank:
		break;

	case eItem_Type_Equipment:
		if ( (item = role->GetEqItem(m_equipment.pos)) != NULL )
			item->Pos = EM_ItemState_CliDisabled;
		break;

	case eItem_Type_Trade:
		break;
	case eItem_Type_Action:
		break;
	case eItem_Type_Shop:
		break;
	case eItem_Type_Skill:
		break;
	}
}

// ----------------------------------------------------------------------------
void CItemClipboard::Clear()
{
	if (m_frame)
		m_frame->UnlockedItem();

	m_frame		= NULL;
	m_type		= eItem_Type_None;	
	m_file.clear();
	m_name.clear();	
}

// ----------------------------------------------------------------------------
void CItemClipboard::SetName(const char* name)
{
	m_name.clear();
	if ( name )
		m_name = name;
}

// ----------------------------------------------------------------------------
void CItemClipboard::SetFile(const char* file)
{
	m_file.clear();
	if ( file )
		m_file = file;
}

// ----------------------------------------------------------------------------
void CItemClipboard::PickupBag(CInterfaceBase* frame, int itemID, int pos)
{
	m_type				= eItem_Type_Bag;
	m_frame				= frame;
	m_bag.itemID		= itemID;
	m_bag.pos			= pos;
}

// ----------------------------------------------------------------------------
void CItemClipboard::PickupBank(CInterfaceBase* frame, int itemID, int pos)
{
	m_type				= eItem_Type_Bank;
	m_frame				= frame;
	m_bank.itemID		= itemID;
	m_bank.pos			= pos;
}

// ----------------------------------------------------------------------------
void CItemClipboard::PickupEquipment(CInterfaceBase* frame, int itemID, int pos)
{
	m_type				= eItem_Type_Equipment;
	m_frame				= frame;
	m_equipment.itemID	= itemID;
	m_equipment.pos		= pos;
}

// ----------------------------------------------------------------------------
void CItemClipboard::PickupAction(CInterfaceBase* frame, int actionType, int id, int level)
{
	m_type				= eItem_Type_Action;
	m_frame				= frame;
	m_action.type		= actionType;
	m_action.id			= id;
	m_action.level		= level;
}

// ----------------------------------------------------------------------------
void CItemClipboard::PickupTrade(CInterfaceBase* frame, int tradeType, int pos, int id)
{
	m_type				= eItem_Type_Trade;
	m_frame				= frame;
	m_trade.type		= tradeType;
	m_trade.pos			= pos;
	m_trade.id			= id;
}

// ----------------------------------------------------------------------------
void CItemClipboard::PickupShop(CInterfaceBase* frame, int shopType, int pos)
{
	m_type				= eItem_Type_Shop;
	m_frame				= frame;
	m_shop.type			= shopType;
	m_shop.pos			= pos;
}

// ----------------------------------------------------------------------------
void CItemClipboard::PickupMacro(CInterfaceBase* frame, int id)
{
	m_type				= eItem_Type_Macro;
	m_frame				= frame;
	m_macro.id			= id;
}

// ----------------------------------------------------------------------------
void CItemClipboard::PickupSkill(CInterfaceBase* frame, int id, int level )
{	
	m_type				= eItem_Type_Skill;
	m_frame				= frame;
	m_skill.id			= id;
	m_skill.level		= level;
}