#include "Net_GSrvConnect.h"
#include "PG_CliConnect.h"
//#include "../MainProc/Global.h"
#pragma unmanaged

Net_GSrvConnect*  Net_GSrvConnect::This         = NULL;


bool Net_GSrvConnect::_Init()
{    
    _Net.RegOnSrvPacketFunction	( EM_PG_CliConnect_LtoC_PlayerItemID       		, _PG_CliConnect_LtoC_PlayerItemID       	);
    _Net.RegOnSrvPacketFunction	( EM_PG_CliConnect_LtoC_ZoneInfo           		, _PG_CliConnect_LtoC_ZoneInfo           	);
    _Net.RegOnSrvPacketFunction	( EM_PG_CliConnect_LtoC_PlayerData         		, _PG_CliConnect_LtoC_PlayerData         	);
    _Net.RegOnSrvPacketFunction	( EM_PG_CliConnect_LtoC_PrepareChangeZone  		, _PG_CliConnect_LtoC_PrepareChangeZone  	);
    _Net.RegOnSrvPacketFunction	( EM_PG_CliConnect_LtoC_ChangeZoneOK       		, _PG_CliConnect_LtoC_ChangeZoneOK       	);

    _Net.RegOnSrvPacketFunction	( EM_PG_CliConnect_LtoC_ModifyNPCInfo			, _PG_CliConnect_LtoC_ModifyNPCInfo      	);
    _Net.RegOnSrvPacketFunction	( EM_PG_CliConnect_LtoC_GetNPCMoveInfoResult    , _PG_CliConnect_LtoC_GetNPCMoveInfoResult	);
    return true;
}
bool Net_GSrvConnect::_Release()
{
    return true;
}

//------------------------------------------------------------------------------------------------------
void Net_GSrvConnect::_PG_CliConnect_LtoC_ModifyNPCInfo( int Sockid , int Size , void* Data )
{
    PG_CliConnect_LtoC_ModifyNPCInfo* PG = (PG_CliConnect_LtoC_ModifyNPCInfo*) Data;
    This->R_ModyNPC( &PG->Info );

}
void Net_GSrvConnect::_PG_CliConnect_LtoC_PlayerItemID ( int Sockid , int Size , void* Data )
{
	SetSrvID_Local( Sockid );
    PG_CliConnect_LtoC_PlayerItemID* PG = (PG_CliConnect_LtoC_PlayerItemID*) Data;
    This->PlayerItemID( PG->GItemID );
}
void Net_GSrvConnect::_PG_CliConnect_LtoC_ZoneInfo     ( int Sockid , int Size , void* Data )
{
    PG_CliConnect_LtoC_ZoneInfo* PG = (PG_CliConnect_LtoC_ZoneInfo*) Data;
    This->ZoneInfo( Sockid , PG->ZoneID , Sockid , 0 );
}
void Net_GSrvConnect::_PG_CliConnect_LtoC_PlayerData   ( int Sockid , int Size , void* Data )
{
    PG_CliConnect_LtoC_PlayerData* PG = (PG_CliConnect_LtoC_PlayerData*) Data;
    This->PlayerData( &PG->BaseData );
}
void Net_GSrvConnect::_PG_CliConnect_LtoC_PrepareChangeZone( int Sockid , int Size , void* Data )
{
    PG_CliConnect_LtoC_PrepareChangeZone* PG = (PG_CliConnect_LtoC_PrepareChangeZone*) Data;
    This->PrepareChangeZone( );
}
void Net_GSrvConnect::_PG_CliConnect_LtoC_ChangeZoneOK ( int Sockid , int Size , void* Data )
{
    PG_CliConnect_LtoC_ChangeZoneOK* PG = (PG_CliConnect_LtoC_ChangeZoneOK*) Data;
    This->ChangeZoneOK( );
}
void Net_GSrvConnect::_PG_CliConnect_LtoC_GetNPCMoveInfoResult( int Sockid , int Size , void* Data )
{
	static vector<NPC_MoveBaseStruct> MoveList;
	PG_CliConnect_LtoC_GetNPCMoveInfoResult* PG = (PG_CliConnect_LtoC_GetNPCMoveInfoResult*) Data;

	if( PG->TotalCount == 0 )
	{		
		This->R_GetNPCMoveInfoResult( PG->GUID , MoveList );
		return;
	}
	else
	{
		MoveList.push_back( PG->Base );
	}

	if( MoveList.size() == PG->TotalCount )
	{
		This->R_GetNPCMoveInfoResult( PG->GUID , MoveList );
		MoveList.clear();
		return;
	}
	
}
//------------------------------------------------------------------------------------------------------
void Net_GSrvConnect::Logout( )
{
    PG_CliConnect_CtoL_RequestLogout Send;

    SendToLocal(  sizeof(Send) , &Send );
}
//------------------------------------------------------------------------------------------------------
void Net_GSrvConnect::ModyNPC( ModifyNPCInfo*  Info )
{
    PG_CliConnect_CtoL_ModifyNPCInfo Send;
    Send.Info = *Info;
    SendToLocal(  sizeof(Send) , &Send );
}
//------------------------------------------------------------------------------------------------------
//Àx¦sNPC²¾°Ê¸ê®Æ
void Net_GSrvConnect::SaveNPCMoveInfo( int GItemID , vector<NPC_MoveBaseStruct>& List )
{
	PG_CliConnect_CtoL_SaveNPCMoveInfo Send;

	int Count = (int)List.size();
	Send.GUID = GItemID;
	Send.TotalCount = Count;

	if( Count == 0 )
	{
		Send.IndexID = -1;
		SendToLocal(  sizeof(Send) , &Send );
		return;
	}

	for( int i = 0 ; i < Count ; i++ )
	{
		Send.IndexID = i;
		Send.Base = List[i];
		SendToLocal(  sizeof(Send) , &Send );
	}
}
//------------------------------------------------------------------------------------------------------
#pragma managed