#include "stdafx.h"
#include "DragWindow.h"

#include "ItemIcon.h"
#include "SkillIcon.h"

#include "UIRootNode.h"
#include "ItemManager.h"
#include "GameUIManager.h"
#include "QuickManager.h"
#include "ObjectManager.h"
#include "hero.h"
#include "ChatManager.h"
#include "GameResourceManager.h"
#include "NpcDisjointWindow.h"
#include "EnhancedWindow.h"
#include "TradeWindow.h"
#include "UserSellWindow.h"
#include "UIMsgboxEvent.h"
#include "WareHouseWindow.h"
#include "PutCardWindow.h"
#include "CardBookWindow.h"
#include "TarotSheetWindow.h"
#include "ChatWindow.h"

cDragWindow::cDragWindow( eUINodeType type )
: cUIWindow( type )
, mpCaller(0)
, mShowIcon(0)
, mIconType(eICON_NULL)
{
}

cDragWindow::~cDragWindow()
{
}

void cDragWindow::Show( cUIWindow* pCaller, eDragFrom dragFrom, cIcon* icon, unsigned int iconType, const cUIPos& pos, bool shift )
{
	assert( icon );
	assert( iconType < eICON_MAX );

	mIconFrom = icon;
	mIconType = iconType;

	mShowIcon->ChangeImage( icon->GetIconParam() );
	mShowIcon->ShowNumber( false );
	mShowIcon->Show();

	switch( mIconType )
	{
	case eICON_NORMAL:
		QUICKMAN->DragIcon( mIconFrom );
		break;
	case eICON_ITEM:
		ITEMMAN->LinkIcon( (cItemIcon*)mIconFrom );
		break;
	}

	mpCaller = pCaller;
	mShiftDown = shift;
	mDragFrom = dragFrom;

	/// 드래그윈도우 위치 선정
	cUIPos newPos( (int)(pos.mX - GetAbsoluteRect().GetWidth() * 0.5), (int)(pos.mY - GetAbsoluteRect().GetHeight() * 0.5) );
	SetRelativePos( newPos );
	ShowModal( eMBEVENT_NONE );
	SetCapture();
}

/// 외부에서 닫힘.
void cDragWindow::Hide( bool onsound )
{
	cUIWindow::Hide( onsound );
	mpCaller = 0;

	ITEMMAN->UnLinkIcon( true );
	QUICKMAN->UnDragIcon();

	mIconFrom = 0;
	mIconType = eICON_NULL;
}

void cDragWindow::Hide( cUIWindow* pCaller )
{
	/// 자기를 호출한 콜러가 아니면 무반응
	if( pCaller == mpCaller )
		Hide();
}	

bool cDragWindow::OnCreate( cUINodeProperty* )
{
	mShowIcon = new cIcon;
	if( mShowIcon->CreateBySkinName( "Drag_Icon", this, 1 ) == false )
		return false;

	Hide( false );
	return true;
}

void cDragWindow::OnMouseMove( const cUIPos& pos )
{
	cUIPos newPos( (int)(pos.mX - GetAbsoluteRect().GetWidth() * 0.5), (int)(pos.mY - GetAbsoluteRect().GetHeight() * 0.5) );
	SetRelativePos( newPos );
}

void cDragWindow::OnLButtonUp( const cUIPos& pos )
{
	/// 윈도우 숨기기
	cUIWindow::Hide();
	mpCaller = 0;

	/// 죽어있는데 아이템을 드래그하면 실패처리
	if( HERO->GetState() == eOBJECT_STATE_DIE )
	{
		CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 235 ) );
	}

	bool setColor = true;
	switch( mDragFrom )
	{
	case DRAG_FROM_INVENTORY:
		if( OnDragFromInventory( pos ) == true )
			setColor = false;
		break;
	case DRAG_FROM_NPC_STORE:
		OnDragFromNpcStore( pos );
		break;
	case DRAG_FROM_QUICKSLOT:
		OnDragFromQuickSlot( pos );
		break;
	case DRAG_FROM_TRADE:
		OnDragFromTradeWindow( pos );
		break;
	case DRAG_FROM_USERSELL:
		OnDragFromUserSellWindow( pos );
		break;
	case DRAG_FROM_CHATLINK:
		OnDragFromChatWindow( pos );
		break;
	case DRAG_FROM_SKILLWINDOW:
		OnDragFromSkillWindow( pos );
		break;
	case DRAG_FROM_COMMUNITYWINDOW:
		OnDragFromCommunityWindow( pos );
		break;
	}

	ITEMMAN->UnLinkIcon( setColor );
	QUICKMAN->UnDragIcon();
}

