#include "stdafx.h"
#include "MessageBox.h"

#include "../../Flow/Flow.h"
#include "../../Flow/FlowMgr.h"

#include <shellapi.h>


std::list< cMessageBox* >	cMessageBox::g_MessageBoxList;

namespace
{
	cMessageBox* GetFrontLiveMessageBox(const TCHAR* szContext)
	{
		while( cMessageBox::IsMessageBox() )
		{
			cMessageBox* pMsg = cMessageBox::GetFirstMessageBox();
			if( pMsg == NULL )
			{
				g_CriticalLog.Log( _T("[MessageBox] %s found NULL front pointer. count=%d"),
					szContext, cMessageBox::GetCount() );
				return NULL;
			}

			if( pMsg->IsLive() )
				return pMsg;

			g_CriticalLog.Log( _T("[MessageBox] %s removing non-live box. type=%u count=%d"),
				szContext, pMsg->GetMessageType(), cMessageBox::GetCount() );
			cMessageBox::MessageBoxEraseList( pMsg );
			NISAFE_DELETE( pMsg );
		}

		return NULL;
	}
}

void cMessageBox::DeleteList( bool bCalEndMessage )
{
	std::list< cMessageBox* >::iterator it = g_MessageBoxList.begin();
	std::list< cMessageBox* >::iterator itEnd = g_MessageBoxList.end();
	for( ; it!=itEnd; ++it )
	{
		if( bCalEndMessage )
			(*it)->_Cancel( false );
		NiDelete *it;
	}
	g_MessageBoxList.clear();
}

bool cMessageBox::DelMsg( int nMsgType, bool bCallEndMsg )
{
	bool bReturn = false;

	std::list< cMessageBox* >::iterator it = g_MessageBoxList.begin();
	std::list< cMessageBox* >::iterator itEnd = g_MessageBoxList.end();
	while( it != itEnd )
	{
		if( (*it)->GetMessageType() == nMsgType )
		{
			if( bCallEndMsg == true )
				(*it)->_Cancel( false );
			NiDelete *it;
			it = g_MessageBoxList.erase( it );
			bReturn = true;
		}
		else
		{
			++it;
		}
	}

	return bReturn;
}

void cMessageBox::InsertList( TCHAR const* szTitle, TCHAR const* szBody, int nMsgType, int nBoxType )
{
	if( g_MessageBoxList.size() )
	{
		// ?????? ?????? ???????????? ??????
		switch( GetFirstMessageBox()->GetFristType() )
		{
		case cPrintMsg::SERVER_VERSION_ERROR:
			return;
		}
	}

	//DeleteList( true );

	// ?????? ??? ????????????
	switch( nMsgType )
	{
	case cPrintMsg::USE_MANUAL_MESSAGE_DISCONNECT:	// ?????????????????? ?????? ????????? ?????????
	case cPrintMsg::SERVER_VERSION_ERROR:
	case cPrintMsg::SERVER_DISCONNET:
	case cPrintMsg::GAME_DEAD:
	case 30417:
	case 20017:	// ????????? ??????(??????) ??? ????????? ??? ??????.	
	case 30018:	// ????????? ?????? ????????? ??? ??????	
	case 10100:	// ?????? ?????? ?????? 
		{
			DeleteList( true );
		}
		break;
	}

	switch( nMsgType )
	{
	case cPrintMsg::RECOMMENT_ANSWER_CONFIRM:
		GAME_EVENT_STPTR->OnEvent( EVENT_CODE::SEND_RECOMMEND_ADD_ANSWER_INFO );
		break;
	}

	cMessageBox* pMsg = NiNew cMessageBox( szTitle, szBody, nMsgType, nBoxType, g_MessageBoxList.size() );
	g_MessageBoxList.push_back( pMsg );
		
// 	switch( nMsgType )
// 	{
// 	case cPrintMsg::SERVER_VERSION_ERROR:
// 	case cPrintMsg::SERVER_DISCONNET:
// 	case 30417:
// 		{
// 			FLOWMGR_ST.ChangePopAllFlow(Flow::CFlow::FLW_LOGIN);
// 			//SetNextGameStep(GAME_LOGOUT);
// 		}		
// 		break;
// 	}
}

bool cMessageBox::UpdateList()
{
	cMessageBox* pMsg = GetFrontLiveMessageBox( _T("UpdateList") );
	if( pMsg == NULL )
		return false;

	switch( pMsg->GetState() )
	{
	case MBOX_NONE:
		pMsg->Update(g_fDeltaTime);
		pMsg->Update_ForMouse();
		break;
	}

	switch( pMsg->GetState() )
	{
	case MBOX_CALL_OK:
		pMsg->_Ok( true );
		MessageBoxEraseList( pMsg );
		NISAFE_DELETE( pMsg );
		break;
	case MBOX_CALL_CANCEL:
		pMsg->_Cancel( true );
		MessageBoxEraseList( pMsg );
		NISAFE_DELETE( pMsg );
		break;
	}

	return true;
}

void cMessageBox::RenderList()
{
	std::list< cMessageBox* >::iterator it = g_MessageBoxList.begin();
	std::list< cMessageBox* >::iterator itEnd = g_MessageBoxList.end();
	for( ; it!=itEnd; ++it )
	{
		if( (*it) == NULL )
		{
			g_CriticalLog.Log( _T("[MessageBox] RenderList skipped NULL entry.") );
			continue;
		}

		if( (*it)->IsLive() == false )
		{
			g_CriticalLog.Log( _T("[MessageBox] RenderList skipped non-live box. type=%u"),
				(*it)->GetMessageType() );
			continue;
		}

		(*it)->Render();
	}
}

bool cMessageBox::OnEnterKeyList()
{
	cMessageBox* pMsg = GetFrontLiveMessageBox( _T("OnEnterKeyList") );
	if( pMsg == NULL )
		return false;
	switch( pMsg->GetMessageType() )
	{
	case cPrintMsg::LOG_OUT:
	case cPrintMsg::GAME_EXIT:
	case 30019:
	case 20039:						// ??????????????? ??????
	case 20040:						// ??????????????? ??????
	case 20041:						// ??????????????? ???????????? ??????
	case 20061:						// ????????? ??????????????? ??????
	case 30180:						// ????????? ??????
	case 10019:						// ?????? ?????? ??????
	case 14010:						// ?????? ?????? ??????
	case 10100:
	case cPrintMsg::GAME_ITEM_DELETE:// ????????? ??????
		return true;
	}

	pMsg->_Ok( true );
	if( pMsg->ExistOkBtnControl() )
		pMsg->GetOkBtnControl()->PlaySound();
	else if( pMsg->ExistCancelBtnControl() )
		pMsg->GetCancelBtnControl()->PlaySound();
		
	MessageBoxEraseList( pMsg );
	NiDelete pMsg;	
	return true;
}

bool cMessageBox::OnEscapeKeyList()
{
	cMessageBox* pMsg = GetFrontLiveMessageBox( _T("OnEscapeKeyList") );
	if( pMsg == NULL )
		return false;

	switch( pMsg->GetMessageType() )
	{
	case 20039:						// ??????????????? ??????
	case 20040:						// ??????????????? ??????
	case 20041:						// ??????????????? ???????????? ??????
	case 20061:						// ????????? ??????????????? ??????
	case 10019:						// ?????? ?????? ??????
	case 14010:						// ?????? ?????? ??????
	case 10100:
	case cPrintMsg::USE_MANUAL_MESSAGE_DISCONNECT:
		return true;
	}

	pMsg->_Cancel( true );
	if( pMsg->ExistCancelBtnControl() )
		pMsg->GetCancelBtnControl()->PlaySound();
	else if( pMsg->ExistOkBtnControl() )
		pMsg->GetOkBtnControl()->PlaySound();

	MessageBoxEraseList( pMsg );
	NiDelete pMsg;	
	return true;
}


bool cMessageBox::OnLButtonUpList( CsPoint pos )
{
	cMessageBox* pMsg = GetFrontLiveMessageBox( _T("OnLButtonUpList") );
	if( pMsg == NULL )
		return false;

	// ????????? ?????? ????????? ???????????? ?????? ????????? ??????
	if( pMsg->IsInWindow( pos ) == true )
		return true;

	if( ( pMsg->ExistOkBtnControl() == false )&&( pMsg->ExistCancelBtnControl() == false ) )
		return true;

	switch( pMsg->GetMessageType() )
	{
	case 30096:						// ?????? ??????
	case 30065:						// ?????? ??????
	case 10017:						// ????????????
	case 30018:						// ??????????????? ?????? ??????
	case 30019:						// ?????? ?????? ??? ?????????
	case 20017:						// ?????? ??????
	case 30026:						// Npc??????
	case 20029:						// ?????? ?????? ??????
	case 20038:						// ??????????????? ???????????? ??? ??????
	case cPrintMsg::GAME_DEAD:
	case cPrintMsg::LOG_OUT:
	case cPrintMsg::GAME_EXIT:
	case 20039:						// ??????????????? ??????
	case 20040:						// ??????????????? ??????
	case 20041:						// ??????????????? ???????????? ??????
	case 30126:						// ?????? ????????????
	case 30135:						// ?????? ?????? ??????
	case 30136:						// ?????? ??????
	case 30145:						// ?????? ????????????
	case 30151:						// ????????? ???????????????
	case 30152:						// ?????? ??????
	case 30154:						// ?????? ??????
	case 30160:						// ?????? ?????????
	case 30161:						// ?????? ????????? ??????
	case 20061:						// ????????? ??????????????? ??????
	case 30180:						// ????????? ??????
	case 30045:						// ?????? ??????
	case 30046:						// ?????? ??????
	case 30443:						// ???????????????
	case 30485:						// ????????????
	case cPrintMsg::RECOMMENT_ANSWER_CONFIRM:						// ????????????
	case 30550:						// ????????? ??????
	case 30549:						// ????????? ?????? ?????????
	case 30701:
		return true;
	}

	if( pMsg->ExistCancelBtnControl() )
	{
		pMsg->_Cancel( true );
		pMsg->GetCancelBtnControl()->PlaySound();

		MessageBoxEraseList( pMsg );
		NiDelete pMsg;		
	}
	else
	{
		pMsg->_Ok( true );
		if( pMsg->ExistOkBtnControl() )
			pMsg->GetOkBtnControl()->PlaySound();

		MessageBoxEraseList( pMsg );
		NiDelete pMsg;		
	}
	return true;
}

bool cMessageBox::OnRButtonUpList( CsPoint pos )
{
	return OnLButtonUpList( pos );
}

