#include "../../mainproc/GameMain.h"
#include "../../netwaker_member/NetWakerClientInc.h"
//#include "../Debug/DebugMessage.h"
//#include "ItemClipboard.h"
#include "FriendFrame.h"

CFriendFrame*			g_pFriend		= NULL;

/*
int	LuaFunc_GetEquipmentItemInfo(lua_State* L);
int	LuaFunc_PickupEquipmentItem(lua_State* L);
int	LuaFunc_UseEquipmentItem(lua_State* L);
int	LuaFunc_GetRoleAttribute(lua_State* L);
int	LuaFunc_GetRoleClass(lua_State* L);
int	LuaFunc_GetRoleLevel(lua_State* L);
int	LuaFunc_GetRoleMoney(lua_State* L);
int	LuaFunc_GetRoleExp(lua_State* L);
int	LuaFunc_GetRoleLVExp(lua_State* L);
int	LuaFunc_AddRoleAttribute(lua_State* L);

int LuaFunc_GetRoleTitle(lua_State* L);
int LuaFunc_GetRoleGuild(lua_State* L);
int LuaFunc_GetRoleIntroduce(lua_State* L);

int LuaFunc_SetRoleIntroduce(lua_State* L);
*/
int	LuaFunc_AddFriend				(lua_State* L);
int	LuaFunc_DelFriend				(lua_State* L);
int	LuaFunc_AddFriendGroup			(lua_State* L);
int	LuaFunc_DelFriendGroup			(lua_State* L);
int	LuaFunc_GetNumFriendGroup		(lua_State* L);
int	LuaFunc_GetFriendGroupInfo		(lua_State* L);
int	LuaFunc_GetFriendInfo			(lua_State* L);


// ----------------------------------------------------------------------------
CFriendFrame::CFriendFrame(CInterface* object)
	: CInterfaceBase(object)
{
	g_pFriend = this;
}

// ----------------------------------------------------------------------------
CFriendFrame::~CFriendFrame()
{
	g_pFriend = NULL;
}

