Ejemplo n.º 1
0
KPlayer* KPlayerMgr::Add2(LPCSTR pszName, DWORD dwId /*= KD_BAD_ID*/ )
{
	INT nIndex = m_cObjMgr.Add(dwId);

	KPlayer* pPlayer = m_cObjMgr.GetByIndex(nIndex);
	QCONFIRM_RET_FALSE(pPlayer);

	BOOL bOk = pPlayer->Init(nIndex, pszName);
	QCONFIRM_RET_FALSE(bOk && "Player Init Failed!");

	// 名字到对象映射表
	m_mapNameToPlayer.insert(std::map<QString, KPlayer*>::value_type(pPlayer->GetStrName(), pPlayer));

	return pPlayer;
}
Ejemplo n.º 2
0
INT KPlayerMgr::Add(LPCSTR pszName, DWORD dwId /*= KD_BAD_ID*/ )
{
	INT nIndex = m_cObjMgr.Add(dwId);

	KPlayer* pPlayer = m_cObjMgr.GetByIndex(nIndex);
	QCONFIRM_RET_FALSE(pPlayer);

	// TODO: 人物创建时应该先SyncToNeighborPlayers,否则周围玩家的SetVar会失效 kk

	BOOL bOk = pPlayer->Init(nIndex, pszName);
	QCONFIRM_RET_FALSE(bOk && "Player Init Failed!");

	// 名字到对象映射表
	m_mapNameToPlayer.insert(std::map<QString, KPlayer*>::value_type(pPlayer->GetStrName(), pPlayer));

	return nIndex;
}
Ejemplo n.º 3
0
KPlayer* KSO3World::NewPlayer(DWORD dwPlayerID)
{
    KPlayer*    pResult         = NULL;
	BOOL        bRetCode        = false;
	KPlayer*    pPlayer         = NULL;
    BOOL        bRegisterFlag   = false;
    BOOL        bInitFlag       = false;

	assert(dwPlayerID != ERROR_ID);

    pPlayer = KMemory::New<KPlayer>();
    KGLOG_PROCESS_ERROR(pPlayer);

    bRetCode = g_pSO3World->m_PlayerSet.Register(pPlayer, dwPlayerID);
    KGLOG_PROCESS_ERROR(bRetCode);
    bRegisterFlag = true;

	bRetCode = pPlayer->Init();
	KGLOG_PROCESS_ERROR(bRetCode);
    bInitFlag = true;

    pResult = pPlayer;
Exit0:
    if (pResult == NULL)
    {
        if (bInitFlag)
        {
            pPlayer->UnInit();
            bInitFlag = false;
        }

        if (bRegisterFlag)
        {
            g_pSO3World->m_PlayerSet.Unregister(pPlayer);
            bRegisterFlag = false;
        }

        if (pPlayer != NULL)
        {
            KMemory::Delete(pPlayer);
            pPlayer = NULL;
        }
    }
	return pResult;
}