void cMessageBox::ResetDeviceList()
{
	std::list< cMessageBox* >::iterator it = g_MessageBoxList.begin();
	std::list< cMessageBox* >::iterator itEnd = g_MessageBoxList.end();
	for( ; it!=itEnd; ++it )
	{
		if( (*it) == NULL )
		{
			g_CriticalLog.Log( _T("[MessageBox] ResetDeviceList skipped NULL entry.") );
			continue;
		}

		if( (*it)->IsLive() == false )
		{
			g_CriticalLog.Log( _T("[MessageBox] ResetDeviceList skipped non-live box. type=%u"),
				(*it)->GetMessageType() );
			continue;
		}

		(*it)->ResetDevice();
	}
}

bool cMessageBox::IsMessageBox( int nMsgType )
{
	std::list< cMessageBox* >::iterator it = g_MessageBoxList.begin();
	std::list< cMessageBox* >::iterator itEnd = g_MessageBoxList.end();
	for( ; it!=itEnd; ++it )
	{
		if( (*it)->GetMessageType() == nMsgType )
			return true;
	}
	return false;
}

cMessageBox* cMessageBox::GetFirstMessageBox()
{
	if( g_MessageBoxList.empty() )
		return NULL;

	return *(--g_MessageBoxList.end());
}

cMessageBox* cMessageBox::GetMessageBox( int nMsgType )
{
	std::list< cMessageBox* >::iterator it = g_MessageBoxList.begin();
	std::list< cMessageBox* >::iterator itEnd = g_MessageBoxList.end();
	for( ; it!=itEnd; ++it )
	{
		if( (*it)->GetMessageType() == nMsgType )
		{
			return (*it);
		}
	}
	return NULL;
}

void cMessageBox::MessageBoxEraseList( cMessageBox* pBox )
{
	std::list< cMessageBox* >::iterator it = g_MessageBoxList.begin();
	std::list< cMessageBox* >::iterator itEnd = g_MessageBoxList.end();
	for( ; it!=itEnd; ++it )
	{
		if( (*it) == pBox )
		{
			g_MessageBoxList.erase( it );
			return;
		}
	}	
}


//////////////////////////////////////////////////////////////////////////////////////////////
//																							//
//																							//
//																							//
//////////////////////////////////////////////////////////////////////////////////////////////
cMessageBox::cMessageBox( TCHAR const* szTitle, TCHAR const* szBody, int nMsgType, int nBoxType, int nMessageListIndex )
:m_pBody(NULL), m_eMsgType( nMsgType ),m_eState( MBOX_NONE ), m_pValuePointer1(NULL),m_bCallProc(false),
m_ButtonOk(NULL),m_ButtonCancel(NULL),m_pProgress(NULL),m_fValue(0.0f),m_nValue1(0),m_nValue2(0),m_nValue3(0),
m_unValue1(0)
{
	switch( m_eMsgType )
	{
	case cPrintMsg::LOG_OUT:
	case cPrintMsg::GAME_EXIT:
		m_fValue = 5.0f;
		m_nValue1 = -1;
		break;
	case 30018: // ????????? ????????????
		m_fValue = 30.0f;
		break;
	case 30096:			// ?????? ???????????????
	case 30065:			// ???????????? ?????? ??????
	case 30126:			// ?????? ????????????
#ifdef GUILD_RENEWAL
	case 30209:			// ?????? ?????? ?????? ??????
#endif
	case 30485:			// ?????? ??????
	
	case cPrintMsg::RECOMMENT_ANSWER_CONFIRM:
	case 30550:			// ????????? ?????? ??????
		m_fValue = 10.0f;
		break;
	}

	Init( szTitle, szBody, nBoxType, nMessageListIndex );

}

void cMessageBox::_Ok( bool bAbsolute )
{
	std::pair<int, int> value(0,0);
	// NULL ?????? OK??? ??????
	if( ( bAbsolute == false )&&( m_ButtonOk == NULL ) )
	{
		_Cancel( true );
		return;
	}

	if( m_bCallProc == true )
		return;
	m_bCallProc = true;

	switch( m_eMsgType )
	{
	case 30410:		// ???????????? ??????
		{
			GAME_EVENT_ST.OnEvent( EVENT_CODE::TUTORIALQUEST_SKIP_ACCEPT, NULL );
		}
		break;
#ifdef LJW_TUTORIAL_RENEWAL_20191128
	case cPrintMsg::TUTORIAL_EVENT_SKIP:
		GAME_EVENT_ST.OnEvent( EVENT_CODE::SKIP_TUTORIAL_EVENT );
		break;
#endif
	case cPrintMsg::LOGIN_HTTP_SERVER_ERROR:
	case cPrintMsg::USE_MANUAL_MESSAGE://Aeria??? ???????????? ???????????? ??????????????? ???????????? ????????????
		PostQuitMessage(0);//	SetNextGameStep(GAME_EXIT);
		break;
	case cPrintMsg::USE_MANUAL_MESSAGE_DISCONNECT:
	case 10100:
		PostQuitMessage(0);//SetNextGameStep(GAME_EXIT);
		break;

	case cPrintMsg::USE_MANUAL_MESSAGE_URL:
		{
			ShellExecute(NULL, _T( "open" ), _T( "iexplore" ), m_szValue1, NULL, SW_SHOWNORMAL );
			if( GLOBALDATA_ST.IsLoginSkiped() )
				PostQuitMessage(0);//SetNextGameStep(GAME_EXIT);//Aeria??? ???????????? ???????????? ??????????????? ???????????? ????????????
		}
		
		break;
	case cPrintMsg::LOGIN_ID_NONE_EXIST:
		{
			if( GLOBALDATA_ST.IsLoginSkiped() )
			{
				CsMessageBox( MB_OK, L"Login ID none exist");
				PostQuitMessage(0);//SetNextGameStep(GAME_EXIT);
			}
		}
		return;

	case 30375:						// ???????????? ?????? ??????
		GAME_EVENT_ST.OnEvent( EVENT_CODE::CLOSE_PERSONSTORE_MSGBOX, NULL );
		return;
	case 30180:						// ????????? ??????
		{
			std::pair<int, int> pairData( m_nValue1, m_nValue2 );
			GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_CHANGETAMER_CHANGE, &pairData );
		}
		return;
	case 20061:						// ????????? ??????????????? ??????
		{
			ShellExecute(NULL, _T( "open" ), _T( "explorer.exe" ), _T( "http://www.daewonstyle.com" ), NULL, SW_SHOW );
		}
		return;
	case 30175:						// ?????? ????????? ???????????? ??????????????? ????????????
		{
			if( net::game )
				net::game->SendItemMove( m_nValue1, m_nValue2, false );
		}
		return;
	case 32000:
		{
			if( net::game )
				net::game->SendItemMove( m_nValue1, m_nValue2 );
		}
		return;
	case 30176:
	case 30177:
		{
#ifndef ITEM_USE_TIME_PASS
			return;
#endif

			if( net::game )
			{
				cItemInfo* pItem = g_pDataMng->GetInven()->GetData( m_nValue1 );
				int nItemCount = pItem->GetCount();

				if(nItemCount == 1)
				{
					net::game->SendItemActive( m_nValue1 );	
				}
				else
				{
					int nEmptyCnt = g_pDataMng->GetInven()->GetEmptySlotCount();	// ???????????? ????????? ??????

					if(nEmptyCnt !=0)
					{
						int nEmptySlot = g_pDataMng->GetInven()->FindEmptySlot(-1);

						g_pDataMng->SendItemMove( m_nValue1, TO_INVEN_SID( nEmptySlot ), 1 );

						net::game->SendItemActive( nEmptySlot );	
					}
					else
					{
						cPrintMsg::PrintMsg( 11015 );	// ??????????????? ?????? ????????? ???????????????.
					}
				}
			}			
		}	
		return;
		
#ifdef VERSION_USA
	case 20079:						// ????????? ??????
		GAME_EVENT_ST.OnEvent( EVENT_CODE::DIGITAMA_SCAN_START, NULL );
		return;
#endif
	case 20080:						// ?????? ????????? ??????
		GAME_EVENT_ST.OnEvent( EVENT_CODE::DIGITAMA_SCAN_START, NULL );
		return;
	case 20081:						// ?????? ????????? ??????
		GAME_EVENT_ST.OnEvent( EVENT_CODE::DIGITAMA_SELL_START, NULL );
		return;

#ifdef UI_ITEMSCAN_RENEWAL
	case 20099:
		GAME_EVENT_ST.OnEvent( EVENT_CODE::DIGITAMA_ALLSCAN, NULL );
		return;
#endif

	case 20066:						// ??? ???????????? ?????? ????????? ?????? ??????
		//g_pCharMng->GetTamerUser()->SetPortal( m_nValue1 );
		GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_PORTAL_MOVE, &m_nValue1 );
		return;

	case 20038:						// ???????????? ?????? ???????????? ??????
		{
			//ShellExecute(NULL, _T( "open" ), _T( "explorer.exe" ), _T( "http://www.digimonmasters.com/down/main.aspx?" ), NULL, SW_SHOW );
		}
		return;
	case 30055:						// ?????? ?????????
		{
			bool bIsBattleRegisted = false;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::IS_BATTLEMATCH_REGISTED, &bIsBattleRegisted );
			if( bIsBattleRegisted )// ?????? ????????? ????????? ????????? ??????
			{
				cPrintMsg::PrintMsg( 40013 );	// ?????? ????????? ????????? ????????? ??????
				return;
			}
			
			if( net::game )
			{
#ifdef SDM_VIP_SYSTEM_20181105
				if( -1 == m_nValue1 )
					net::game->SendJumpGate( 0, m_nValue2, true );
				else
					net::game->SendJumpGate( m_nValue1, m_nValue2 );
#else
				net::game->SendJumpGate( m_nValue1, m_nValue2 );
#endif
			}
		}
		return;
	case 30544:
		{
			cSkill* pSkillMng = g_pCharMng->GetTamerUser()->GetSkillMng();
			if( pSkillMng->GetSkill_Inex() == -1 )
			{
				cPrintMsg::PrintMsg( 30586 );
				return;
			}

			bool bIsBattleRegisted = false;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::IS_BATTLEMATCH_REGISTED, &bIsBattleRegisted );
			if( bIsBattleRegisted )// ?????? ????????? ????????? ????????? ??????
			{
				cPrintMsg::PrintMsg( 40013 );	// ?????? ????????? ????????? ????????? ??????
				return;
			}

			if( net::game )
			{
				net::game->SendTamerActiveSkill( pSkillMng->GetSkill_Inex() );
				net::game->SendTamerJumpGate( 9801, m_nValue2 );		//????????? ??????, ?????????
			}
		}
		return;
	case 30054:						// ?????? ????????? 4?????? ?????? ??????
		{
			if( g_pGameIF && g_pGameIF->IsActiveWindow( cBaseWindow::WT_MAKE_TACTICS ) )
			{
				g_pGameIF->GetMakeTactics()->SendServer();
				g_pGameIF->GetMakeTactics()->GetDeleteBackupFunction();
			}
		}
		return;
	case 30050:						// ?????? ???????????? ??????
		{
			int AccompanySlotIdx = m_nValue1;
			int ArchiveSlotIdx = m_nValue2;
			int nCost = m_nValue3;
			
			CDigimonArchiveContents::ChangeData kData;
			kData.accompanyslotidx = m_nValue1;
			kData.archiveslotidx = m_nValue2;
			kData.changecost = m_nValue3;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::REQ_CHANGE_DIGIMON, &kData);
		}
		return;
		
	case 30456:						// ?????? ??????.
	case 20021:						// ?????? ????????? ??????
		{
			if( m_nValue3 != 0 )
			{
				g_pDataMng->GetServerSync()->SendServer( (cData_ServerSync::eSYNC)m_nValue3, 0 );
			}
			g_pDataMng->ItemLock( TO_INVEN_SID( m_nValue1 ) );
			if( net::game )
			{
				net::game->SendItemUse( m_nValue2, m_nValue1 );
			}
		}
		return;
	case 20022:						// ?????? ?????? ?????? ????????? ??????
		{
			CsC_AvObject* pNpc = (CsC_AvObject*)m_pValuePointer1;
			pNpc->SetAnimation( ANI::NPC_YES );
			CsC_AvObject* pTamer = g_pCharMng->GetTamerUser();
			pTamer->SetPauseAll( true );

			g_pDataMng->GetServerSync()->SendServer( cData_ServerSync::CASH_CAPSULE_COIN_COMPLEATE, 0 );
			g_pDataMng->GetServerSync()->SendServer( cData_ServerSync::CASH_CAPSULE_COIN_WAIT, 0 );
			g_pDataMng->GetServerSync()->SendServer( cData_ServerSync::CASH_CAPSULE_COIN_CLIENT, 0 );			

			g_pDataMng->ItemAllLock();
			if( net::game )
			{
				g_pDataMng->GetServerSync()->SendServer( cData_ServerSync::CASH_CAPSULE_COIN_SERVER, 0 );
				net::game->SendCapsuleToItem( pNpc->GetFTID(), m_nValue1 );
			}
			g_pGameIF->CloseDynamicIF( cBaseWindow::WT_TALK );
		}
		return;
	case 30300:
		{
			// ????????? ?????? ????????? ????????? ??????
			g_pDataMng->ItemLock( TO_INVEN_SID( m_nValue1 ) );
			if( net::game )
			{
				net::game->SendItemUse( m_nValue2, m_nValue1 );
			}
		}
		return;
	case 20090:						// ????????? ??????
		{
			std::wstring cashShopWebUrl = GLOBALDATA_ST.GetCashShopWebUrl();
			if( !cashShopWebUrl.empty() )
				ShellExecute(NULL, _T( "open" ), _T( "explorer.exe" ), cashShopWebUrl.c_str(), NULL, SW_SHOW );			
		}
		return;