/// 인벤토리 -> 외부 
bool cDragWindow::OnDragFromInventory( const cUIPos& pos )
{
	cUINode* node = GetRoot()->GetNode( pos );
	if( !node )
		return false;

	if( mIconType != eICON_ITEM )
		return false;

	cItemIcon* itemIcon = (cItemIcon*)mIconFrom;
	if( itemIcon == 0 )
		return false;

	/// 쓰레기통에 대한 처리 
	if( node->GetID() == eUIID_INVENTORY_GARBAGE || 
		node->GetID() == eUIID_WAREHOUSE_TRASH ||
		node->GetID() == eUIID_WAREHOUSE2_TRASH ||
		node->GetID() == eUIID_BAG0_TRASH ||
		node->GetID() == eUIID_BAG1_TRASH ||
		node->GetID() == eUIID_BAG2_TRASH )
	{
		unsigned int slotIndex0 = itemIcon->GetSlotIndex();
		eItemIn in = ITEMMAN->GetItemIn( slotIndex0 );

		/// 장비창에 있는것은 버릴수 없다.
		if( in != ITEM_IN_EQUIP )
			GAMEUI->ShowItemDumpAskWindow( itemIcon->GetSlotIndex() );
		return false;
	}

	/// 가져온 인벤 슬롯 정보
	unsigned int slotIndex0 = itemIcon->GetSlotIndex();
	eItemIn in = ITEMMAN->GetItemIn( slotIndex0 );
	assert( in != ITEM_IN_NULL );

	/// npc 상점과 상점영역 체크 
	cUIWindow* store = (cUIWindow*)GAMEUI->GetNpcStore();
	if( store && (node == (cUIContainer*)store || node->GetParent() == (cUIContainer*)store) )
	{
		if( in != ITEM_IN_INVEN_PRIVATE )
			return false;

		DragToNpcStore();
		return false;
	}

	/// 판매노점 체크
	cUserSellWindow* userSell = GAMEUI->GetUserSellWindow();
	if( userSell && (node == (cUIContainer*)userSell || node->GetParent() == (cUIContainer*)userSell) )
	{
		if( in != ITEM_IN_INVEN_PRIVATE )
			return false;

		if( userSell->GetStatus() == eUSERSELL_JOIN )
			return false;

		if( userSell->IsNetLock() == true )
			return false;

		if( userSell->IsOpen() == false )
		{
			CHATMANAGER->AddSystemMsg( eSYSTEM_NORMAL, GAMERESOURCEMAN->GetGameText( 2509 ) );
		}
		else
		{
			GAMEUI->ShowMoneyWindow( eMONEY_NONE, eMBEVENT_USERSELL_ITEMMONEYADD, slotIndex0 );
		}
		return false;
	}

	/// 채팅윈도우 체크
	cChatWindow* chatWin = GAMEUI->GetChatWindow();
	if( chatWin && (node == (cUIContainer*)chatWin || node->GetParent() == (cUIContainer*)chatWin) )
	{
		if( in != ITEM_IN_INVEN_PRIVATE )
			return false;

		return chatWin->AddLinkItem( slotIndex0 );
	}

	/// 거래 체크
	cTradeWindow* trade = GAMEUI->GetTradeWindow();
	if( trade && (node == (cUIContainer*)trade || node->GetParent() == (cUIContainer*)trade) )
	{
		if( in != ITEM_IN_INVEN_PRIVATE )
			return false;

		if( trade->IsNetLock() == true )
			return false;

		ITEMMAN->TryToTradeItemAdd( slotIndex0 );
		return false;
	}

	/// 카드컬렉션북 체크
	cCardBookWindow* cardBook = GAMEUI->GetCardBookWindow();
	if( cardBook && (node == (cUIContainer*)cardBook || node->GetParent() == (cUIContainer*)cardBook) )
	{
		if( in != ITEM_IN_INVEN_PRIVATE )
			return false;

		/// 락 검사
		/*if( cardBook->IsNetLock() == true )
		return false;*/

		cItem& item0 = ITEMMAN->GetItem( slotIndex0 );
		cItemDefine* define = ITEMMAN->GetItemDefine( item0.GetIndex() );
		if( !define )
			return false;

		unsigned char type = define->GetType();
		unsigned char subtype = define->GetSubType();

		/// 현재 컬렉션북 페이지 검사
		switch( cardBook->GetCurrentPage() )
		{
		case ePAGE_DATA:
			break;
		case ePAGE_TAROT:	/// 타롯 페이지
			if( type == ITEM_CARD && subtype == ITEM_CARD_TAROT )
			{
				/// 타롯 카드인경우,
				cItemTarot* tarot = define->GetTarotDefine();
				if( !tarot )
					return false;
				
				cTarotSheetWindow* sheet = cardBook->GetTarotSheet();
				if( !sheet )
					return false;

				unsigned long registItemIdx = sheet->IsRegistItem( tarot->GetUniqueNumber() );
				unsigned int bookslotIndex = sheet->GetSlotIndex( tarot->GetUniqueNumber() );
				if( !(registItemIdx == ULONG_MAX || bookslotIndex == ULONG_MAX) )
				{
					eMSGBox_Event event = (registItemIdx == 0)? eMBEVENT_ITEM_CARDBOOK_TAROTNEW : eMBEVENT_ITEM_CARDBOOK_TAROTUPDATE;
					GAMEUI->ShowItemCardBook( event, slotIndex0, bookslotIndex, registItemIdx );
				}
			}
			else if( type == ITEM_SPREAD )
			{
				/// 스프레드인경우,
				cTarotSheetWindow* sheet = cardBook->GetTarotSheet();
				if( !sheet )
					return false;

				/// 
				unsigned int emptyItemSlot = sheet->GetEmptySlotIndex();
				unsigned long registItemIdx = sheet->IsRegistItem( emptyItemSlot - INVENTORY_TAROT_BEGIN );
				if( !(registItemIdx == ULONG_MAX ) )
				{
					eMSGBox_Event event = (registItemIdx == 0)? eMBEVENT_ITEM_CARDBOOK_SPREADNEW : eMBEVENT_ITEM_CARDBOOK_SPREADUPDATE;
					GAMEUI->ShowItemCardBook( event, slotIndex0, emptyItemSlot, registItemIdx );
				}
			}
			break;
		case ePAGE_MONSTER:
			break;
		case ePAGE_STORY:
			break;
		default:
			assert(0);
			break;
		}

		return false;
	}

	/// 아이콘 체크
	if( node->IsKindof(eUINODE_ICON) )
	{
		cIcon* icon = (cIcon*)node;
		
		/// 퀵슬롯 처리
		cUIContainer* con = node->GetParent();
		if( con && (con->GetID() == eUIID_ROW_QUICKSLOT || con->GetID() == eUIID_COLUMN_QUICKSLOT ||
			        con->GetID() == eUIID_ROW_QUICKSLOT_FS || con->GetID() == eUIID_COLUMN_QUICKSLOT_FS ) )
		{
			if( in != ITEM_IN_INVEN_PRIVATE )
				return false;

			if( DragToQuickSlot( DRAG_FROM_INVENTORY, icon ) == false )
				return false;
		}

		/// 아이템 처리
		if( icon->GetIconType() == eICON_ITEM )
		{
			if( DragToItemSlot( icon ) == true )
				return true;
		}
	}
	return false;
}

