int NFCCreateRoleModule::OnLoadRoleFinalEvent( const NFIDENTID& object, const int nEventID, const NFIValueList& var ) { if ( 9 != var.GetCount() ) { return -1; } //赋予属性 const char* pstrAccount = var.StringVal( 0 ); NFCValueList valueInfo; valueInfo << pstrAccount; int nCount = 0; for ( int i = 1; i <= 7; i += 2 ) { const char* pstrRoleName = var.StringVal( i ); if ( strlen( pstrRoleName ) > 0 ) { //看容器中是否已经存在,存在则不创建 NFCValueList varHallObjectList; NFCValueList varHalvalueInfo; varHalvalueInfo << pstrRoleName; int nHallObjectCount = m_pKernelModule->GetObjectByProperty( mnRoleHallContainer, "RoleName", varHalvalueInfo, varHallObjectList ); if ( nHallObjectCount > 0 ) { for ( int j = 0; j < varHallObjectList.GetCount(); j++ ) { m_pKernelModule->LogErrorObject( varHallObjectList.ObjectVal( j ) ); m_pKernelModule->DestroyObject( varHallObjectList.ObjectVal( j ) ); } } GTProperty* gtPproperty = m_pElementInfoModule->GetPropertyManager( "Scene0" )->GetElement( "RelivePos" ); const char* pstrRelivePos = gtPproperty->QueryString(); NFCValueList valueRelivePos( pstrRelivePos, "," ); char szConfigIindex[MAX_PATH] = { 0 }; sprintf( szConfigIindex, "%d", var.IntVal( i + 1 ) ); NFCValueList arg; arg << "Account" << pstrAccount; arg << "RoleName" << pstrRoleName; arg << "SceneID" << mnRoleHallContainer; arg << "X" << atof( valueRelivePos.StringVal( 0 ) ); arg << "Y" << atof( valueRelivePos.StringVal( 1 ) ); arg << "Z" << atof( valueRelivePos.StringVal( 2 ) ); m_pKernelModule->CreateObject( 0, mnRoleHallContainer, 0, "Player", szConfigIindex, arg ); nCount++; } } char szInfo[MAX_PATH] = { 0 }; sprintf( szInfo, "Load data final, %s: have %d role.", pstrAccount, nCount ); m_pKernelModule->LogInfo( szInfo ); return 0; }
int NFCCreateRoleModule::OnLoadRoleBeginEvent( const NFIDENTID& object, const int nEventID, const NFIValueList& var ) { //直接从NOSQL数据库拉 const char* pstrAccount = var.StringVal( 0 ); NFCValueList roleLlist; if ( m_pNoSqlModule->QueryAccountRoleList( pstrAccount, roleLlist ) > 0 ) { for ( int i = 0; i < roleLlist.GetCount(); i++ ) { const char* pstrRoleName = roleLlist.StringVal( i ); if ( strlen( pstrRoleName ) > 0 ) { //看容器中是否已经存在,存在则不创建 NFCValueList varHallObjectList; NFCValueList varHalvalueInfo; varHalvalueInfo << pstrRoleName; int nHallObjectCount = m_pKernelModule->GetObjectByProperty( mnRoleHallContainer, "RoleName", varHalvalueInfo, varHallObjectList ); if ( nHallObjectCount > 0 ) { for ( int j = 0; j < varHallObjectList.GetCount(); j++ ) { m_pKernelModule->LogErrorObject( varHallObjectList.ObjectVal( j ) ); m_pKernelModule->DestroyObject( varHallObjectList.ObjectVal( j ) ); } } GTProperty* gtPproperty = m_pElementInfoModule->GetPropertyManager( "Scene0" )->GetElement( "RelivePos" ); const char* pstrRelivePos = gtPproperty->QueryString(); NFCValueList valueRelivePos( pstrRelivePos, "," ); char szConfigIindex[MAX_PATH] = { 0 }; sprintf( szConfigIindex, "%d", var.IntVal( i + 1 ) ); NFCValueList arg; arg << "Account" << pstrAccount; arg << "RoleName" << pstrRoleName; arg << "SceneID" << mnRoleHallContainer; arg << "X" << atof( valueRelivePos.StringVal( 0 ) ); arg << "Y" << atof( valueRelivePos.StringVal( 1 ) ); arg << "Z" << atof( valueRelivePos.StringVal( 2 ) ); m_pKernelModule->CreateObject( 0, mnRoleHallContainer, 0, "Player", szConfigIindex, arg ); } } } return 0; }
int NFCSceneProcessModule::OnEnterSceneEvent( const NFIDENTID& self, const int nEventID, const NFIDataList& var ) { if ( var.GetCount() != 4 || !var.TypeEx(TDATA_TYPE::TDATA_OBJECT, TDATA_TYPE::TDATA_INT, TDATA_TYPE::TDATA_INT, TDATA_TYPE::TDATA_INT, TDATA_TYPE::TDATA_UNKNOWN)) { return 0; } NFIDENTID ident = var.Object( 0 ); int nType = var.Int( 1 ); int nTargetScene = var.Int( 2 ); int nTargetGroupID = var.Int( 3 ); int nOldSceneID = m_pKernelModule->GetPropertyInt( self, "SceneID" ); char szSceneID[MAX_PATH] = {0}; sprintf(szSceneID, "%d", nTargetScene); #ifdef NF_USE_ACTOR int nActorID = m_pElementInfoModule->GetPropertyInt(szSceneID, "ActorID"); int nSelfActorID = pPluginManager->GetActorID(); if (nSelfActorID != nActorID) { m_pLogModule->LogNormal(NFILogModule::NLL_ERROR_NORMAL, ident, "target scene not runing in this server", nTargetScene); return 1; #endif if ( self != ident ) { m_pLogModule->LogNormal(NFILogModule::NLL_ERROR_NORMAL, ident, "you are not you self, but you want to entry this scene", nTargetScene); return 1; } const int nNowContainerID = m_pKernelModule->GetPropertyInt(self, "SceneID"); const int nNowGroupID = m_pKernelModule->GetPropertyInt(self, "GroupID"); if (nNowContainerID == nTargetScene && nNowGroupID == nTargetGroupID) { //本来就是这个层这个场景就别切换了 m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, ident, "in same scene and group but it not a clone scene", nTargetScene); return 1; } nTargetGroupID = CreateCloneScene( nTargetScene, nTargetGroupID, "File.xml", NFCDataList() ); if ( nTargetGroupID <= 0 ) { m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, ident, "CreateCloneScene failed", nTargetScene); return 0; } //得到坐标 float fX = 0.0f; float fY = 0.0f; float fZ = 0.0f; const std::string& strRelivePosList = m_pElementInfoModule->GetPropertyString(szSceneID, "RelivePos"); NFCDataList valueRelivePosList( strRelivePosList.c_str(), ";" ); if ( valueRelivePosList.GetCount() >= 1 ) { NFCDataList valueRelivePos( valueRelivePosList.String( 0 ).c_str(), "," ); if ( valueRelivePos.GetCount() == 3 ) { fX = boost::lexical_cast<float>( valueRelivePos.String( 0 ) ); fY = boost::lexical_cast<float>( valueRelivePos.String( 1 ) ); fZ = boost::lexical_cast<float>( valueRelivePos.String( 2 ) ); } } NFCDataList xSceneResult( var ); xSceneResult.Add( fX ); xSceneResult.Add( fY ); xSceneResult.Add( fZ ); m_pEventProcessModule->DoEvent( self, NFED_ON_OBJECT_ENTER_SCENE_BEFORE, xSceneResult ); if(!m_pKernelModule->SwitchScene( self, nTargetScene, nTargetGroupID, fX, fY, fZ, 0.0f, var )) { m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, ident, "SwitchScene failed", nTargetScene); return 0; } xSceneResult.Set(3, NFINT64(nTargetGroupID));//spicial m_pEventProcessModule->DoEvent( self, NFED_ON_OBJECT_ENTER_SCENE_RESULT, xSceneResult ); return 0; } int NFCSceneProcessModule::OnLeaveSceneEvent( const NFIDENTID& object, const int nEventID, const NFIDataList& var ) { if (1 != var.GetCount() || !var.TypeEx(TDATA_TYPE::TDATA_INT, TDATA_TYPE::TDATA_UNKNOWN)) { return -1; } NFINT32 nOldGroupID = var.Int(0); NF_SHARE_PTR<NFIObject> pObject = m_pKernelModule->GetObject(object); if (pObject.get() && nOldGroupID > 0) { int nContainerID = pObject->GetPropertyInt("SceneID"); if (GetCloneSceneType(nContainerID) == SCENE_TYPE_MAINLINE_CLONE) { m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, object, "DestroyCloneSceneGroup", nOldGroupID); DestroyCloneScene(nContainerID, nOldGroupID, var); } } return 0; } int NFCSceneProcessModule::OnObjectClassEvent( const NFIDENTID& self, const std::string& strClassName, const CLASS_OBJECT_EVENT eClassEvent, const NFIDataList& var ) { if ( strClassName == "Player" ) { if ( CLASS_OBJECT_EVENT::COE_DESTROY == eClassEvent ) { //如果在副本中,则删除他的那个副本 int nContainerID = m_pKernelModule->GetPropertyInt(self, "SceneID"); if (GetCloneSceneType(nContainerID) == SCENE_TYPE_MAINLINE_CLONE) { int nGroupID = m_pKernelModule->GetPropertyInt(self, "GroupID"); m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, self, "DestroyCloneSceneGroup", nGroupID); DestroyCloneScene(nContainerID, nGroupID, NFCDataList()); } } else if ( CLASS_OBJECT_EVENT::COE_CREATE_HASDATA == eClassEvent ) { m_pEventProcessModule->AddEventCallBack( self, NFED_ON_CLIENT_ENTER_SCENE, this, &NFCSceneProcessModule::OnEnterSceneEvent ); m_pEventProcessModule->AddEventCallBack( self, NFED_ON_CLIENT_LEAVE_SCENE, this, &NFCSceneProcessModule::OnLeaveSceneEvent ); } } return 0; } E_SCENE_TYPE NFCSceneProcessModule::GetCloneSceneType( const int nContainerID ) { char szSceneIDName[MAX_PATH] = { 0 }; sprintf( szSceneIDName, "%d", nContainerID ); if (m_pElementInfoModule->ExistElement(szSceneIDName)) { return (E_SCENE_TYPE)m_pElementInfoModule->GetPropertyInt(szSceneIDName, "SceneType"); } return SCENE_TYPE_ERROR; }
int NFCCreateRoleModule::OnCreateRoleEvent( const NFIDENTID& object, const int nEventID, const NFIValueList& var ) { if ( 6 != var.GetCount() ) { return 0; } //如果有4个玩家则不让创建 const char* pstrAccountName = var.StringVal( 0 ); const char* pstrRoleName = var.StringVal( 1 ); int nRoleSex = var.IntVal( 2 ); int nRoleJob = var.IntVal( 3 ); int nRoleRace = var.IntVal( 4 ); int nRoleCamp = var.IntVal( 5 ); NFCValueList roleLlist; if ( m_pNoSqlModule->QueryAccountRoleList( pstrAccountName, roleLlist ) >= 4 ) //if (m_pDataBaseModule->QueryAccountRoleList(pstrAccountName, roleLlist) >= 4) { return 0; } ////////////////////////////////////////////////////////////////////////// //创建人物直接走了数据库 ////////////////////////////////////////////////////////////////////////// if ( m_pNoSqlModule->CreateRole( pstrAccountName, pstrRoleName ) <= 0 ) //if (m_pDataBaseModule->CreateRole(pstrAccountName, pstrRoleName) <= 0) { return 0; } NFCValueList varPropertyKeyList; NFCValueList varPropertyValueList; varPropertyKeyList << "RoleName" << "Sex" << "Job" << "Race" << "Camp" << "SceneID" << "LastContainerID" << "ClassName"; varPropertyValueList << pstrRoleName << nRoleSex << nRoleJob << nRoleRace << nRoleCamp << mnRoleHallContainer << 1 << "Player"; int nConfigName = nRoleJob + nRoleSex * 10; char szConfigName[MAX_PATH] = { 0 }; sprintf( szConfigName, "%d", nConfigName ); //弄到所有的属性 GTPropertyManager* pConfigPropertyManager = m_pElementInfoModule->GetPropertyManager( szConfigName ); if ( pConfigPropertyManager ) { GTProperty* pConfigPropertyInfo = pConfigPropertyManager->First(); while ( pConfigPropertyInfo ) { //看属性是否需要保存,不需要保存的就别村 if ( !pConfigPropertyInfo->GetSave() ) { pConfigPropertyInfo = pConfigPropertyManager->Next(); continue; } //这个属性RoleName是玩家的,因此,这里不能有RoleName const NFIValueList& valueList = pConfigPropertyInfo->GetValue(); if ( 0 != strcmp( pConfigPropertyInfo->GetKey(), "RoleName" ) && 0 != strcmp( pConfigPropertyInfo->GetKey(), "Sex" ) && 0 != strcmp( pConfigPropertyInfo->GetKey(), "Job" ) && 0 != strcmp( pConfigPropertyInfo->GetKey(), "Race" ) && 0 != strcmp( pConfigPropertyInfo->GetKey(), "Camp" ) && 0 != strcmp( pConfigPropertyInfo->GetKey(), "Account" ) && 0 != strcmp( pConfigPropertyInfo->GetKey(), "SceneID" ) && 0 != strcmp( pConfigPropertyInfo->GetKey(), "LastContainerID" ) && 0 != strcmp( pConfigPropertyInfo->GetKey(), "ClassName" ) ) { varPropertyKeyList << pConfigPropertyInfo->GetKey(); varPropertyValueList.Append( valueList, 0, 1 ); } pConfigPropertyInfo = pConfigPropertyManager->Next(); } } varPropertyKeyList << "RoleName"; varPropertyValueList << pstrRoleName; varPropertyKeyList << "Sex"; varPropertyValueList << nRoleSex; varPropertyKeyList << "Job"; varPropertyValueList << nRoleJob; varPropertyKeyList << "Race"; varPropertyValueList << nRoleRace; varPropertyKeyList << "Camp"; varPropertyValueList << nRoleCamp; varPropertyKeyList << "SceneID"; varPropertyValueList << mnRoleHallContainer; varPropertyKeyList << "LastContainerID"; varPropertyValueList << 1;//1号场景为新手村 varPropertyKeyList << "ClassName"; varPropertyValueList << "Player"; varPropertyKeyList << "Level"; varPropertyValueList << 1; m_pNoSqlModule->SetRoleProperty( pstrRoleName, varPropertyKeyList, varPropertyValueList ); ////////////////////////////////////////////////////////////////////////// GTProperty* gtPproperty = m_pElementInfoModule->GetPropertyManager( "Scene0" )->GetElement( "RelivePos" ); const char* pstrRelivePos = gtPproperty->QueryString(); NFCValueList valueRelivePos( pstrRelivePos, "," ); NFCValueList arg; arg << "Account" << pstrAccountName; arg << "RoleName" << pstrRoleName; arg << "SceneID" << mnRoleHallContainer; arg << "X" << atof( valueRelivePos.StringVal( 0 ) ); arg << "Y" << atof( valueRelivePos.StringVal( 1 ) ); arg << "Z" << atof( valueRelivePos.StringVal( 2 ) ); m_pKernelModule->CreateObject( 0, mnRoleHallContainer, 0, "Player", szConfigName, arg ); //nosql 则不需要这样了 //m_pEventProcessModule->DoEvent(0, NFED_ON_DATABASE_SERVER_LOADROE_BEGIN, NFCValueList() << pstrAccountName); return 0; }
int NFCSceneProcessModule::OnEnterSceneEvent( const NFGUID& self, const int nEventID, const NFIDataList& var ) { if ( var.GetCount() != 4 || !var.TypeEx(TDATA_TYPE::TDATA_OBJECT, TDATA_TYPE::TDATA_INT, TDATA_TYPE::TDATA_INT, TDATA_TYPE::TDATA_INT, TDATA_TYPE::TDATA_UNKNOWN)) { return 0; } const NFGUID ident = var.Object( 0 ); const int nType = var.Int( 1 ); const int nTargetScene = var.Int( 2 ); const int nTargetGroupID = var.Int( 3 ); const int nNowSceneID = m_pKernelModule->GetPropertyInt( self, NFrame::Player::SceneID()); const int nNowGroupID = m_pKernelModule->GetPropertyInt(self, NFrame::Player::GroupID()); if ( self != ident ) { m_pLogModule->LogNormal(NFILogModule::NLL_ERROR_NORMAL, ident, "you are not you self, but you want to entry this scene", nTargetScene); return 1; } if (nNowSceneID == nTargetScene && nTargetGroupID == nNowGroupID) { //本来就是这个层这个场景就别切换了 m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, ident, "in same scene and group but it not a clone scene", nTargetScene); return 1; } //每个玩家,一个副本 NFINT64 nNewGroupID = 0; if (nTargetGroupID <= 0) { nNewGroupID = CreateCloneScene( nTargetScene ); } else { nNewGroupID = nTargetGroupID; } if ( nNewGroupID <= 0 ) { m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, ident, "CreateCloneScene failed", nTargetScene); return 0; } //得到坐标 double fX = 0.0; double fY = 0.0; double fZ = 0.0; const std::string strSceneID = lexical_cast<std::string>(nTargetScene); const std::string& strRelivePosList = m_pElementInfoModule->GetPropertyString(strSceneID, NFrame::Scene::RelivePos()); NFCDataList valueRelivePosList( strRelivePosList.c_str(), ";" ); if ( valueRelivePosList.GetCount() >= 1 ) { NFCDataList valueRelivePos( valueRelivePosList.String( 0 ).c_str(), "," ); if ( valueRelivePos.GetCount() == 3 ) { fX = lexical_cast<double>( valueRelivePos.String( 0 ) ); fY = lexical_cast<double>( valueRelivePos.String( 1 ) ); fZ = lexical_cast<double>( valueRelivePos.String( 2 ) ); } } NFCDataList xSceneResult( var ); xSceneResult.Add( fX ); xSceneResult.Add( fY ); xSceneResult.Add( fZ ); m_pKernelModule->DoEvent( self, NFED_ON_OBJECT_ENTER_SCENE_BEFORE, xSceneResult ); if(!m_pKernelModule->SwitchScene( self, nTargetScene, nNewGroupID, fX, fY, fZ, 0.0f, var )) { m_pLogModule->LogNormal(NFILogModule::NLL_INFO_NORMAL, ident, "SwitchScene failed", nTargetScene); return 0; } xSceneResult.Add( nNewGroupID ); m_pKernelModule->DoEvent( self, NFED_ON_OBJECT_ENTER_SCENE_RESULT, xSceneResult ); return 0; }