#ifdef VERSION_USA
	case 30600:						// ??????????????? ?????? ?????? ?????? ??????
		{
			g_pDataMng->GetServerSync()->SendServer( cData_ServerSync::DIGIMON_EVOLUTION_OPEN, 0, &m_nValue1, &m_nValue2, &m_nValue3 );			
		}
		return;
#endif
	case 30034:						// ??????????????? ?????? ?????? ?????? ??????
		{
			g_pDataMng->GetServerSync()->SendServer( cData_ServerSync::DIGIMON_EVOLUTION_OPEN, 0, &m_nValue1, &m_nValue2, &m_nValue3 );			
		}
		return;

	case 30041:						// ????????? ?????? ??????
		{
			g_pDataMng->GetServerSync()->SendServer( cData_ServerSync::DIGIMON_RIDE_OPEN, 0, &m_nValue1, &m_nValue2, &m_nValue3 );			
		}
		break;

	case 10017:						// ???????????? ??????
		{
			GAME_EVENT_ST.OnEvent(EVENT_CODE::SEND_CHANGE_CHANNEL, &m_nValue1 );
		}
		return;
	case 30065:						// ????????? ?????? ?????? ??????
		{
			GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_PARTY_INVITE_ANSWER_ACCEPT );
		}
		return;
	case 30018:						// ????????? ???????????? ??????						
		{
			std::pair<bool, unsigned int> result;
			result.first = true;
			result.second = m_nValue1;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_TRADE_REQUEST_RESULT, &result );
		}			
		return;

	case 30026:						// Npc??????
		assert_cs( g_pGameIF );
		assert_cs( g_pCharMng );
		g_pGameIF->CloseDynamicIF( cBaseWindow::WT_NPCFIND );
		g_pCharMng->GetDigimonUser( 0 )->SetDigimonUserState( CDigimonUser::DU_NPCFIND, &m_nValue1 );
		return;

	case 30113:						// ????????????
		g_pHelpArrow->ReleaseArrowPoint();
		return;

	case 20051:						// 2??????????????? ??????
		//g_pSecondPassword->Open( cSecondPassword::eSet, cSecondPassword::ePassRegist );
		return;

	case 30116:						// ???????????? ??????
		{
			std::wstring cashPage = GLOBALDATA_ST.GetWebCashPageUrl();
			if( !cashPage.empty() )
				ShellExecute(NULL, _T( "open" ), _T( "explorer.exe" ), cashPage.c_str(), NULL, SW_SHOW );
		}		
		return;
	case 10051:				// ?????? ?????????. ?????????????????? ??????
		{
			std::wstring url = GLOBALDATA_ST.GetNoticeWebUrl();
			if( !url.empty() )
				ShellExecute(NULL, _T( "open" ), _T( "explorer.exe" ), url.c_str(), NULL, SW_SHOW );
			PostQuitMessage(0);//SetNextGameStep(GAME_EXIT);//Aeria??? ???????????? ???????????? ????????? ???????????? ????????????
		}		
		return;

#ifdef VERSION_TH
	case 10054:
		PostQuitMessage(0);//	g_nGameLoop = GAME_EXIT;
		return;
#endif

	case 30312:
		{
			GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_CASHSHOP_ITEM_PURCHASE, &m_unValue1 );
		}
		return;

	case 30314:
		{
			std::pair<std::wstring, unsigned int> buyItemInfo;
			buyItemInfo.first = m_szValue1;
			buyItemInfo.second = m_unValue1;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_CASHSHOP_ITEM_PRESENT, &buyItemInfo );
		}
		return;

	case cPrintMsg::CHARSELECT_DELETE_CHAR:
		GAME_EVENT_STPTR->OnEvent( EVENT_CODE::OPEN_CHARDEL_PASSWORD_WINDOW );		
		//g_pCharacterSelect->InitDeleteChar();
		return;

	case cPrintMsg::GAME_ITEM_DELETE:
		{
			// ?????? ????????? ?????? ?????? ??????????????? ????????? ????????? ??????
			if( g_pGameIF->IsActiveWindow( cBaseWindow::WT_PERSONSTORE ) )
			{
				cPrintMsg::PrintMsg( 10004 );				
				CURSOR_ST.IconDropCancel();
			}
			else
				CURSOR_ST.IconDropOk();
		}
		return;

	case cPrintMsg::SERVER_VERSION_ERROR:
	case cPrintMsg::SERVER_DISCONNET:
#ifdef IGNORE_DISCONNECT_EXIT			// ?????? ??? ?????? ????????? ????????? ?????????(KOR- debug, release)
		GLOBALDATA_ST.ResetAccountInfo();
		FLOWMGR_ST.ChangePopAllFlow(Flow::CFlow::FLW_LOGIN);//SetNextGameStep(GAME_LOGOUT);
#else
		PostQuitMessage(0);//SetNextGameStep(GAME_EXIT);
#endif
		return;

	case cPrintMsg::QUEST_DROP_BTN:
		g_pDataMng->GetQuest()->DropProcQuest();
		return;

	case cPrintMsg::LOG_OUT:
		FLOWMGR_ST.ChangePopAllFlow(Flow::CFlow::FLW_SERVERSEL);//SetNextGameStep( GAME_LOGOUT );
		return;

	case cPrintMsg::GAME_EXIT:
	case 30443:						// ???????????????
		PostQuitMessage(0);//SetNextGameStep( GAME_EXIT );
		return;

	case cPrintMsg::SAME_MACRO_KEY:
		if( g_pGameIF->IsActiveWindow( cBaseWindow::WT_OPTION_MACRO ) )
			g_pGameIF->GetOptionMacro()->SetBackupKey();
		return;

	case 20004:			// ?????? ???????????? ??????
		if( g_pGameIF->IsActiveWindow( cBaseWindow::WT_MAKE_TACTICS ) )
			g_pGameIF->GetMakeTactics()->DestroyResistDigitama( true );
		return;

	case 20017:			// ?????? ??????	
		{
			GAME_EVENT_ST.OnEvent( EVENT_CODE::REQUEST_DELETE_DIGIMON, &m_nValue1 );
		}
		return;

	case 11028:			// ???????????? ????????? ??????
		if( g_pGameIF->IsActiveWindow( cBaseWindow::WT_STORE ) )
		{
			CsItem::sINFO* pFTItem = g_pDataMng->GetInven()->GetFTData( m_nValue1 );
			if( pFTItem->IsCashType() ) // ????????????????????? 
			{
				cPrintMsg::PrintMsg( 20082, pFTItem->s_szName );
				int nSellInvenIndex = m_nValue1;
				int nSellItemCount  = m_nValue2;
				cMessageBox::GetFirstMessageBox()->SetValue1( nSellInvenIndex );
				cMessageBox::GetFirstMessageBox()->SetValue2( nSellItemCount );
			}
			else // ?????? ???????????????
			{
				std::pair< int, int > pairSellInfo( m_nValue1, m_nValue2 );
				GAME_EVENT_STPTR->OnEvent( EVENT_CODE::SEND_STORE_ITEMSELL, &pairSellInfo );
			}			
		}	
		return;

	case 20082:			// ?????? ????????? ????????? ??????
		if( g_pGameIF->IsActiveWindow( cBaseWindow::WT_STORE ) )
		{
			std::pair< int, int > pairSellInfo( m_nValue1, m_nValue2 );
			GAME_EVENT_STPTR->OnEvent( EVENT_CODE::SEND_STORE_ITEMSELL, &pairSellInfo );
		}	
		return;

	case 20031:			// ??????????????? ?????????
	case 20032:			// ??????????????? ?????????

		GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_CASHSHOP_ITEM_CROP, &m_nValue1 );
// 		if( g_pGameIF->IsActiveWindow( cBaseWindow::WT_CASH ) )
// 			g_pGameIF->GetCash()->SendCropCashItem( m_nValue1 );
		return;

	case 20085:			// ?????? ????????? ?????????
	case 20086:			// ?????? ????????? ?????????
		{
			GS2C_RECV_REWARD_SEND_TYPE recv;
			recv.iType = 1;
			switch( m_nValue2 )
			{
			case 0:	recv.bSendAll = false;	recv.iIndex = m_nValue1;				break;
			case 1:	recv.bSendAll = true;	recv.iIndex = -1;				break;
			default:
				return;
			}			

			GAME_EVENT_ST.OnEvent( EVENT_CODE::REWARD_SEND_ACCPET_DATA, &recv );

		}
		return;