/// 스킬창 -> 외부
void cDragWindow::OnDragFromSkillWindow( const cUIPos& pos )
{
	cUINode* node = GetRoot()->GetNode( pos );

	if( node && node->IsKindof(eUINODE_ICON) )
	{
		cIcon* icon = (cIcon*)node;
		if( icon->GetIconType() == eICON_NORMAL )
		{
			/// 퀵슬롯 처리
			DragToQuickSlot( DRAG_FROM_SKILLWINDOW, icon );
		}
	}
}

void cDragWindow::OnDragFromCommunityWindow( const cUIPos& pos )
{
	cUINode* node = GetRoot()->GetNode( pos );

	if( node && node->IsKindof(eUINODE_ICON) )
	{
		cIcon* icon = (cIcon*)node;
		if( icon->GetIconType() == eICON_NORMAL )
		{
			/// 퀵슬롯 처리
			DragToQuickSlot( DRAG_FROM_COMMUNITYWINDOW, icon );
		}
	}
}

///  npc 상점 -> inven 
void cDragWindow::OnDragFromNpcStore( const cUIPos& pos )
{
	cUINode* node = GetRoot()->GetNode( pos );

	if( mIconType != eICON_ITEM )
		return;

	cItemIcon* itemIcon = (cItemIcon*)mIconFrom;
	if( itemIcon == 0 )
		return;

	if( node && node->IsKindof(eUINODE_ICON) )
	{
		cItemIcon* icon = (cItemIcon*)node;

		unsigned int slotIndex = icon->GetSlotIndex();
		eItemIn in = ITEMMAN->GetItemIn( slotIndex );

		/// Npc 상점 -> 인벤 개인
		if( in == ITEM_IN_INVEN_PRIVATE )
		{
			unsigned int itemIndex = itemIcon->GetItemIndex();
			assert( itemIndex );

			cItemDefine* itemDefine = ITEMMAN->GetItemDefine( itemIndex );
			assert( itemDefine );

			/// 1개라도 살수 있어야 구입가능
			if( ITEMMAN->CheckBuyItem( itemIndex, 1 ) == false )
				return;

			if( itemDefine->GetCapacity() == 1 )
			{
				GAMEUI->ShowItemBuyAskWindow( itemIndex, 1 );
			}
			else
			{
				GAMEUI->ShowItemCountWindow( eMBEVENT_ITEMCOUNT_BUY, itemIndex );
			}
		}
	}
}

