コード例 #1
0
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;
}
コード例 #2
0
BOOL KPlayerBaseProcess::PtcPlayerData( LPCBYTE pData, UINT uDataLen )
{
	KS2C_PLAYERDATA* pSData = (KS2C_PLAYERDATA* )pData;
	// CheckSize
	QCONFIRM_RET_FALSE(_offsetof(KS2C_PLAYERDATA, sVarSync.aMapVarSet) + sizeof(KMAP_VAR_VALUE) *
		(pSData->sVarSync.wMapVarNum) == uDataLen);

	Q_Printl("Received Player Data. Client Player Rolename: " << pSData->szPlayerName <<
		" Id:" << pSData->dwPlayerId);

	g_cOrpgWorld.m_dwClientPlayerId = pSData->dwPlayerId;
	g_cOrpgWorld.m_dwLogicFrames = pSData->dwLogicFrames;
	g_cOrpgWorld.m_nServerId = pSData->nServerId;

    InitStartTimeEvaluation(&g_cOrpgWorld.m_StartTimeEvaluation);
    g_cOrpgWorld.m_nStartLoop = g_cOrpgWorld.m_dwLogicFrames;
    g_cOrpgWorld.m_nGSGameLoop = g_cOrpgWorld.m_dwLogicFrames;
    g_cOrpgWorld.m_dwStartTime = timeGetTime();
	g_cOrpgWorld.m_dwServerTime = pSData->dwServerTime;

	KPlayer* pPlayer = g_cOrpgWorld.AddPlayer(pSData->szPlayerName, pSData->dwPlayerId);
	QCONFIRM_RET_FALSE(pPlayer);
	g_cScriptManager.SetMe((QLunaBase*)pPlayer->GetScriptInterface());

	pPlayer->SetKinId(0);
	pPlayer->SetKinName("");
	pPlayer->SetKinFigure(0);
	pPlayer->m_cPlayerClient.LoadSyncVarSelf(pSData->sVarSync);

	g_cOrpgWorld.m_cEventCreator.FireEvent(emKOBJEVENTTYPE_PLAYER_LOGIN, g_cOrpgWorld.m_dwClientPlayerId, 0, 0);		// by houxuan, 玩家登陆事件

	// 通知服务端已完成加载
	DoSyncEnd();

	return TRUE;
}