#ifdef USE_BARCODE_REDER
	case 20039:			// ??????????????? ??????
		nsBARCODE::SendBarcodeResist();
		return;
	case 20040:			// ??????????????? ??????
		nsBARCODE::SendBarcodeRelease();
		return;
#endif

	case 30126: //?????? ??????
		if( net::game )
		{
			u4 certify = (u4)m_unValue1;
			net::game->SendGuildAllow( m_szValue1, certify );					

			if( g_pGameIF->IsActiveWindow( cBaseWindow::WT_COMMUNITY ) )
			{
				g_pGameIF->CloseDynamicIF( cBaseWindow::WT_COMMUNITY );			
			}	
		}
		return;
	case 30135: //???????????? ??????
		GAME_EVENT_ST.OnEvent( EVENT_CODE::CHECK_GUILD_DESTROY, null );
		return;

	case 30152: //?????? ??????
		g_pDataMng->GetServerSync()->SendServer( cData_ServerSync::GUILD_DESTROY, 0 );
		return;			
	
	case 30136: //?????? ??????
		g_pDataMng->GetServerSync()->SendServer( cData_ServerSync::GUILD_LEAVE, 0 );
		return;

	case 30145: //?????? ??????
		g_pDataMng->GetServerSync()->SendServer( cData_ServerSync::GUILD_BAN, 0, m_szValue1 );
		return;
		
	case 30151: //????????? ?????? ?????????
		g_pDataMng->GetServerSync()->SendServer( cData_ServerSync::GUILD_AP_MASTER, 0, m_szValue1 );
		return;

	case 30154: //?????? ??????
		g_pDataMng->GetServerSync()->SendServer( cData_ServerSync::GUILD_CREATE, 0, m_szValue1 );	
		return;

	case 30160:		// ?????? ?????????
		cPrintMsg::PrintMsg( 30161 );
		cMessageBox::GetFirstMessageBox()->SetValue1( m_nValue1 );
		return;
	case 30161:		// ?????? ????????? ??????
		if( net::game )
		{
			// ????????? ??????
			g_pDataMng->ItemLock( TO_INVEN_SID( m_nValue1 ) );
			net::game->SendItemUse( g_pCharMng->GetDigimonUser( 0 )->GetUniqID(), m_nValue1 );
		}
		return;

	case 30045:
		{
			std::pair<bool, int> delInfo = pair<bool, int>(true, m_nValue1);
			GAME_EVENT_STPTR->OnEvent(EVENT_CODE::DELETE_FRIEND_SHUTOUT, &delInfo);
		}
		return;

	case 30046:
		{
			std::pair<bool, int> delInfo = pair<bool, int>(false, m_nValue1);
			GAME_EVENT_STPTR->OnEvent(EVENT_CODE::DELETE_FRIEND_SHUTOUT, &delInfo);
		}
		return;

	case 30340:		// ????????? ?????? ????????? ?????? ?????? ??????
		{
			// ????????? ??????
			g_pDataMng->ItemLock( TO_INVEN_SID( m_nValue1 ) );
			if( net::game )
				net::game->SendItemUse( m_nValue2, m_nValue1 );
		}
		return;
	case 30326:		// ????????? ????????????
		{
			unsigned int targetUIDX = m_unValue1;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_MACROPROTECT_QUESTION, &targetUIDX);
// 			if( net::game )
// 				net::game->SendMacroQuestion( m_szValue1 );
		}
		return;
		
	case 30451:
		{
			if( net::game )
			{
				switch( m_nValue1 )
				{
				case RTTI_TAMER_USER: //?????????
					if( g_pCharMng->GetTamerUser()->GetBuff()->IsBuffData( m_nValue2 ) )	//?????? ??????????????? ?????? ????????? ???????????? ??????.. ???????????????
						net::game->SendManualRemove( 1, m_nValue2 );					
					break;
				case RTTI_DIGIMON_USER: //?????????
					if( g_pCharMng->GetDigimonUser(0)->GetBuff()->IsBuffData( m_nValue2 ) )	//?????? ??????????????? ?????? ????????? ???????????? ??????.. ???????????????
						net::game->SendManualRemove( 2, m_nValue2 );					
					break;
				default:
					assert_csm( false, L"????????? object??????"  );
					break;
				}
			}				
		}
		return;

	case 30485: //????????????		
		{
			int nResult = 1;// ??????
			GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_DUAL_REQUEST_ANSWER, &nResult );
		}
		return;

	case 30426:		// ?????? ?????????
	case 30429:
		{
			g_pGameIF->GetEnchantTactics()->SendWeakServer();
		}
		return;
	case cPrintMsg::RECOMMENT_ANSWER_CONFIRM:
		{
			GAME_EVENT_STPTR->OnEvent( EVENT_CODE::SEND_RECOMMEND_ADD_ANSWER_INFO );
			return;
		}
#ifdef MINIGAME
	case 30540:
		{
			int nCount = 0;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::GET_MAKETACTICS_DIGITAMA_COUNT, &nCount);
			int nMoney = (5000 + 5000*nCount);

			if( nMoney > g_pDataMng->GetInven()->GetMoney().GetInt() )
				cPrintMsg::PrintMsg( 11003 );	// ???????????????
			else
				net::game->SendMinigameStart( cMinigame::HATCH, nCount );
		}
		
		return;
#endif
	case 30520:
		if( net::game )
		{			
			net::game->SendGetNatureItem( m_nValue1, m_nValue2 );
		}
		return;
	case 30534:
		{
			// ?????? ????????? ????????? ?????????
			if( g_pDataMng->GetTactics()->GetEmptyTactics() == NULL )
			{
				cPrintMsg::PrintMsg( 30535 );
				break;
			}

			// ????????? ?????? ?????? ????????? ??????
			CsPoint pos( -1, -1 );
			cSeparate::DeleteInstance( GetWindowType(), 0 );
			cCreateName::DeleteInstance( cBaseWindow::WT_CHANGE_T_NAME, 0 );	
			cCreateName* pCName = cCreateName::NewInstance( cBaseWindow::WT_CHANGE_D_NAME, 0, pos );
			if( pCName )
			{
				pCName->SetValue1( m_nValue1 );	// ????????? ?????? ??????
				pCName->SetValue2( true );		// true?????? ???????????? ????????? ?????????, false?????? ???????????? ?????????
			}
		}
		return;

	case 30538: // ???????????? ????????? ????????? ????????? ????????? ????????????
	case 30539: // ???????????? ????????? ????????? ????????? ????????? ????????????
		{
			// m_nValue1 == inven index
			GAME_EVENT_ST.OnEvent( EVENT_CODE::OPEN_CHANGETAMER_WINDOW, &m_nValue1 );
		}
		return;

#ifdef USE_SHUTDOWN
	case 30445:
	case 30442:
		{
			PostQuitMessage(0);//SetNextGameStep( GAME_EXIT );
		}
		return;