///
void cDragWindow::OnDragFromQuickSlot( const cUIPos& pos )
{
	cUINode* node = GetRoot()->GetNode( pos );

	if( !node )
		return;

	if( node->IsKindof(eUINODE_ICON) )
	{
		cIcon* icon = (cIcon*)node;
		if( icon->GetIconType() == eICON_NORMAL )
		{
			/// 퀵슬롯 처리
			DragToQuickSlot( DRAG_FROM_QUICKSLOT, icon );
		}
	}
	else
	{
		QUICKMAN->DeleteData();
	}
}

void cDragWindow::OnDragFromTradeWindow( const cUIPos& pos )
{
	cUINode* node = GetRoot()->GetNode( pos );
	if( !node )
		return;

	if( mIconType != eICON_ITEM )
		return;

	cItemIcon* itemIcon = (cItemIcon*)mIconFrom;
	if( itemIcon == 0 )
		return;

	cTradeWindow* trade = (cTradeWindow*)GAMEUI->GetTradeWindow();
	if( trade )
	{
		if( trade->IsNetLock() == true )
			return;

		if( trade->GetStatus() != ItemExchangeBegin )
			return;

		cUIRect tradeRect = trade->GetAbsoluteRect();
		
		/// 트레이드 윈도우 영역인지 체크
		if( tradeRect.ContainPoint( pos ) == true )
			return;
		
		/// 영역에 없으면 삭제 
		int slot = trade->GetInvenSlot( itemIcon->GetID() );

		/// 인벤 슬롯과, 트레이드 슬롯을 모두 넣는다
		if( slot > -1 && ITEMMAN->TryToTradeItemDelete( slot, itemIcon->GetID() ) == false )
			return;
	}
}

void cDragWindow::OnDragFromChatWindow( const cUIPos& pos )
{
	cUINode* node = GetRoot()->GetNode( pos );
	if( !node )
		return;

	if( mIconType != eICON_ITEM )
		return;

	cItemIcon* itemIcon = (cItemIcon*)mIconFrom;
	if( itemIcon == 0 )
		return;

	cChatWindow* chatWin = (cChatWindow*)GAMEUI->GetChatWindow();
	if( chatWin )
	{
		cUIRect rect = chatWin->GetAbsoluteRect();

		/// 채팅 윈도우 영역인지 체크
		if( rect.ContainPoint( pos ) == false )
		{
			/// 등록 삭제
			chatWin->DeleteLinkItem();
		}
	}
}