// ----------------------------------------------------------------------------
void CFriendFrame::RegisterFunc()
{
	lua_State* L = GetLuaStateWorld();
	if (L)
	{
		lua_register(L, "AddFriend",				LuaFunc_AddFriend				);
		lua_register(L, "DelFriend",				LuaFunc_DelFriend				);
		lua_register(L, "AddFriendGroup",			LuaFunc_AddFriendGroup			);
		lua_register(L, "DelFriendGroup",			LuaFunc_DelFriendGroup			);
		lua_register(L, "GetNumFriendGroup",		LuaFunc_GetNumFriendGroup		);
		lua_register(L, "GetFriendGroupInfo",		LuaFunc_GetFriendGroupInfo		);
		lua_register(L, "GetFriendInfo",			LuaFunc_GetFriendInfo			);

		/*
		lua_register(L, "GetEquipmentItemInfo",		LuaFunc_GetEquipmentItemInfo	);
		lua_register(L, "PickupEquipmentItem",		LuaFunc_PickupEquipmentItem		);
		lua_register(L, "UseEquipmentItem",			LuaFunc_UseEquipmentItem		);
		lua_register(L, "GetRoleAttribute",			LuaFunc_GetRoleAttribute		);
		lua_register(L, "GetRoleClass",				LuaFunc_GetRoleClass			);
		lua_register(L, "GetRoleLevel",				LuaFunc_GetRoleLevel			);
		lua_register(L, "GetRoleMoney",				LuaFunc_GetRoleMoney			);
		lua_register(L, "GetRoleExp",				LuaFunc_GetRoleExp				);
		lua_register(L, "GetRoleLVExp",				LuaFunc_GetRoleLVExp			);
		lua_register(L, "AddRoleAttribute",			LuaFunc_AddRoleAttribute		);

		lua_register(L, "GetRoleTitle",				LuaFunc_GetRoleTitle			);
		lua_register(L, "GetRoleGuild",				LuaFunc_GetRoleGuild			);
		lua_register(L, "GetRoleIntroduce",			LuaFunc_GetRoleIntroduce		);
		lua_register(L, "SetRoleIntroduce",			LuaFunc_SetRoleIntroduce		);
		*/
	}
}
/*
// ----------------------------------------------------------------------------
int LuaFunc_SetRoleIntroduce(lua_State* L)
{
	const char* cszString  = luaL_checkstring( L, 1 );
	
	char	szBuff[ 1024 ];
	strcpy( szBuff, cszString );

	NetCli_FriendList::SL_ModifyMyInfo( cszString );


	return 1;
}
*/
// ----------------------------------------------------------------------------
int	LuaFunc_AddFriend				(lua_State* L)
{
	const char* cszString  = luaL_checkstring( L, 1 );
	
	char	szBuff[ 1024 ];
	strcpy( szBuff, cszString );

	NetCli_FriendListChild::SChat_BefriendRequest( szBuff );

	return 0;
}
// ----------------------------------------------------------------------------
int	LuaFunc_DelFriend				(lua_State* L)
{
	const char* cszString  = luaL_checkstring( L, 1 );
	
	char	szBuff[ 1024 ];
	strcpy( szBuff, cszString );

	NetCli_FriendListChild::SL_DelFriend( szBuff );

	return 0;
}
// ----------------------------------------------------------------------------
int	LuaFunc_AddFriendGroup			(lua_State* L)
{
	// 1 ID 2 Group ID 3 
	
	int iFriendID	= luaL_checkint( L, 1 );	// Friend ID 
	int iGroupID	= luaL_checkint( L, 2 );	// Group ID 
	
	return 0;
}
// ----------------------------------------------------------------------------
int	LuaFunc_DelFriendGroup			(lua_State* L)
{
	int iGroupID	= luaL_checkint( L, 2 );	// Friend ID 

	return 0;
}
// ----------------------------------------------------------------------------
int	LuaFunc_GetNumFriendGroup		(lua_State* L)
{
	int iNumGroup = NetCli_FriendListChild::m_mapFolderID.size();
	lua_pushnumber( L, iNumGroup );

	return 1;
}
// ----------------------------------------------------------------------------
int	LuaFunc_GetFriendGroupInfo		(lua_State* L)
{
	// 1 GroupID
	int iGroupID	= luaL_checkint( L, 1 );	// Group ID 

	map< string, int > &mapFolderID = NetCli_FriendListChild::m_mapFolderID;

	for( map< string, int >::iterator it = mapFolderID.begin(); it != mapFolderID.end(); it++ )
	{
		if( it->second == iGroupID )
		{
			lua_pushstring( L, it->first.c_str() );
			return 1;
		}
	}

	return 0;
}
// ----------------------------------------------------------------------------
int	LuaFunc_GetFriendInfo			(lua_State* L)
{
	// 1 FriendID
	int iFriendIndex	= luaL_checkint( L, 1 ) -1;	// Friend ID 

	if( iFriendIndex >= 0 && iFriendIndex < _MAX_FRIENDLIST_COUNT_ )
	{		
		BaseFriendStruct* pFriend =  &( CNetGlobal::RoleData()->SelfData.FriendList.FriendList[ iFriendIndex ] );

		if( !pFriend->IsEmpty() )
		{
			FriendInfo	info		= NetCli_FriendListChild::m_mapFriendInfo[ pFriend->Name.Begin() ];

			// FriendName
				lua_pushstring( L, pFriend->Name.Begin() );

			// GroupID
				int iFolderID = -1;
				map< string, int >::iterator it = NetCli_FriendListChild::m_mapFolderID.find( pFriend->Group.Begin() );

				if( it != NetCli_FriendListChild::m_mapFolderID.end() )
					iFolderID = it->second;
				else
					iFolderID = 1;			

				lua_pushnumber( L, iFolderID );

			// ZoneID
				lua_pushnumber( L, info.ZoneID );

			// Title
				lua_pushnumber( L, -1 );

			// Guild
				lua_pushnumber( L, -1 );

			// Class1 ID
				lua_pushnumber( L, info.Voc );

			// Class1 Level
				lua_pushnumber( L, info.VocLV );
				
			// Class2 ID
				lua_pushnumber( L, info.Voc_Sub );

			// Class1 Level
				lua_pushnumber( L, info.Voc_SubLV );

			// Introduction
				lua_pushstring( L, info.Introduection.c_str() );

			// Note
				lua_pushstring( L, info.Introduection.c_str() );



		}		
	}

	return 0;
}
// ----------------------------------------------------------------------------