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::OnSyncJumpTo( LPCBYTE pData, UINT uDataLen )
{
	KS2C_SYNC_JUMP_TO* pReceived = (KS2C_SYNC_JUMP_TO*)pData;

	KPlayer* pPlayer = g_cPlayerMgr.GetById(pReceived->dwId);
	QCONFIRM_RET_FALSE(pPlayer);

	pPlayer->SetPosition(pReceived->nX, pReceived->nY, pReceived->nZ);
	pPlayer->JumpTo(pReceived->nDestX, pReceived->nDestY, pReceived->nDestZ);

	return TRUE;
}
BOOL KPlayerBaseProcess::OnSyncAdjustMove( LPCBYTE pData, UINT uDataLen )
{
	KS2C_SYNC_ADJUST_MOVE* pReceived = (KS2C_SYNC_ADJUST_MOVE*)pData;

	//cprintf("Adjust: %d\n", pPak->nMoveCount);

	KPlayer* pPlayer = g_cPlayerMgr.GetById(g_cOrpgWorld.m_dwClientPlayerId);
	QCONFIRM_RET_FALSE(pPlayer);

	//if (pReceived->nMoveCount < pPlayer->m_sMoveCtrl.nMoveCount || pPlayer->m_pScene == NULL)
	//{
	//	QLogPrintf(
	//	    LOG_DEBUG, "[move] apply adjust(%d < %d)", 
	//	    pReceived->nMoveCount, pPlayer->m_sMoveCtrl.nMoveCount
	//	);

	//	DoApplyMoveAdjust();
	//	goto EXIT0;
	//}

	INT nX = 0, nY = 0, nZ = 0;
	pPlayer->GetPosition(nX, nY, nZ);

	{
		printf("[MoveAdjust] S[%d-%d],c[%d,%d,%d]s[%d,%d,%d],F[%d-%d] Diff[%d]\n",
			pPlayer->m_eMoveState,
			pReceived->nMoveState,
			nX, nY, nZ, 
			pReceived->nX, pReceived->nY, pReceived->nZ, 
			g_cOrpgWorld.m_dwLogicFrames, pReceived->dwVirtualFrame,
			g_cOrpgWorld.m_dwLogicFrames - pReceived->dwVirtualFrame);
	}

	pPlayer->SetPosition(pReceived->nX, pReceived->nY, pReceived->nZ);
	pPlayer->SetMoveState((KE_MOVE_STATE)pReceived->nMoveState);
	pPlayer->m_nVelocityXY = pReceived->nVelocityXY;
	pPlayer->m_nDirectionXY = pReceived->nDirectionXY;
	pPlayer->m_nDestX = pReceived->nDestX;
	pPlayer->m_nDestY = pReceived->nDestY;
	pPlayer->m_nDestZ = pReceived->nDestZ;

	if (pReceived->dwVirtualFrame < g_cOrpgWorld.m_dwLogicFrames)
	{
		pPlayer->ForwardPosition(g_cOrpgWorld.m_dwLogicFrames - pReceived->dwVirtualFrame);
	}

EXIT0:
	return TRUE;
}