BOOL KPlayerMgr::RemoveById( DWORD dwId ) { KPlayer* pPlayer = m_cObjMgr.GetById(dwId); QCONFIRM_RET_FALSE(pPlayer); // 擦除映射表 m_mapNameToPlayer.erase(pPlayer->GetStrName()); pPlayer->Uninit(); return m_cObjMgr.Remove(dwId); }
BOOL KPlayerMgr::RemoveByIndex( INT nIndex ) { KPlayer* pPlayer = m_cObjMgr.GetByIndex(nIndex); QCONFIRM_RET_FALSE(pPlayer); // 擦除映射表 m_mapNameToPlayer.erase(pPlayer->GetStrName()); pPlayer->Uninit(); return m_cObjMgr.RemoveByIndex(nIndex); }
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; }
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; }