#endif
	case 20029:
		{
			switch(m_nValue1)
			{
			case 1 :	// ????????? ??????
				switch( m_nValue2 )
				{
				case nItem::TabInven:
					{				
						g_pDataMng->GetInven()->GetData( m_nValue3 )->Reset();
					}			
					break;
				case nItem::TabEquip:
					{
						g_pDataMng->GetTEquip()->SetData( m_nValue3, NULL, true );				
					}			
					break;
				case nItem::TabWarehouse:
					{
						//g_pDataMng->GetWarehouse()->GetData( m_nValue3 )->Reset();
						value.first = WareHouseContents::WAREHOUSE_NORMAL;
						value.second = m_nValue3;
						GAME_EVENT_ST.OnEvent( EVENT_CODE::WAREHOUSE_RESET, &value);
					}
					break;
#ifdef NEW_SHARESTASH
				case nItem::TabShareStash:
					{
						//						g_pDataMng->GetWarehouse()->GetShareData( m_nValue3 )->Reset();
						value.first = WareHouseContents::WAREHOUSE_SHARE;
						value.second = m_nValue3;
						GAME_EVENT_ST.OnEvent( EVENT_CODE::WAREHOUSE_RESET, &value);

					}
					break;
#endif
				case nItem::TabChipset:
					{
						g_pDataMng->GetDigivice()->GetChipset( m_nValue3 )->Reset();
					}
					break;
				case nItem::TabGiftShop:
					{
						// ?????? ?????????
						int nVoteItemID = m_nValue3;
/*?????? ??????
						// ?????????????????? ????????? ?????????
						cData_Cash::MAP_POSTINFO	PostInfo = g_pDataMng->GetCash()->GetPostDataMap();
						SAFE_POINTER_BEK(PostInfo);
						cData_Cash::MAP_POSTINFO::iterator	it = PostInfo->begin();
						for( it; it!=PostInfo->end(); ++it )
						{
							cItemInfo* pGiftItem = &it->second;
							if( pGiftItem->m_nType == 0 )
								continue;

							if( pGiftItem->m_nType == nVoteItemID )
							{
								//?????? ????????? ??????
								pGiftItem->DecreaseCount( nItemCnt );
							}
						}
*/
					}
					break;
				default:
					assert_cs( false );
				}
				break;
			case 2 :	// ????????? ?????????
				switch( m_nValue2 )
				{
				case nItem::TabInven:
					{				
						g_pDataMng->GetInven()->GetData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
					}			
					break;
				case nItem::TabEquip:
					{
						g_pDataMng->GetTEquip()->GetData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
						CsC_PartObject::sCHANGE_PART_INFO cp;
						cp.s_nPartIndex = m_nValue3;
						if( g_pCharMng && g_pCharMng->GetTamerUser() )
							g_pCharMng->GetTamerUser()->ChangePart( &cp );
					}
					break;
				case nItem::TabWarehouse:
					{
//						g_pDataMng->GetWarehouse()->GetData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
						value.first = WareHouseContents::WAREHOUSE_NORMAL;
						value.second = m_nValue3;
						GAME_EVENT_ST.OnEvent( EVENT_CODE::WAREHOUSE_ENDTIME, &value);

					}
					break;
#ifdef NEW_SHARESTASH
				case nItem::TabShareStash:
					{
//						g_pDataMng->GetWarehouse()->GetShareData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
						value.first = WareHouseContents::WAREHOUSE_SHARE;
						value.second = m_nValue3;
						GAME_EVENT_ST.OnEvent( EVENT_CODE::WAREHOUSE_ENDTIME, &value);
					}
					break;
#endif
				case nItem::TabChipset:
					{
						g_pDataMng->GetDigivice()->GetChipset( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
					}
					break;
				default:
					assert_cs( false );
				}
				break;
			case 3:
				// ????????? ?????????
				switch( m_nValue2 )
				{
				case nItem::TabInven:
					g_pDataMng->GetInven()->GetData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
					break;
				case nItem::TabEquip:
					g_pDataMng->GetTEquip()->GetData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;			
					( (CTamer*)g_pCharMng->GetTamerUser() )->CheckBuff();
					break;
				case nItem::TabWarehouse:
					//std::pair<int, int> value(WareHouseContents::WAREHOUSE_NORMAL, m_nValue3); 
					value.first = WareHouseContents::WAREHOUSE_NORMAL;
					value.second = m_nValue3;
					GAME_EVENT_ST.OnEvent( EVENT_CODE::WAREHOUSE_ENDTIME, &value);
//					g_pDataMng->GetWarehouse()->GetData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
					break;
#ifdef NEW_SHARESTASH
				case nItem::TabShareStash:
					//std::pair<int, int> value(WareHouseContents::WAREHOUSE_SHARE, m_nValue3); 
					value.first = WareHouseContents::WAREHOUSE_SHARE;
					value.second = m_nValue3;
					GAME_EVENT_ST.OnEvent( EVENT_CODE::WAREHOUSE_ENDTIME, &value);
//					g_pDataMng->GetWarehouse()->GetShareData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
					break;
#endif
				case nItem::TabChipset:			
					g_pDataMng->GetDigivice()->GetChipset( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;			
					break;
				default:
					assert_cs( false );
				}
				break;
			default:
				assert_cs( false );
			}

		}
		return;
	case 30548:
		{
			cSkill::sINFO* pSkill = g_pCharMng->GetTamerUser()->GetSkillMng()->GetSkill( g_pCharMng->GetTamerUser()->GetSkillMng()->GetSkill_Inex() );
			if( pSkill == NULL )
			{
				cPrintMsg::PrintMsg( 30586 );
				break;
			}

			if( net::game )
				net::game->SendTamerSummon_StateCheck2(4, 2, m_nValue1 );

			 g_pCharMng->GetTamerUser()->GetSkillMng()->SetSkill_Index( -1 );	// ?????? ?????????
		}
		return;

	case 30550:
		{
			bool bValue = false;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::GET_IS_TUTORIAL_PLAYING, &bValue);
			if( bValue )
			{
				if(net::game)
					net::game->SendTamerSummonAccept(3, 0);
				cPrintMsg::PrintMsg( 30412 );
			}
			else
			{
				if( net::game )
					net::game->SendTamerSummonAccept(3, 1);
			}
			return;
		}
	case 30561:
		{
			GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_GET_ITEM_MACHINE, NULL );
		}
		return;
	case 30562:
		{
			GAME_EVENT_ST.OnEvent( EVENT_CODE::CLOSE_MACHINE, NULL );
		}
		return;
	case 30581:
		// ????????? ??????
		g_pDataMng->ItemLock( TO_INVEN_SID( m_nValue1 ) );

		if( net::game )
			net::game->SendItemUse( g_pCharMng->GetTamerUser()->GetUniqID(), m_nValue1 );
		else
			assert_cs( false );

		return;

	case 30583:
		if( net::game )
			net::game->SendTamerCashSkillDelete( m_nValue1 );
		return;
	case 30602: // ????????? ????????? ?????? ???????????? ???????????? ????????? ?????????????????????????
	case 30611: // ????????? ????????? ?????? ???????????? ????????? ????????? ?????????????????????????
	case 30605: // ????????? ????????? ?????? ???????????? ???????????? ???????????? ?????????????????????????
	case 30608: // ????????? ????????? ?????? ???????????? ???????????? ?????? ????????? ?????????????????????????
		GAME_EVENT_ST.OnEvent( EVENT_CODE::START_ENCHANT_OPTION_ENCHANT, NULL );
		return;
	case 30621: //?????? ??? ??????
		{
			//?????? ??????
			bool bSound = false;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::OPEN_INVENTORY, &bSound );

			//????????? ????????? ?????? ??? ??????????????? ????????? ??????

			//???????????????
			u4 nUserID =  g_pCharMng->GetTamerUser()->GetUniqID();

			//Npc??????
			CsC_AvObject* m_pTarget = NULL;
			m_pTarget = g_pGameIF->GetMastersMatchTarget();
			DWORD nNpcID = ((CNpc*)m_pTarget)->GetFTNpc()->GetInfo()->s_dwNpcID;

			//??????
			net::game->SendMastersMatchOpen( nUserID, (u4)nNpcID );

			//????????? ????????? ?????????
			cPrintMsg::PrintMsg( 10019 );
		}
		break;
	case 30625:		// ????????? ?????? ????????? ?????????????????????????
		{
			int test = 0;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::REQ_START_INCUBATING, &test);
		}
		break;
	case 30626:		// ????????? ?????? ????????? ??????????????????????
		{
			int test = 0;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::REQ_STOP_INCUBATING, &test);
		}
		break;
	case 30629:		// ?????? ?????? ?????? ???????????? ????????????????????? ??????????????????
		{
			int test = 0;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::REQ_UNREGISTER_INCUBATED_DIGIMON, &test);
		}
		break;
	case 30628:		// ?????? ?????? ?????? ???????????? ?????? ????????? ???????????? ???????????? ????????????????????????
		{
			int test = 0;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::REQ_CHANGE_DIGIMON_IN_ACTIVATE_INCUSLOT, &test);
		}
		break;
	case 30630:		// ?????? ????????? ???????????? ???????????? ?????? ?????? ?????????????????? ?????? ??????????????????
		{
			int test = 0;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::REQ_REGISTER_DIGIMON_TO_ACTIVATE_INCUSLOT, &test);
		}
		break;
	case 30670:	// ?????? ?????? ????????? ?????????????????????
		{
			u4 nDigimonID = g_pGameIF->GetEncyclopedia()->_GetSelectDigimonID();
			//????????? ????????? ?????????
			cPrintMsg::PrintMsg( 10019 );
			net::game->SendEncyclopediaGetItem( nDigimonID );
		}
		break;
	case 30672:	// ?????? ??? ????????? ????????????????????????
		{
			u4 nDeckIdx = g_pGameIF->GetEncyclopedia()->_GetSelectDeckIdx();
			net::game->SendEncyclopediaGetDeck( nDeckIdx );

			//?????? ??????
			GS2C_RECV_ENCYCLOPEDIA_USEDECK recv;
			recv.iDeckIdx = nDeckIdx;
			recv.bUse = true;
			GAME_EVENT_STPTR->OnEvent( EVENT_CODE::ENCYCLOPEDIA_USE_DECK, &recv );

			
		}
		break;
	case 30673:	// ??? ????????? ????????????????????????
		{
			u4 nDeckIdx = g_pGameIF->GetEncyclopedia()->_GetSelectDeckIdx();
			net::game->SendEncyclopediaGetDeck( 0 );

			//?????? ??????
			GS2C_RECV_ENCYCLOPEDIA_USEDECK recv;
			recv.iDeckIdx = nDeckIdx;
			recv.bUse = false;
			GAME_EVENT_STPTR->OnEvent( EVENT_CODE::ENCYCLOPEDIA_USE_DECK, &recv );
		}
		break;
	case 30656:	// ?????? ?????? ??????????????????? ??????
		{
			if( g_pGameIF->IsActiveWindow(cBaseWindow::WT_CARDIDENTIFY) )
			{
				g_pGameIF->GetCardIdentify()->SendUnSeal();
			}
		}
		break;

	case 30657:	// ?????? ??????????????????? ??????
		{
			if( g_pGameIF->IsActiveWindow(cBaseWindow::WT_CARDRESEAL) )
			{
				g_pGameIF->GetCardReSeal()->SendReSeal();
			}
		}
		break;

#ifdef LOGIN_SCREEN
	case 10009://????????? ?????? ??????, ??????
		{		// ????????? ???????????? ??????
			if( net::account )
			{
				net::account->m_nIsChangeServer = true;
				net::account->DoDisconnect();
			}

			GLOBALDATA_ST.ResetAccountInfo();
			FLOWMGR_ST.ChangePopAllFlow(Flow::CFlow::FLW_LOGIN);
		}
	//	g_pLogin->SelectServerDisconnect();
		break;
#endif

#ifdef BUFF_CHECK_MSG
	case 20220:
		if( net::game )
			net::game->SendItemUse( m_nValue1, m_nValue2 );		
		break;
#endif

	case 20067:
		GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_PORTAL_MOVE, &m_nValue2 );
		break;

#ifdef MEGAPHONE_BAN
	case 30676:
		{
			if( g_pGameIF->IsActiveWindow( cBaseWindow::WT_CHATOPTION ) )
				g_pGameIF->CloseDynamicIF( cBaseWindow::WT_CHATOPTION );

			if( net::game )
				net::game->SendItemUse( m_nValue1, m_nValue2 );
		}
		break;
#endif
#ifdef GUILD_RENEWAL
	case 30206:	// GSP??? ???????????? [str]????????? ????????? ???????????????????
	case 30207:	// ?????? ????????? ????????? ?????? ????????? ??????????????? [str] ????????? ???????????????.
	case 30216: // ?????????\n?????????????????????????%
		{
			//???????????? ?????? ????????? ???????????? ?????? ?????? ?????? ??????.
			cCommunityContent::sGUILD_PERSON_INFO myInfo;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::GET_GUILD_MYINFO, &myInfo );
			if( myInfo.s_eRank != cCommunityContent::eRANK::GR_2NDMASTER && myInfo.s_eRank != cCommunityContent::eRANK::GR_MASTER )
			{
				std::pair<cCommunityContent::eRANK, std::wstring*> guildName;
				guildName.first = cCommunityContent::GR_2NDMASTER;
				GAME_EVENT_ST.OnEvent( EVENT_CODE::GET_GUILDRANK_NAME, &guildName );
				//?????? ????????? ???
				cPrintMsg::PrintMsg( 30158, guildName.second );
				return;
			}
			// ?????? ?????? ?????? ??????
			u4 nSkillCode = m_nValue1;
			CsSkill* pSkill = nsCsFileTable::g_pSkillMng->GetSkill( nSkillCode );
			for( int i=0; i<SKILL_APPLY_MAX_COUNT; ++i )
			{
				if( pSkill->GetInfo()->s_Apply[i].s_nID == 0 )
					break;
				switch( pSkill->GetInfo()->s_Apply[ i ].s_nA )
				{
				case GUILD_SUMMON:			// ?????? ????????? ??????
				case GUILD_NATUREUP:		// ?????? ????????? ??????
				case GUILD_SCANREDUCE:		// ?????? ?????? ??????
				case GUILD_SCANBITUP:		// ?????? ??? Bit ?????? ??????
				case GUILD_HATCHUP:			// ?????? ?????? ??????
				case GUILD_CROPBITUP:		// ?????? ??? Bit ?????? ??????
				case GUILD_MOVEUP:			// ?????? ?????? ??????
				case GUILD_INCHAPAYREDUCE:	// ?????? ?????? ??????
				case GUILD_INCHARATEUP:		// ?????? ?????? ??????
					{
						if( net::game )
							net::game->SendUseGuildSkill( pSkill->GetInfo()->s_Apply[ i ].s_nA, &nSkillCode );
					}
					return;
				default:
					break;
				}
			}
		}
		break;
	case 30209:	//?????? ???????????? ?????? ????????? ??????????????????. ?????? ????????? ?????????????????????????
		{
			bool bIsBattleRegisted = false;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::IS_BATTLEMATCH_REGISTED, &bIsBattleRegisted );
			if( bIsBattleRegisted )// ?????? ????????? ????????? ?????? ????????? ?????? ??? ??????.
			{
				cPrintMsg::PrintMsg( 40013 );	// ?????? ????????? ????????? ?????? ????????? ?????? ??? ??????.
				return;
			}

			u4 nSkillCode = m_nValue1;
			if( net::game )
				net::game->SendGuildSkill_Summon( nSkillCode );
		}
		break;
