BOOL KPlayerBaseProcess::OnSyncPlayer( LPCBYTE pData, UINT uDataLen )
{
	KS2C_SYNC_PLAYER* pReceived = (KS2C_SYNC_PLAYER*)pData;
	// CheckSize
	QCONFIRM_RET_FALSE(_offsetof(KS2C_SYNC_PLAYER, sVarSync.aMapVarSet) + sizeof(KMAP_VAR_VALUE) *
		(pReceived->sVarSync.wMapVarNum) == uDataLen);

	// TODO: improve
	KPlayer* pPlayer = g_cPlayerMgr.GetById(pReceived->dwPlayerId);
	if (pPlayer)
	{
		pPlayer->m_cPlayerClient.LoadSyncVarOther(pReceived->sVarSync);
		pPlayer->SetPosition(pReceived->nX, pReceived->nY, pReceived->nZ);
		pPlayer->SetMoveState((KE_MOVE_STATE)pReceived->nMoveState);
		pPlayer->m_nVelocityXY = pReceived->nVelocityXY;
		pPlayer->m_nDestX = pReceived->nDestX;
		pPlayer->m_nDestY = pReceived->nDestY;
		pPlayer->m_nDestZ = pReceived->nDestZ;
		pPlayer->m_nFaceDirection = pReceived->nDirectionXY; // 暂时用速度方向代替
		pPlayer->SetKinName(pReceived->szKinName);
		pPlayer->SetKinId(pReceived->dwKinId);
		pPlayer->SetKinFigure(pReceived->dwKinFigure);

		QLogPrintf(LOG_LEVEL_WARNING, "[PlayerBaseProcess] %s :player_id=%d,already exists", __FUNCTION__, pReceived->dwPlayerId);
		return FALSE;
	}
	else
	{
		pPlayer = g_cOrpgWorld.AddPlayer(pReceived->szName, pReceived->dwPlayerId);
		QCONFIRM_RET_FALSE(pPlayer);

		pPlayer->m_cPlayerClient.LoadSyncVarOther(pReceived->sVarSync);

		// get client scene
		IKScene* pScene = g_pSceneMgr->FirstScene();
		QCONFIRM_RET_FALSE(pScene);

		pScene->AddPlayer(pPlayer, pReceived->nX, pReceived->nY, pReceived->nZ);
		pPlayer->SetMoveState((KE_MOVE_STATE)pReceived->nMoveState);
		pPlayer->m_nVelocityXY = pReceived->nVelocityXY;
		pPlayer->m_nDestX = pReceived->nDestX;
		pPlayer->m_nDestY = pReceived->nDestY;
		pPlayer->m_nDestZ = pReceived->nDestZ;
		pPlayer->m_nFaceDirection = pReceived->nDirectionXY; // 暂时用速度方向代替
		pPlayer->SetKinName(pReceived->szKinName);
		pPlayer->SetKinId(pReceived->dwKinId);
		pPlayer->SetKinFigure(pReceived->dwKinFigure);
		pPlayer->FireEvent(emKOBJEVENTTYPE_CHARACTER_ENTER_SCENE, pPlayer->GetId(), FALSE, 0);
		return TRUE;
	}

	return TRUE;
}
BOOL KPlayerBaseProcess::OnSyncSelf( LPCBYTE pData, UINT uDataLen )
{
	KS2C_SYNC_SELF* pSData = (KS2C_SYNC_SELF* )pData;

	g_cOrpgWorld.m_dwClientSceneId = pSData->dwSceneId;

	KPlayer* pPlayer = g_cPlayerMgr.GetById(g_cOrpgWorld.m_dwClientPlayerId);
	QCONFIRM_RET_FALSE(pPlayer);
	
	// 为了加载地图时,加快3D地图的加载所作的优化
	pPlayer->m_nX = pSData->nX;
	pPlayer->m_nY = pSData->nY;
	pPlayer->m_nZ = pSData->nZ;
	pPlayer->m_nFaceDirection = pSData->nDirectionXY;

	IKScene* pScene = g_cOrpgWorld.LoadScene(pSData->dwSceneId);
	QCONFIRM_RET_FALSE(pScene);

	//modify by wdb
	const KSCENE_CONFIG* pSceneCfg = g_pSceneMgr->GetSceneInfo(g_cOrpgWorld.m_dwClientSceneId);
	QCONFIRM_RET_FALSE(pSceneCfg);

	CHAR szNavPath[MAX_PATH] = {0};	
	snprintf(szNavPath,
			 countof(szNavPath) - 1,
			 "%s/%s%s",
			 pSceneCfg->szPath,
			 pSceneCfg->szClass,
			 KD_SCENE_NAVFILE_EXT);

	IKPlayerFindPath* pIKPlayerFindPath = GetPlayerFindPath(pPlayer);
	QCONFIRM_RET_FALSE(pIKPlayerFindPath);
	BOOL bLoadRet = pIKPlayerFindPath->LoadNavPath(szNavPath);
	if (!bLoadRet)
	{
		QLogPrintf(LOG_INFO, "Load Scene Name:%s Navigate Path File %s Failed!\n", pSceneCfg->szClass, szNavPath);
	}

	pScene->AddPlayer(pPlayer, pSData->nX, pSData->nY, pSData->nZ);
	pPlayer->m_cPlayerClient.DynamicSceneFlag(pSData->nDynamicScene);
	pPlayer->m_nDirectionXY = pSData->nDirectionXY;
	pPlayer->m_nFaceDirection = pSData->nDirectionXY;
	pPlayer->m_sMoveCtrl.nMoveCount = 0;

	pPlayer->FireEvent(emKOBJEVENTTYPE_CHARACTER_ENTER_SCENE, pPlayer->GetId(), FALSE, 0);

	return TRUE;
}