BOOL NPC_DepotItem_gettItem( int meindex, int talkerindex, int num)
{
	int emptyindex;
	int itemindex;

	if( !CHAR_CheckDepotItem( talkerindex) ) return FALSE;

	if( (emptyindex=CHAR_findEmptyItemBox( talkerindex)) == -1 ) return FALSE;
	itemindex = CHAR_getDepotItemIndex( talkerindex, num);
	if( !ITEM_CHECKINDEX( itemindex) )return FALSE;

	CHAR_setDepotItemIndex( talkerindex, num, -1);
	CHAR_setItemIndex( talkerindex, emptyindex, itemindex);
	CHAR_sendItemDataOne( talkerindex, emptyindex);
	
	CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);

	LogItem(
		CHAR_getChar( talkerindex, CHAR_NAME ),
		CHAR_getChar( talkerindex, CHAR_CDKEY ),
#ifdef _add_item_log_name
		itemindex,
#else
		ITEM_getInt( itemindex, ITEM_ID),
#endif
		"Depot(取出道具)",
		CHAR_getInt( talkerindex,CHAR_FLOOR),
		CHAR_getInt( talkerindex,CHAR_X ),
 		CHAR_getInt( talkerindex,CHAR_Y ),
		ITEM_getChar( itemindex, ITEM_UNIQUECODE),
		ITEM_getChar( itemindex, ITEM_NAME),
		ITEM_getInt( itemindex, ITEM_ID) );

	{
		int i, cnt=0;
		int work[CHAR_MAXDEPOTITEMHAVE];
		for( i = 0; i < CHAR_MAXDEPOTITEMHAVE; i ++ ) {
			work[i] = -1;
		}
		for( i = 0; i < CHAR_MAXDEPOTITEMHAVE; i ++ ) {
			itemindex = CHAR_getDepotItemIndex( talkerindex, i);
			if( !ITEM_CHECKINDEX( itemindex)) continue;
			work[ cnt++] = itemindex;
		}
		for( i = 0; i < CHAR_MAXDEPOTITEMHAVE; i ++ ) {
			CHAR_setDepotItemIndex( talkerindex, i, work[i]);
		}
	}


	return TRUE;
}
BOOL NPC_DepotItem_InsertItem( int meindex, int talkerindex, int num)
{
	int emptyindex;
	int itemindex;
	int cost = CHAR_getWorkInt( meindex, NPC_WORK_COST);

	if( !CHAR_CheckDepotItem( talkerindex) ) return FALSE;
	if( (emptyindex=CHAR_findEmptyDepotItem( talkerindex) ) == -1 ) return FALSE;
	itemindex = CHAR_getItemIndex( talkerindex, num);
	if( !ITEM_CHECKINDEX( itemindex) )return FALSE;
#if 1 // 共同倉庫不可存的物品
	if( ITEM_getInt( itemindex, ITEM_DROPATLOGOUT) || // 登出後消失
			ITEM_getInt( itemindex, ITEM_VANISHATDROP) || // 丟棄後消失
			!ITEM_getInt( itemindex, ITEM_CANPETMAIL)) { // 不可寵郵寄
		print("\n 改封包!!非法存放道具:%s ", CHAR_getChar( talkerindex, CHAR_CDKEY) );
		return FALSE;
	}
#endif
	if( CHAR_DelGold( talkerindex, cost ) == 0 ) return FALSE;

	CHAR_setItemIndex( talkerindex, num, -1);
	CHAR_sendItemDataOne( talkerindex, num);
	CHAR_setDepotItemIndex( talkerindex, emptyindex, itemindex);

//	CHAR_DelGold( talkerindex, cost );
	CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);

	LogItem(
		CHAR_getChar( talkerindex, CHAR_NAME ),
		CHAR_getChar( talkerindex, CHAR_CDKEY ),
#ifdef _add_item_log_name
		itemindex,
#else
		ITEM_getInt( itemindex, ITEM_ID),
#endif
		"Depot(存放道具)",
		CHAR_getInt( talkerindex,CHAR_FLOOR),
		CHAR_getInt( talkerindex,CHAR_X ),
 		CHAR_getInt( talkerindex,CHAR_Y ),
		ITEM_getChar( itemindex, ITEM_UNIQUECODE),
		ITEM_getChar( itemindex, ITEM_NAME),
		ITEM_getInt( itemindex, ITEM_ID) );

	NPC_DepotItem_CheckRepeat( talkerindex);

	return TRUE;
}
BOOL NPC_DepotItem_gettItem( int meindex, int talkerindex, int num)
{
	int emptyindex;
	int itemindex;

	if( !CHAR_CheckDepotItem( talkerindex) ) return FALSE;

	if( (emptyindex=CHAR_findEmptyItemBox( talkerindex)) == -1 ) return FALSE;
	itemindex = CHAR_getDepotItemIndex( talkerindex, num);
	if( !ITEM_CHECKINDEX( itemindex) )return FALSE;
#ifdef _JZ_CF_DELPETITEM
	int ID1,ID2,j;
	ID1 = ITEM_getInt( itemindex, ITEM_ID);
	for( j=0;j<5;j++ ) {
		ID2 = getDelItem(j);
		if(ID2 == 0)break;
		if( ID1 == ID2){
			CHAR_setDepotItemIndex( talkerindex, num, -1);
			LogItem(CHAR_getChar( talkerindex, CHAR_NAME ), //人物名
							CHAR_getChar( talkerindex, CHAR_CDKEY ), //帳號
#ifdef _add_item_log_name  // WON ADD 在item的log中增加item名稱
							itemindex,
#else
      				ITEM_getInt( itemindex, ITEM_ID ),
#endif
							"poolitemshop(CF設置清除物品)",
							CHAR_getInt( talkerindex,CHAR_FLOOR),
							CHAR_getInt( talkerindex,CHAR_X ),
 	     				CHAR_getInt( talkerindex,CHAR_Y ),
           		ITEM_getChar( itemindex, ITEM_UNIQUECODE),
							ITEM_getChar( itemindex, ITEM_NAME),
							ITEM_getInt( itemindex, ITEM_ID)
							);
			CHAR_talkToCli( talkerindex, -1, "系統清除你倉庫裡的道具", CHAR_COLORWHITE );
			return TRUE;
		}
	}
#endif
	CHAR_setDepotItemIndex( talkerindex, num, -1);
	CHAR_setItemIndex( talkerindex, emptyindex, itemindex);
	CHAR_sendItemDataOne( talkerindex, emptyindex);
	
	CHAR_send_P_StatusString( talkerindex, CHAR_P_STRING_GOLD);

	LogItem(
		CHAR_getChar( talkerindex, CHAR_NAME ),
		CHAR_getChar( talkerindex, CHAR_CDKEY ),
#ifdef _add_item_log_name
		itemindex,
#else
		ITEM_getInt( itemindex, ITEM_ID),
#endif
		"Depot(取出道具)",
		CHAR_getInt( talkerindex,CHAR_FLOOR),
		CHAR_getInt( talkerindex,CHAR_X ),
 		CHAR_getInt( talkerindex,CHAR_Y ),
		ITEM_getChar( itemindex, ITEM_UNIQUECODE),
		ITEM_getChar( itemindex, ITEM_NAME),
		ITEM_getInt( itemindex, ITEM_ID) );

	{
		int i, cnt=0;
		int work[CHAR_MAXDEPOTITEMHAVE];
		for( i = 0; i < CHAR_MAXDEPOTITEMHAVE; i ++ ) {
			work[i] = -1;
		}
		for( i = 0; i < CHAR_MAXDEPOTITEMHAVE; i ++ ) {
			itemindex = CHAR_getDepotItemIndex( talkerindex, i);
			if( !ITEM_CHECKINDEX( itemindex)) continue;
			work[ cnt++] = itemindex;
		}
		for( i = 0; i < CHAR_MAXDEPOTITEMHAVE; i ++ ) {
			CHAR_setDepotItemIndex( talkerindex, i, work[i]);
		}
	}


	return TRUE;
}
void NPC_PoolItemShopWindowTalked( int meindex, int talkerindex, 
								int seqno, int select, char *data)
{
	if( NPC_Util_CharDistance( talkerindex, meindex ) > 2) return;

	//print("\n NPC_PoolItemShopWindowTalked: seq:%d sel:%d data:%s", seqno, select, data);

	switch( seqno ) {
	  case CHAR_WINDOWTYPE_POOLITEMSHOP_START:
		switch( atoi( data)) {
		  case 1:
			if( CHAR_getCharPoolItemIndexElement( talkerindex) != -1 ) {
				NPC_PoolItemShop_printWindow_Pool( meindex, talkerindex);
			}else {
				NPC_PoolItemShop_printWindow_Full( meindex, talkerindex);
			}
			break;
		  case 2:
			if( CHAR_findEmptyItemBox( talkerindex) != -1 ) {
				NPC_PoolItemShop_printWindow_Draw( meindex, talkerindex);
			}else {
				NPC_PoolItemShop_printWindow_HaveItemFull( meindex, talkerindex);
			}
			break;
#ifdef _NPC_DEPOTITEM
		  case 3:
			if( !CHAR_CheckDepotItem( talkerindex) ){
				CHAR_GetDepotItem( meindex, talkerindex);
				CHAR_talkToCli( talkerindex, -1, "取得道具,請稍後!", CHAR_COLORYELLOW);
			}else{
				NPC_PoolItemShop_DepotItem_Menu( meindex, talkerindex);
			}
			break;
#endif

		}
		break;
	  case CHAR_WINDOWTYPE_POOLITEMSHOP_POOL_MSG:
	  	if( atoi( data) == 0){
			NPC_PoolItemShop_printWindow_Start( meindex, talkerindex);
	  	}else {
			NPC_PoolItemShop_PoolItem( meindex, talkerindex, atoi(data)-1);
		}
		break;
	  case CHAR_WINDOWTYPE_POOLITEMSHOP_DRAW_MSG:
	  	if( atoi( data) == 0){
			NPC_PoolItemShop_printWindow_Start( meindex, talkerindex);
	  	}else {
		  	NPC_PoolItemShop_DrawItem( meindex, talkerindex, atoi(data)-1);
		}
	  	break;
	  case CHAR_WINDOWTYPE_POOLITEMSHOP_FULL_MSG:
		NPC_PoolItemShop_printWindow_Start( meindex, talkerindex);
	  	break;
	  case CHAR_WINDOWTYPE_POOLITEMSHOP_HAVEITEMFULL_MSG:
		NPC_PoolItemShop_printWindow_Start( meindex, talkerindex);
	  	break;

#ifdef _NPC_DEPOTITEM
	  case CHAR_WINDOWTYPE_DEPOTITEMSHOP_MENU:
			if( !CHAR_CheckDepotItem( talkerindex) ){
				CHAR_GetDepotItem( meindex, talkerindex);
				return;
			}else{
				NPC_PoolItemShop_DepotItem_Menu( meindex, talkerindex);
			}
		  break;
	  case CHAR_WINDOWTYPE_DEPOTITEMSHOP_HANDLE:
		  if( !CHAR_CheckDepotItem( talkerindex) ) return ;
		  switch( atoi( data)) {
		  case 1://放入
				if( CHAR_findEmptyDepotItem( talkerindex) == -1 ){
					CHAR_talkToCli( talkerindex, -1, "倉庫已滿!", CHAR_COLORYELLOW);
					return;
				}
				NPC_DepotItem_Item_printWindow( meindex, talkerindex);
			  break;
		  case 2:
				if( CHAR_findEmptyItemBox( talkerindex) == -1 ) {
					CHAR_talkToCli( talkerindex, -1, "身上道具欄位已滿!", CHAR_COLORYELLOW);
					return;
				}
				NPC_DepotItem_Depot_printWindow( meindex, talkerindex);
			  break;
		  }
		  break;
	  case CHAR_WINDOWTYPE_DEPOTITEMSHOP_ADD://放入
			if( !CHAR_CheckDepotItem( talkerindex) ) return ;
			if( atoi( data) == 0){
				NPC_PoolItemShop_DepotItem_Menu( meindex, talkerindex);
			}else {
				if( NPC_DepotItem_InsertItem( meindex, talkerindex, atoi( data)-1) == FALSE ){
					NPC_PoolItemShop_DepotItem_Menu( meindex, talkerindex);
					CHAR_talkToCli( talkerindex, -1, "存放道具失敗,請稍後再試!", CHAR_COLORYELLOW);
				}
			}
		  break;
	  case CHAR_WINDOWTYPE_DEPOTITEMSHOP_GET:
			if( !CHAR_CheckDepotItem( talkerindex) ) return ;
			if( atoi( data) == 0){
				NPC_PoolItemShop_DepotItem_Menu( meindex, talkerindex);
			}else {
				if( NPC_DepotItem_gettItem( meindex, talkerindex, atoi( data)-1) == FALSE ){
					NPC_PoolItemShop_DepotItem_Menu( meindex, talkerindex);
					CHAR_talkToCli( talkerindex, -1, "取出道具失敗,請稍後再試!", CHAR_COLORYELLOW);
				}
			}
		  break;
#endif
  
	  default:
		break;
	}
}