#endif

	case 30680:		// ????????? ????????? ?????? ??????
		// ????????? ??????
		g_pDataMng->ItemLock( TO_INVEN_SID( m_nValue1 ) );

		if( net::game )
			net::game->SendItemUse( g_pCharMng->GetTamerUser()->GetUniqID(), m_nValue1 );
		else
			assert_cs( false );

		return;

	case 30687:		// ????????? ????????? ?????? ??????
		{
	 		if( net::game )
				net::game->SendDigimonSkillDelete( m_nValue1 );			
		}

		return;

	case 30701:
		{
			GAME_EVENT_ST.OnEvent( EVENT_CODE::ASK_DIGIMON_TO_ITEM, &m_nValue1 );
		}
		return;

	case 30703:
		switch( m_nValue1 )
		{
		case 1:	// ??????????????? ???????????????
			{
				GAME_EVENT_ST.OnEvent( EVENT_CODE::ASK_ITEM_TO_DIGIMON, &m_nValue2 );
			}
			break;
		case 2:	// ??????????????? ???????????????
			{
			}
			break;

		case 3:	// ??????????????? ???????????????
			{
				GAME_EVENT_ST.OnEvent( EVENT_CODE::ASK_DIGIMON_TO_ITEM, &m_nValue2 );
			}
			break;
		}
		return;

	case 11048: // ????????? max skill lv ???
		{
			SAFE_POINTER_BEK( g_pDataMng );
			if( !g_pDataMng->IsItemUse( TO_INVEN_SID( m_nValue1 ) ) )
				break;

			cData_Inven* pInven = g_pDataMng->GetInven();
			SAFE_POINTER_BEK( pInven );

			cItemInfo* pItem = pInven->GetData( m_nValue1 );
			SAFE_POINTER_BEK( pItem );
			SAFE_POINTER_BEK( nsCsFileTable::g_pItemMng );
			CsItem* pFTItem = nsCsFileTable::g_pItemMng->GetItem( pItem->m_nType );
			SAFE_POINTER_BEK( pFTItem );
			CsItem::sINFO* pFTInfo = pFTItem->GetInfo();
			SAFE_POINTER_BEK( pFTInfo );

			SAFE_POINTER_BEK( g_pCharMng );

			CDigimonUser* pDigimonUser = g_pCharMng->GetDigimonUser( 0 );
			SAFE_POINTER_BEK( pDigimonUser );

			DWORD dwTotalType = pFTInfo->s_nType_L * 100 + pFTInfo->s_nType_S;
			int nEvoType = pDigimonUser->GetEvoType();
			if( !nsCsFileTable::g_pBaseMng->IsEnableSkillMaxLvUpFromEvoType( nEvoType, dwTotalType ) )
			{
				cPrintMsg::PrintMsg( nsSkillLimitOpenResult::ItemTypeError );// ?????? ???????????? ????????? ????????? ?????????
				break;
			}

			// ?????? ????????? ????????? ?????? ????????? ?????? ??????
			int nSkillMaxLv = pDigimonUser->GetCurrentEvoMaxSkillLv();
			int nCurrentMaxSkillRanke = nsCsFileTable::g_pBaseMng->GetSkillRankFromSkillMaxLv( nEvoType, nSkillMaxLv );
			int nNeedSkillRank = nsCsFileTable::g_pBaseMng->GetBeforOpenSkillRankeFromItemSubType( dwTotalType );
			if( nCurrentMaxSkillRanke < nNeedSkillRank )// ?????? ?????? ????????? ???????????? ?????????.
			{
				cPrintMsg::PrintMsg( nsSkillLimitOpenResult::SkipBeforeLevel );// ?????? ???????????? ????????? ????????? ?????????
				break;
			}

			if( nCurrentMaxSkillRanke > nNeedSkillRank )// ?????? ?????? ?????? ????????? ?????? ?????????.
			{
				cPrintMsg::PrintMsg( nsSkillLimitOpenResult::AlreadyOpen );// ?????? ???????????? ????????? ????????? ?????????
				break;
			}

			int nSlot = pDigimonUser->GetFTEvolCurObj()->m_nEvoSlot;
 			if( net::game )
 				net::game->SendSkillMaxLvUp( m_nValue1, pItem->m_nType, nSlot );

		}break;

	case MESSAGE_ACTION:
		{
			GAME_EVENT_ST.OnEvent(EVENT_CODE::START_TRADE_DATA, NULL );
		}
		break;

	case cPrintMsg::GAME_ITEM_MAKING:
		{
			GAME_EVENT_ST.OnEvent(EVENT_CODE::SEND_ITEM_PRODUCTION_RUN, NULL );
		}
		break;

		// ?????? ????????? ============================================================
	case cPrintMsg::EQUIPSYS_WITHDRAW_ITEM:
		GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_CHARGE_ITEM_WITHDRAW, NULL );
		break;

	case cPrintMsg::EQUIPSYS_CANCEL_CHARGE:
		GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_CHARGE_ITEM_CANCEL, NULL );
		break;

	case cPrintMsg::EQUIPSYS_UNLOCK_SLOT:
		GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_CHARGE_ITEM_UNLOCK, NULL );
		break;
		// ==========================================================================
	}

 	_Default();
}

void cMessageBox::_Cancel( bool bAbsolute )
{
	std::pair<int, int> value(0,0);

	// NULL ?????? ????????? ??????
	if( ( bAbsolute == false )&&( m_ButtonCancel == NULL ) )
	{
		_Ok( true );
		return;
	}

	if( m_bCallProc == true )
		return;
	m_bCallProc = true;

	switch( m_eMsgType )
	{
	case 10020:						// ????????? ????????? ?????? ????????? ?????? ?????? ?????? ??????
		{
			if( net::net )
			{
#ifdef DEBUG_NETWORK
				DBG("------------------About to disconnect---------------------\n");
#endif
				((cCliAccount*)net::net)->m_nIsChangeServer = true;
				net::net->cClient::DoDisconnect();
				Sleep( 100 );				
			}

			xdelete(net::account_tmp);
			net::account_tmp = net::account;
			net::account = null;
			net::net = net::account;
			if( GLOBALDATA_ST.IsLoginSkiped() )
				PostQuitMessage(0);//SetNextGameStep(GAME_EXIT);//Aeria??? ???????????? ???????????? ??????????????? ???????????? ????????????
		}
		return;

	case 30175:						// ?????? ????????? ???????????? ??????????????? ????????????
	case 32000:
		{
			g_pDataMng->ResetItemTryCount();
			g_pDataMng->ItemUnlock( m_nValue1 );
			g_pDataMng->ItemUnlock( m_nValue2 );
		}
		return;

	case 30176:	
	case 30177:	
		{			
#ifndef ITEM_USE_TIME_PASS
			return;
#endif
			g_pDataMng->ResetItemTryCount();
			g_pDataMng->ItemUnlock( m_nValue1 );
			g_pDataMng->ItemUnlock( m_nValue2 );
		}
		return;

	case 30065:						// ????????? ?????? ?????? ??????
		{
			GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_PARTY_INVITE_ANSWER_REJECT );
// 			if( net::game )
// 			{
// 				net::game->SendPartyInviteReject();
// 			}
		}
		return;
	case 30018:						// ????????? ???????????? ??????
		{
			std::pair<bool, unsigned int> result;
			result.first = false;
			result.second = m_nValue1;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_TRADE_REQUEST_RESULT, &result );
			
// 			if( net::game )
// 			{
// 				net::game->SendTradeReject( m_nValue1 );
// 			}
		}
		return;

	case 30019:						// ?????? ?????? ??? ?????????
		{
			std::pair<bool, unsigned int> result;
			result.first = false;
			result.second = m_nValue1;
			GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_TRADE_REQUEST_RESULT, &result );
