#include "../../mainproc/GameMain.h"
#include "../../Interface/Login/LoginParent.h"
#include "../../Interface/Login/CharacterSelect.h"
#include "../../Interface/Debug/DebugMessage.h"
#include "NetCli_Login_Child.h"

// --------------------------------------------------------------------------------------
bool CNetCli_Login_Child::_Init()
{
	if (m_pThis)
		return false;

	m_pThis = new CNetCli_Login_Child;
	return CNetCli_Login::_Init();
}

// --------------------------------------------------------------------------------------
bool CNetCli_Login_Child::_Release()
{
	CNetCli_Login::_Release();

	if (m_pThis)
	{
		delete m_pThis;
		m_pThis = NULL;
	}

	return true;
}

// --------------------------------------------------------------------------------------
void CNetCli_Login_Child::On_Login(const char* pszInfo)
{
	g_pDebugMessage->DebugOutput(1, "login succeed!");
}

// --------------------------------------------------------------------------------------
void CNetCli_Login_Child::On_Logout()
{
	g_pDebugMessage->DebugOutput(1, "logout!");
}

// --------------------------------------------------------------------------------------
void CNetCli_Login_Child::On_LoginFailed(SYSLogFailedENUM emLogFailed)
{
	switch ( emLogFailed )
	{
	case EM_NetLogFailed_PasswordError:
		g_pDebugMessage->DebugOutput( 0, "密碼錯誤!" );
		break;

	case EM_NetLogFailed_ConnectFail:
		g_pDebugMessage->DebugOutput( 0, "連線不成功!" );
		break;

	case EM_NetLogFailed_ConnectError:
		g_pDebugMessage->DebugOutput( 0, "連結位置錯誤!" );
		break;

	case EM_NetLogFailed_NotFindError:
		g_pDebugMessage->DebugOutput( 0, "找不到帳號!" );
		break;

	case EM_NetLogFailed_ProxyNotExist:
		g_pDebugMessage->DebugOutput( 0, "Proxy不存在!" );
		break;

	case EM_NetLogFailed_SwitchDisconnect:
		g_pDebugMessage->DebugOutput( 0, "未完成註冊及與 Switch 斷線!" );
		break;

	case EM_NetLogFailed_ProxyLoginFailed:
		g_pDebugMessage->DebugOutput( 0, "未完成註冊及與 Proxy 連線失敗!" );
		break;

	case EM_NetLogFailed_UnknowError:
		g_pDebugMessage->DebugOutput( 0, "暫時未規類的錯誤!" );
		break;

	default:
		g_pDebugMessage->DebugOutput( 0, "On_LoginFailed error code!" );
		break;
	}	
}

// --------------------------------------------------------------------------------------
void CNetCli_Login_Child::On_ServerConnect(int iServerID , const char* cpszServerName)
{
	int a = 0;
	//SetSrvID_Local( iServerID );

	// 清除資料
	//g_pCharacterSelect->Clear();

	g_pLoginParent->SendLoginScreen(GLUE_SCREEN_CHAR_SELECT);
}

// --------------------------------------------------------------------------------------
void CNetCli_Login_Child::On_ServerDisConnect( int iServerID )
{
	if( iServerID == _ServerNetID.m_iChat )
	{
		g_pDebugMessage->DebugOutput( 1, "Chat Server is DisConnect!" );
	}
	else if( iServerID == _ServerNetID.m_iLocal )
	{
		g_pDebugMessage->DebugOutput( 1, "Local Server is DisConnect!" );
	}
	else if( iServerID == _ServerNetID.m_iMaster )
	{
		g_pDebugMessage->DebugOutput( 1, "Master Server is DisConnect!" );
	}
	
}

// --------------------------------------------------------------------------------------
void CNetCli_Login_Child::On_SamepleRoleData( int iFieldIndex, SampleRoleData* pSampleRole )
{
	g_pCharacterSelect->Insert(iFieldIndex, pSampleRole);
}

// --------------------------------------------------------------------------------------
void CNetCli_Login_Child::On_SamepleRoleDataEnd()
{
	g_pCharacterSelect->SendCharacterListUpdate();

#ifdef _AUTOLOGIN
	if( m_bAutoLogin == true )
		SelectRole( m_iAutoLoginRoleID );
#endif

}

// --------------------------------------------------------------------------------------
void CNetCli_Login_Child::On_SelectRoleResult( EM_SelectRoleResult emResult, int iDBID )
{
	switch ( emResult )
	{
	case EM_SelectRole_OK:		
		g_pDebugMessage->DebugOutput( 1, "EM_SelectRole_OK!" );
		break;

	case EM_SelectRole_No_This:
		g_pDebugMessage->DebugOutput( 0, "EM_SelectRole_No_This!" );
		break;

	case EM_SelectRole_ZoneNotExist:
		g_pDebugMessage->DebugOutput( 0, "EM_SelectRole_ZoneNotExist!" );
		break;

	default:
		g_pDebugMessage->DebugOutput( 0, "Select role failed! reult_code(%d)", emResult );
	}
}

// --------------------------------------------------------------------------------------
void CNetCli_Login_Child::On_DeleteRoleResult( EM_DeleteRoleResult emResult )
{
	switch ( emResult )
	{
	case EM_DeleteRole_OK:
		g_pDebugMessage->DebugOutput( 1, "delete role is succeed!" );
		g_pCharacterSelect->Clear();
		CNetCli_Login::RquestRoleData();		
		break;

	case EM_RoleNotExist:
		g_pDebugMessage->DebugOutput( 0, "EM_RoleNotExist!" );
		break;

	case EM_DeleteSysErr:
		g_pDebugMessage->DebugOutput( 0, "EM_DeleteSysErr!" );
		break;

	default:
		g_pDebugMessage->DebugOutput( 0, "Delete role failed! reult_code(%d)", emResult );
		break;
	}
}

// --------------------------------------------------------------------------------------
void  CNetCli_Login_Child::On_CreateRoleResult( EM_CreateRoleResult emResult )
{
	switch ( emResult )
	{
	case EM_CreateRole_OK:
		g_pCharacterSelect->Clear();
		CNetCli_Login::RquestRoleData();
		g_pLoginParent->SendLoginScreen(GLUE_SCREEN_CHAR_SELECT);
		g_pDebugMessage->DebugOutput( 1, "EM_CreateRole_OK!" );
		break;

	case EM_RoleNameExist:
		g_pDebugMessage->DebugOutput( 0, "EM_RoleNameExist!" );
		break;

	case EM_SystemError:
		g_pDebugMessage->DebugOutput( 0, "EM_SystemError!" );
		break;

	default:
		g_pDebugMessage->DebugOutput( 0, "Create role failed! reult_code(%d)", emResult );
		break;
	}
}
// --------------------------------------------------------------------------------------
void CNetCli_Login_Child::On_EnterWorld ( int iDBID, SampleRoleData* pSampleRole )
{
	g_pGameMain->EnterWorld(iDBID, pSampleRole->RoleName.Begin());
}
// --------------------------------------------------------------------------------------
void CNetCli_Login_Child::On_LeaveWorld ( int iDBID )
{
	g_pGameMain->LeaveWorld();
}
// --------------------------------------------------------------------------------------