void cDragWindow::OnDragFromUserSellWindow( const cUIPos& pos )
{
	cUINode* node = GetRoot()->GetNode( pos );
	if( !node )
		return;

	cUserSellWindow* userSell = (cUserSellWindow*)GAMEUI->GetUserSellWindow();
	if( !userSell )
		return;

	if( userSell->IsNetLock() == true )
		return;

	if( mIconType != eICON_ITEM )
		return;

	cItemIcon* itemIcon = (cItemIcon*)mIconFrom;
	if( itemIcon == 0 )
		return;

	/// 판매 상태
	if( userSell->GetStatus() == eUSERSELL_SELL )
	{
		cUIRect sellRect = userSell->GetAbsoluteRect();

		/// 판매노점상 내부이면 리턴
		if( sellRect.ContainPoint( pos ) == true )
			return;

		/// 영역에 없으면 삭제
		int slot = userSell->GetSelectInvenSlot();

		/// 인벤 슬롯과, 판매노점 슬롯 모두 삽입
		if( slot > -1 && ITEMMAN->TryToUserSellDelete( slot ) == false )
			return;
	}
	/// 구매상태
	else if( userSell->GetStatus() == eUSERSELL_JOIN )
	{
		cUINode* node = GetRoot()->GetNode( pos );

		if( node && node->IsKindof( eUINODE_ICON ) )
		{
			cItemIcon* icon = (cItemIcon*)node;
			eItemIn in = ITEMMAN->GetItemIn( icon->GetSlotIndex() );

			/// 구매창 -> 인벤 개인
			if( in == ITEM_IN_INVEN_PRIVATE )
			{
				sUserSellData* data = userSell->GetSelectJoinData();
				sInventory* inv = &data->mThatInven;

				cItemDefine* itemDefine = ITEMMAN->GetItemDefine( inv->ItemIndex );

				if( itemDefine->GetCapacity() > 1 )
					GAMEUI->ShowItemCountWindow( eMBEVENT_ITEMCOUNT_USERSELLBUY, inv->number, inv->ItemIndex, inv->count );
				else
					GAMEUI->ShowItemUserSellBuyAskWindow( inv->number, inv->ItemIndex, 1, data->mPrice );
			}	
		}
	}
}

/// 퀵슬롯으로 드래그
bool cDragWindow::DragToQuickSlot( eDragFrom dragFrom, cIcon* icon )
{
	cUIContainer* parent = icon->GetParent();
	unsigned int parentID = parent->GetID();

	/// 퀵슬롯 확인검사
	if( parentID != eUIID_COLUMN_QUICKSLOT && parentID != eUIID_ROW_QUICKSLOT &&
		parentID != eUIID_COLUMN_QUICKSLOT_FS && parentID != eUIID_ROW_QUICKSLOT_FS )
		return false;

	if( mIconFrom == 0 )
		return false;

	/// 놓는 위치에 따른 fs 슬롯 판별
	bool toIsFS = ( parentID == eUIID_COLUMN_QUICKSLOT || parentID == eUIID_ROW_QUICKSLOT ) ? false : true;
	
	/// 몬스터 변신상태일때, 몬스터 스킬 슬롯에 등록 불가!! 
	if( toIsFS && HERO->IsTransformMonster() && icon->GetID() < QUICK_COUNT_MON )
		return false;

	/// 퀵슬롯에 등록
	if( dragFrom == DRAG_FROM_QUICKSLOT )
	{
		QUICKMAN->MoveData( icon->GetID(), mShowIcon, toIsFS );
	}
	else
	{
		QUICKMAN->AddData( icon->GetID(), mIconFrom, toIsFS );
	}
	return false;
}

/// 상점 아이콘 부분이 아닌 상점 이벤트 영역으로 드래그할시에 처리.
/// 아이콘 아닌부분도 이벤트 발생 가능하도록 위함
void cDragWindow::DragToNpcStore()
{
	if( mIconType != eICON_ITEM )
		return;

	cItemIcon* itemIcon = (cItemIcon*)mIconFrom;
	if( itemIcon == 0 )
		return;

	unsigned int slotIndex0 = itemIcon->GetSlotIndex();
	eItemIn in = ITEMMAN->GetItemIn( slotIndex0 );

	/// 모든 상황이 일어나면, 링크 아이콘을 원상태로 돌리기 위함
	if( mShiftDown == false )
	{
		/// 인벤 개인 -> Npc 상점
		if( in == ITEM_IN_INVEN_PRIVATE )
		{
			const cItem& item = ITEMMAN->GetItem( slotIndex0 );

			if( item.GetCount() == 0 )
				return;

			if( item.GetCount() == 1 )
			{
				GAMEUI->ShowItemSellAskWindow( slotIndex0, 1 );
			}
			else
			{
				GAMEUI->ShowItemCountWindow( eMBEVENT_ITEMCOUNT_SELL, slotIndex0 );
			}
		}
	}
}