// 			if( net::game )
// 			{
// 				net::game->SendTradeReject( m_nValue1 );
// 			}
		}
		return;	

	case 30126:
		if( net::game )
		{
			u4 certify = (u4)m_unValue1;
			net::game->SendGuildReject( m_szValue1, certify );
		}
		return;

	case 30485:
		{
			int nResult = 0;// ?????? ?????? ?????? ??????(0:??????,1:??????)
			GAME_EVENT_ST.OnEvent( EVENT_CODE::SEND_DUAL_REQUEST_ANSWER, &nResult );
		}
		return;

		
	case 30312:
	case 30314:
		{
			GAME_EVENT_ST.OnEvent( EVENT_CODE::CLOSE_CASH_ITEMBUY_WINDOW );
		}
		return;
	case cPrintMsg::GAME_ITEM_DELETE:
		CURSOR_ST.IconDropCancel();
		return;

	case cPrintMsg::SAME_MACRO_KEY:
		if( g_pGameIF->IsActiveWindow( cBaseWindow::WT_OPTION_MACRO ) )
			g_pGameIF->GetOptionMacro()->ReleaseCheckRadio();
		return;
	case cPrintMsg::RECOMMENT_ANSWER_CONFIRM:
		{
			GAME_EVENT_STPTR->OnEvent( EVENT_CODE::SEND_RECOMMEND_ADD_ANSWER_INFO );
			return;
		}
	case 10051:
	case 19997:
		{
			if( GLOBALDATA_ST.IsLoginSkiped() )
				PostQuitMessage(0);//SetNextGameStep(GAME_EXIT);//Aeria??? ???????????? ???????????? ????????? ???????????? ????????? ????????? ????????????
		}
		return;
	case 30549:
		if(net::game)
			net::game->SendTamerSummonAccept(2, 0);
		cPrintMsg::PrintMsg( 30551 );
		return;
		
	case 30550:
		if(net::game)
			net::game->SendTamerSummonAccept(3, 0);
		cPrintMsg::PrintMsg( 30551 );
		return;
	case 20029:
		{
			switch(m_nValue1)
			{
			case 1 :	// ????????? ??????
				switch( m_nValue2 )
				{
				case nItem::TabInven:
					{				
						g_pDataMng->GetInven()->GetData( m_nValue3 )->Reset();
					}			
					break;
				case nItem::TabEquip:
					{
						g_pDataMng->GetTEquip()->SetData( m_nValue3, NULL, true );				
					}			
					break;
				case nItem::TabWarehouse:
					{						
						value.first = WareHouseContents::WAREHOUSE_NORMAL;
						value.second = m_nValue3;
						GAME_EVENT_ST.OnEvent( EVENT_CODE::WAREHOUSE_RESET, &value);
//						g_pDataMng->GetWarehouse()->GetData( m_nValue3 )->Reset();
					}
					break;
#ifdef NEW_SHARESTASH
				case nItem::TabShareStash:
					{
						value.first = WareHouseContents::WAREHOUSE_SHARE;
						value.second = m_nValue3;
						GAME_EVENT_ST.OnEvent( EVENT_CODE::WAREHOUSE_RESET, &value);
//						g_pDataMng->GetWarehouse()->GetShareData( m_nValue3 )->Reset();
					}
					break;
#endif
				case nItem::TabChipset:
					{
						g_pDataMng->GetDigivice()->GetChipset( m_nValue3 )->Reset();
					}
					break;
				default:
					assert_cs( false );
				}
				break;
			case 2 :	// ????????? ?????????
				switch( m_nValue2 )
				{
				case nItem::TabInven:
					{				
						g_pDataMng->GetInven()->GetData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
					}			
					break;
				case nItem::TabEquip:
					{
						g_pDataMng->GetTEquip()->GetData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
						CsC_PartObject::sCHANGE_PART_INFO cp;
						cp.s_nPartIndex = m_nValue3;
						if( g_pCharMng && g_pCharMng->GetTamerUser() )
							g_pCharMng->GetTamerUser()->ChangePart( &cp );
					}
					break;
				case nItem::TabWarehouse:
					{
						std::pair<int, int> value(WareHouseContents::WAREHOUSE_NORMAL, m_nValue3); 
						GAME_EVENT_ST.OnEvent( EVENT_CODE::WAREHOUSE_ENDTIME, &value);
//						g_pDataMng->GetWarehouse()->GetData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
					}
					break;
#ifdef NEW_SHARESTASH
				case nItem::TabShareStash:
					{
						std::pair<int, int> value(WareHouseContents::WAREHOUSE_SHARE, m_nValue3); 
						GAME_EVENT_ST.OnEvent( EVENT_CODE::WAREHOUSE_ENDTIME, &value);
//						g_pDataMng->GetWarehouse()->GetShareData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
					}
					break;
#endif
				case nItem::TabChipset:
					{
						g_pDataMng->GetDigivice()->GetChipset( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
					}
					break;
				default:
					assert_cs( false );
				}
				break;
			case 3:
				// ????????? ?????????
				switch( m_nValue2 )
				{
				case nItem::TabInven:
					g_pDataMng->GetInven()->GetData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
					break;
				case nItem::TabEquip:
					g_pDataMng->GetTEquip()->GetData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;			
					( (CTamer*)g_pCharMng->GetTamerUser() )->CheckBuff();
					break;
				case nItem::TabWarehouse:
//					std::pair<int, int> value(WareHouseContents::WAREHOUSE_NORMAL, m_nValue3); 
					value.first = WareHouseContents::WAREHOUSE_NORMAL;
					value.second = m_nValue3;
					GAME_EVENT_ST.OnEvent( EVENT_CODE::WAREHOUSE_ENDTIME, &value);
//					g_pDataMng->GetWarehouse()->GetData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
					break;
#ifdef NEW_SHARESTASH
				case nItem::TabShareStash:
					//std::pair<int, int> value(WareHouseContents::WAREHOUSE_SHARE, m_nValue3); 
					value.first = WareHouseContents::WAREHOUSE_SHARE;
					value.second = m_nValue3;
					GAME_EVENT_ST.OnEvent( EVENT_CODE::WAREHOUSE_ENDTIME, &value);
//					g_pDataMng->GetWarehouse()->GetShareData( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;
					break;
#endif
				case nItem::TabChipset:			
					g_pDataMng->GetDigivice()->GetChipset( m_nValue3 )->m_nEndTime = ITEMINFO_INVALIDE_TIME;			
					break;
				default:
					assert_cs( false );
				}
				break;
			default:
				assert_cs( false );
			}

		}
		return;

#ifdef BUFF_CHECK_MSG
		case 20220:
			g_pDataMng->ItemUnlock( m_nValue2 );
			break;
#endif
		case 30626:
			{
				int test = 0;
				GAME_EVENT_ST.OnEvent( EVENT_CODE::ON_CANCEL_INCUBATING, &test);
			}
			break;
#ifdef MEGAPHONE_BAN
		case 30676:
			g_pDataMng->ItemUnlock( m_nValue2 );
			break;
#endif

		// ????????? ?????? ????????? ?????? ??? ??????????????? ????????? ??????.
		case MESSAGE_ACTION:
			{
			}
			break;
		case 30680:		// ????????? ????????? ?????? ??????
			break;
		case 30687:		// ????????? ????????? ?????? ??????
			g_pDataMng->GetServerSync()->RecvServer( cData_ServerSync::MEMORY_SKILL_DELETE, 0 );
			break;;
		case cPrintMsg::GAME_ITEM_MAKING:
			{
			}
			break;

		case 20038:		// 2017-07-11-nova ??????????????? ???????????? ??? ?????? ???????????? ????????? ?????????????????? ?????? ?????????		
			{
				GAME_EVENT_STPTR->OnEvent(EVENT_CODE::RECV_USE_BARCODE_FALSE);			
			}
			return;
		case 11048:
			g_pDataMng->ItemUnlock( m_nValue1 );
			break;
	}

	_Default();
}

void cMessageBox::_Default()
{
	switch( m_eMsgType )
	{
	case cPrintMsg::GAME_DEAD:
		if( net::game )
		{
			CsC_AvObject* pMyDigimon = g_pCharMng ? g_pCharMng->GetDigimonUser( 0 ) : NULL;
			if( pMyDigimon && pMyDigimon->GetBaseStat() )
			{
				if( pMyDigimon->IsServerDie() == false &&
					pMyDigimon->GetBaseStat()->GetHP() > 0 )
				{
					g_CriticalLog.Log( _T("[Die] Ignore stale GAME_DEAD confirm. hp=%d"),
						pMyDigimon->GetBaseStat()->GetHP() );
					return;
				}
			}

			g_pResist->SetEnablePortal(true);	//2017-06-07-nova ????????? ????????? ?????? ?????? ?????? ?????? ?????? ????????? ??????
			g_CriticalLog.Log( _T("[Die] GAME_DEAD confirm accepted. sending DieConfirm.") );
			net::game->SendDieConfirm();
		}
		return;

	case 10014:	// ?????? ????????? ????????? ??????
	case 10013:	// ??????????????? ?????????????????? ?????? ??????
		PostQuitMessage(0);//SetNextGameStep( GAME_EXIT );
		break;

	case 30371:		
		g_pGameIF->GetDynamicIF( cBaseWindow::WT_UNIONSTORE );
		return;
	}
}

void cMessageBox::Destroy()
{
	cBaseWindow::Delete();	
}

void cMessageBox::DeleteResource()
{
	DeleteScript();
	SAFE_NIDELETE( m_pBody );
	SAFE_NIDELETE( m_pProgress );
}

void cMessageBox::Init( TCHAR const* szTitle, TCHAR const* szBody, int nBoxType, int nMessageListIndex )
{
	assert_cs( IsLive() == false );
	cBaseWindow::Init();

	m_ButtonOk = NULL;
	m_ButtonCancel = NULL;

	// ????????? ???????????? ??????????????? ????????? ?????? ??????
	int y = 100;
	//if( ( g_pLogin != NULL )&&( g_pFocusEdit != NULL ) )
	if( (FLOWMGR_ST.GetCurTopFlowID() != Flow::CFlow::FLW_LOGIN) &&  (g_pFocusEdit != NULL) )
	{
		y = 270;
	}

	CsPoint size( 356, 157 );
	switch( m_eMsgType )
	{
	case 30463:				// ?????? ??????
		size.y += 30;
		break;
	case 20039:
	case 20040:
	case 20041:
		size = CsPoint( 700, 210 );
		break;
	case 20061:
	case 30621:
		size = CsPoint( 690, 140 );
		break;
	case 30740:
		size = CsPoint( 690, 260 );
	}

	nMessageListIndex = nMessageListIndex%40;
	int x = ( DEFAULT_SCREEN_WIDTH - size.x )/2;
	x += (nMessageListIndex/10*10) + (nMessageListIndex%10)*6;
	y += nMessageListIndex/10*40 + (nMessageListIndex%10)*5;
	
	InitScript( "Control_G\\MessageBox\\MessageBoxBack.tga", CsPoint( x, y ), size, false, IFREGION_X::JUST_CENTER, IFREGION_Y::JUST_CENTER );
	AddSprite( CsPoint( 0, 25 ), CsPoint( size.x, 1 ), "Control_G\\MessageBox\\Line.tga" );

	cText::sTEXTINFO ti;
	ti.Init( &g_pEngine->m_FontSystem, CFont::FS_12 );
	ti.s_eTextAlign = DT_CENTER;
	ti.SetText( szTitle );
	AddText( &ti, CsPoint( size.x/2, 3 ) );

	ti.Init( &g_pEngine->m_FontSystem, CFont::FS_12 );
	m_pBody = NiNew cStringList;
	switch( m_eMsgType )
	{
	case 20039:
		{
			ti.s_eTextAlign = DT_LEFT;
			m_eTextAlign = DT_LEFT;
						
			g_pStringAnalysis->Cut( m_pBody, MAX_ANAL_LEN, UISTRING_TEXT( "GAMESCANNER_NOTICE_REGIST" ).c_str(), &ti );

			AddSprite( CsPoint( 0, size.y - 80 ), CsPoint( size.x, 1 ), "Control_G\\MessageBox\\Line.tga" );

			ti.s_eTextAlign = DT_CENTER;
			ti.s_Color = FONT_GOLD;
			ti.SetText( UISTRING_TEXT( "GAMESCANNER_REGIST_MESSAGE" ).c_str() );  
			AddText( &ti, CsPoint( size.x/2, size.y - 70 ) );
		}
		break;
	case 20040:
		{
			ti.s_eTextAlign = DT_LEFT;
			m_eTextAlign = DT_LEFT;

			g_pStringAnalysis->Cut( m_pBody, MAX_ANAL_LEN, UISTRING_TEXT( "GAMESCANNER_NOTICE_RELEASE" ).c_str(), &ti );

			AddSprite( CsPoint( 0, size.y - 80 ), CsPoint( size.x, 1 ), "Control_G\\MessageBox\\Line.tga" );

			ti.s_eTextAlign = DT_CENTER;
			ti.s_Color = FONT_GOLD;
			ti.SetText( UISTRING_TEXT( "GAEMSCANNER_RELEASE_MESSAGE" ).c_str() ); 
			AddText( &ti, CsPoint( size.x/2, size.y - 70 ) );
		}
		break;
	case 20041:
		{
			ti.s_eTextAlign = DT_LEFT;
			m_eTextAlign = DT_LEFT;

			g_pStringAnalysis->Cut( m_pBody, MAX_ANAL_LEN, UISTRING_TEXT( "GAMESCANNER_REQUEST_RELEASE" ).c_str(), &ti );

			AddSprite( CsPoint( 0, size.y - 80 ), CsPoint( size.x, 1 ), "Control_G\\MessageBox\\Line.tga" );

			ti.s_eTextAlign = DT_CENTER;
			ti.s_Color = FONT_GOLD;
			ti.SetText( UISTRING_TEXT( "GAMESCANNER_NOTICE_RELEASE_REMAIN_TIME" ).c_str() ); 
			AddText( &ti, CsPoint( size.x/2, size.y - 70 ) );
		}
		break;
	case 20061:
		{
			g_pStringAnalysis->Cut( m_pBody, MAX_ANAL_LEN, UISTRING_TEXT( "GAMESCANNER_CONNECT_ERROR_MESSAGE" ).c_str(), &ti );

			ti.s_Color = NiColor( 1, 1, 0 );
			ti.SetText( UISTRING_TEXT( "GAMESCANNER_CONNECT_HOMEPAGE" ).c_str() );
			cString* pString = NiNew cString;
			pString->AddText( &ti );
			m_pBody->AddTail( pString );
		}
		break;
	case 30621:
		{
			ti.s_eTextAlign = DT_LEFT;
			m_eTextAlign = DT_LEFT;
			g_pStringAnalysis->Cut_Parcing( m_pBody, 770, szBody, &ti );
		}
		break;
	case 30740:
		{
			ti.s_eTextAlign = DT_LEFT;
			m_eTextAlign = DT_LEFT;
			g_pStringAnalysis->Cut_Parcing( m_pBody, 643, szBody, &ti );
		}
		break;
	default:
		{
			//ti.s_eTextAlign = DT_CENTER;
			m_eTextAlign = DT_CENTER;
			g_pStringAnalysis->Cut_Parcing( m_pBody, 310, szBody, &ti );
		}
	}	
	
	SetBtnControl( nBoxType );

	if( m_fValue != 0.0f )
	{
		m_pProgress = NiNew cProgressBar;
		m_pProgress->Init( NULL, cProgressBar::BAR_3IMAGE, GetRootClient() + CsPoint( 17, size.y - 45 ), CsPoint( size.x - 19, 3 ), 
			CsPoint( 2, 2 ), "TargetWindow\\DsBar1.tga", false );		
		m_pProgress->SetRenderPosText( cProgressBar::TEXT_NONE );
		m_pProgress->SetRange( CsPoint( 0, (int)m_fValue ) );		
	}
}

void cMessageBox::SetBtnControl( int nBtnType )
{
	SAFE_NIDELETE( m_ButtonOk );
	SAFE_NIDELETE( m_ButtonCancel );

	CsPoint size = GetRoot()->GetSize();
	cButton::eIMAGE_TYPE eBtnType = cButton::IMAGE_NOR_1;
	switch( nBtnType )
	{
	case CsTalk_Message::MT_OK_CANCEL:
		m_ButtonOk = AddButton( CsPoint( size.x/2 - 84, size.y - 31 ), CsPoint( 73, 18 ), eBtnType, UISTRING_TEXT( "MESSAGEBOX_BTN_YES" ).c_str(), cWindow::SD_Np1 );
		m_ButtonCancel = AddButton( CsPoint( size.x/2 + 14, size.y - 31 ), CsPoint( 73, 18 ), eBtnType, UISTRING_TEXT( "MESSAGEBOX_BTN_NO" ).c_str(), cWindow::SD_Bu2 );
		break;	
	case CsTalk_Message::MT_OK:
		m_ButtonOk = AddButton( CsPoint( size.x/2 - 40, size.y - 31 ), CsPoint( 73, 18 ), eBtnType, UISTRING_TEXT( "COMMON_TXT_OK" ).c_str(), cWindow::SD_Bu3 );
		break;
	case CsTalk_Message::MT_CANCEL:
		m_ButtonCancel = AddButton( CsPoint( size.x/2 - 40, size.y - 31 ), CsPoint( 73, 18 ), eBtnType, UISTRING_TEXT( "COMMON_TXT_CANCEL" ).c_str(), cWindow::SD_Bu2 );
		break;
	case CsTalk_Message::MT_NOBUTTON:
		break;
	default:
		assert_cs( false );
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////
//																							//
//																							//
//																							//
//////////////////////////////////////////////////////////////////////////////////////////////
void cMessageBox::Update(float const& fDeltaTime)
{
	// ???????????? ????????? ??????????????? ?????? ????????? ??????
	if( g_pDataMng->GetServerSync()->IsChageDigimon() == true )
	{
		switch( m_eMsgType )
		{
		case 30160:
		case 30161:
			m_eState = MBOX_CALL_CANCEL;
			cPrintMsg::PrintMsg( 30024 );
			return;
		}
	}

	switch( m_eMsgType )
	{
	case cPrintMsg::LOG_OUT:
	case cPrintMsg::GAME_EXIT:
		{
			if( ( m_fValue -= g_fDeltaTime ) < 0.0f )
			{
				//[?????? : 2018.01.25
				//???????????? ?????? ???????????? ????????? ???????????? ?????? ????????? ?????? ????????????.
				//?????? ?????? : ?????? ????????? ?????? ?????? ????????? ?????? ?????? ???????????? ???????????? -> APP ????????? ??????
				//[?????? : 2018.01.31
				//????????? ??????
				//if(g_pGameIF && g_pGameIF->GetChatMain())
				//	g_pGameIF->GetChatMain()->OnEscapeKey();

				m_eState = MBOX_CALL_OK;
				return;
			}
			else if( m_nValue1 != (int)m_fValue )
			{			
				m_nValue1 = (int)m_fValue;

				std::wstring msg;
				if( m_eState == cPrintMsg::LOG_OUT )
					msg = UISTRING_TEXT( "IN_GAME_LOGOUT_MESSAGE");
				else
					msg = UISTRING_TEXT( "IN_GAME_EXIT_MESSAGE");

				DmCS::StringFn::ReplaceAll( msg, L"#time#", m_nValue1 );
				if( m_nValue2 > 0 )
				{
					msg += UISTRING_TEXT( "IN_GAME_NEXT_EXP_MESSAGE"); 
					DmCS::StringFn::ReplaceAll( msg, L"#value#", m_nValue2 );
				}

				SAFE_NIDELETE( m_pBody );
				m_pBody = NiNew cStringList;

				cText::sTEXTINFO ti;
				ti.Init( &g_pEngine->m_FontSystem, CFont::FS_12 );
				//ti.s_eTextAlign = DT_CENTER;			
				g_pStringAnalysis->Cut_Parcing( m_pBody, 310, const_cast<TCHAR*>(msg.c_str()) , &ti );

				m_pProgress->SetBarPos( (int)m_fValue );
			}
		}
		break;
	case 30018:						// ?????? ?????? ????????? ??????	
		{
			// 30????????? ?????? ???????????? ?????? ??????
			if( ( m_fValue -= g_fDeltaTime ) < 0.0f )
			{
				m_eState = MBOX_CALL_CANCEL;
				return;
			}

			float fLen = ( g_pCharMng->GetTamerUser()->GetPos2D() - g_pMngCollector->GetObject( m_nValue1 )->GetPos2D() ).Length();
			if( fLen > IF_TARGET_TAMER_MAX_DIST*3 )
			{
				m_eState = MBOX_CALL_CANCEL;
				return;
			}

			m_pProgress->SetBarPos( (int)m_fValue );
		}
		break;
	case cPrintMsg::RECOMMENT_ANSWER_CONFIRM:
		{
			if( ( m_fValue -= g_fDeltaTime ) < 0.0f )
			{
				m_eState = MBOX_CALL_CANCEL;
				return;
			}
		}
		break;
	case 30096:						// ??????
	case 30126:						// ?????? ????????????
	case 30065:						// ?????? ??????
#ifdef GUILD_RENEWAL
	case 30209:						// ?????? ?????? ?????? ??????
#endif
	case 30485:						// ?????? ??????
	case 30550:						// ????????? ?????? ??????
		{
			// 10????????? ?????? ???????????? ?????? ??????
			if( ( m_fValue -= g_fDeltaTime ) < 0.0f )
			{
				m_eState = MBOX_CALL_CANCEL;			
				return;
			}
			m_pProgress->SetBarPos( (int)m_fValue );
		}
		break;	
	}
}

cBaseWindow::eMU_TYPE
cMessageBox::Update_ForMouse()
{
	cBaseWindow::eMU_TYPE muReturn = cBaseWindow::Update_ForMouse();
	if( muReturn == MUT_OUT_WINDOW )
		return muReturn;

	if( ( m_ButtonOk != NULL )&&( m_ButtonOk->Update_ForMouse() == cButton::ACTION_CLICK ) )
	{
		m_eState = MBOX_CALL_OK;
		return muReturn;
	}

	if( ( m_ButtonCancel != NULL )&&( m_ButtonCancel->Update_ForMouse() == cButton::ACTION_CLICK ) )
	{
		m_eState = MBOX_CALL_CANCEL;
		return muReturn;
	}
	return muReturn;
}

//////////////////////////////////////////////////////////////////////////////////////////////
//																							//
//																							//
//																							//
//////////////////////////////////////////////////////////////////////////////////////////////
void cMessageBox::Render()
{
	RenderScript();

	int y = m_pBody->GetSize() == 1 ? 48 : 33;

	switch( m_eTextAlign )
	{
	case DT_CENTER:
		m_pBody->Render( CsPoint( 178, y ) + GetRootClient(), 2, m_eTextAlign );
		break;
	case DT_LEFT:
		m_pBody->Render( CsPoint( 20, y ) + GetRootClient(), 2 );
		break;
	default:
		assert_cs( false );
	}

	if( m_pProgress )
		m_pProgress->Render();	
}


void cMessageBox::ResetDevice()
{
	ResetDeviceScript();
	if( m_pProgress )
		m_pProgress->ResetDevice();	
}