/// 인벤토리 -> NPC상점, 인벤토리, 분해창,...
/// 슬롯 대 슬롯으로 비교해야하는경우 사용 ( 반드시 해당 위치 슬롯을 체크하는경우 )
bool cDragWindow::DragToItemSlot( cIcon* icon )
{
	if( mIconType != eICON_ITEM )
		return false;

	cItemIcon* itemIconFrom = (cItemIcon*)mIconFrom;
	if( itemIconFrom == 0 )
		return false;

	cItemIcon* itemIcon = (cItemIcon*)icon;
	unsigned int slotIndex0 = itemIconFrom->GetSlotIndex();
	unsigned int slotIndex1 = itemIcon->GetSlotIndex();

	if( slotIndex0 == slotIndex1 )
		return false;

	eItemIn in = ITEMMAN->GetItemIn( slotIndex0 );
	eItemIn out = ITEMMAN->GetItemIn( slotIndex1 );

	if( in == ITEM_IN_NULL )
		return false;
	if( out == ITEM_IN_NULL )
		return false;

	cItem& item = ITEMMAN->GetItem( slotIndex0 );

	if( mShiftDown == false )
	{
		/// 인벤 개인 -> Npc 상점
		if( in == ITEM_IN_INVEN_PRIVATE && out == ITEM_IN_NPCSTORE )
		{
			if( item.GetCount() == 0 )
				return false;

			if( item.GetCount() == 1 )
				GAMEUI->ShowItemSellAskWindow( slotIndex0, 1 );
			else
				GAMEUI->ShowItemCountWindow( eMBEVENT_ITEMCOUNT_SELL, slotIndex0 );
			return false;
		}
	}
	else
	{
		/// 인벤 개인 -> 인벤 개인
		/// 인벤 개인 <-> 창고 개인
		if( (in == ITEM_IN_INVEN_PRIVATE && in == out) ||
			(in == ITEM_IN_INVEN_PRIVATE && out == ITEM_IN_WAREHOUSE_PRIVATE) ||
			(in == ITEM_IN_WAREHOUSE_PRIVATE && out == ITEM_IN_INVEN_PRIVATE) )
		{
			GAMEUI->ShowItemCountWindow( eMBEVENT_ITEMCOUNT_SPLIT, slotIndex0, slotIndex1 );
			return false;
		}
	}
	
	/// 인벤 개인 -> 분해 윈도우
	if( in == ITEM_IN_INVEN_PRIVATE && out == ITEM_IN_DISJOINT )
	{
		/// 분해 아이템 등록 
		cNpcDisjointWindow* disjoint = GAMEUI->GetNpcDisjointWindow();
		if( disjoint && disjoint->AddItem( slotIndex0 ) == false )
			return false;
	}
	/// 인벤 개인 -> 강화 아이템 슬롯
	else if( in == ITEM_IN_INVEN_PRIVATE && out == ITEM_IN_ENHANCED_ITEM )
	{
		/// 강화 아이템 등록
		cEnhancedWindow* enhanced = GAMEUI->GetEnhancedWindow();
		if( enhanced && enhanced->AddItem( slotIndex0 ) == false )
			return false;
	}
	/// 인벤 개인 -> 강화 카드 슬롯
	else if( in == ITEM_IN_INVEN_PRIVATE && out == ITEM_IN_ENHANCED_CARD )
	{
		/// 강화 카드 등록
		cEnhancedWindow* enhanced = GAMEUI->GetEnhancedWindow();
		if( enhanced && enhanced->AddCard( slotIndex0 ) == false )
			return false;
	}
	/// 인벤 개인 -> 카드 장착 [아이템] 슬롯
	else if( in == ITEM_IN_INVEN_PRIVATE && out == ITEM_IN_PUTCARD_ITEMSLOT )
	{
		/// 아이템 등록
		cPutCardWindow* putcard = GAMEUI->GetPutCardWindow();
		if( putcard && putcard->AddItem( slotIndex0 ) == false )
			return false;
	}
	/// 인벤 개인 -> 카드 장착 [카드] 슬롯
	else if( in == ITEM_IN_INVEN_PRIVATE && out == ITEM_IN_PUTCARD_CARDSLOT )
	{
		cPutCardWindow* putcard = GAMEUI->GetPutCardWindow();
		if( putcard && putcard->TestAddCard( slotIndex0, slotIndex1 ) == false )
			return false;
	}
	/// 인벤 개인 -> 컬렉션북 [타로카드]슬롯
	else if( in == ITEM_IN_INVEN_PRIVATE && out == ITEM_IN_CARDBOOK_TAROT )
	{
		cItem& item0 = ITEMMAN->GetItem( slotIndex0 );
		cItemDefine* define = ITEMMAN->GetItemDefine( item0.GetIndex() );
		if( !define )
			return false;

		if( !(define->GetType() == ITEM_CARD && define->GetSubType() == ITEM_CARD_TAROT) )
			return false;
		
		/// 타롯 카드인경우,
		cItemTarot* tarot = define->GetTarotDefine();
		if( !tarot )
			return false;

		cCardBookWindow* cardBook = (cCardBookWindow*)GAMEUI->GetCardBookWindow();
		cTarotSheetWindow* sheet = cardBook->GetTarotSheet();
		if( sheet )
		{
			unsigned long registItemIdx = sheet->IsRegistItem( tarot->GetUniqueNumber() );
			unsigned int bookslotIndex = sheet->GetSlotIndex( tarot->GetUniqueNumber() );
			if( !(registItemIdx == ULONG_MAX || bookslotIndex == ULONG_MAX) )
			{
				eMSGBox_Event event = (registItemIdx == 0)? eMBEVENT_ITEM_CARDBOOK_TAROTNEW : eMBEVENT_ITEM_CARDBOOK_TAROTUPDATE;
				GAMEUI->ShowItemCardBook( event, slotIndex0, bookslotIndex, registItemIdx );
			}
		}
		return false;
	}
	/// 인벤 개인 -> 컬렉션북 [스프레드]슬롯
	else if( in == ITEM_IN_INVEN_PRIVATE && out == ITEM_IN_CARDBOOK_SPREAD )
	{
		cItem& item0 = ITEMMAN->GetItem( slotIndex0 );
		cItemDefine* define = ITEMMAN->GetItemDefine( item0.GetIndex() );
		if( !define )
			return false;

		if( define->GetType() != ITEM_SPREAD )
			return false;

		/// 스프레드인경우,
		cCardBookWindow* cardBook = (cCardBookWindow*)GAMEUI->GetCardBookWindow();
		cTarotSheetWindow* sheet = cardBook->GetTarotSheet();
		if( sheet )
		{
			unsigned long registItemIdx = sheet->IsRegistItem( slotIndex1 - INVENTORY_TAROT_BEGIN );	
			if( !(registItemIdx == ULONG_MAX ) )
			{
				eMSGBox_Event event = (registItemIdx == 0)? eMBEVENT_ITEM_CARDBOOK_SPREADNEW : eMBEVENT_ITEM_CARDBOOK_SPREADUPDATE;
				GAMEUI->ShowItemCardBook( event, slotIndex0, slotIndex1, registItemIdx );
			}
		}	
		return false;
	}
	else if( out == ITEM_IN_NPCSTORE || out == ITEM_IN_DISJOINT ||
			out == ITEM_IN_ENHANCED_ITEM || out == ITEM_IN_ENHANCED_CARD ||
			out == ITEM_IN_PUTCARD_ITEMSLOT || out == ITEM_IN_CARDBOOK_SPREAD ||
			out == ITEM_IN_CARDBOOK_TAROT )
	{
		/// 도착지점이 잘못되었으면 리턴
		return false;
	}
	else
	{
		///  락 걸린 슬롯이면 리턴
		cItem& item1 = ITEMMAN->GetItem( slotIndex1 );
		if( item1.GetIndex() > 0 && item1.IsLock() == true )
			return false;

		if( ITEMMAN->TryToMoveItem( slotIndex0, slotIndex1, itemIconFrom ) == false )
			return false;
	}
	return true;
}
