bool NFCSceneProcessModule::AfterInit() { //初始化场景容器 #ifdef NF_USE_ACTOR int nSelfActorID = pPluginManager->GetActorID(); #endif NF_SHARE_PTR<NFILogicClass> pLogicClass = m_pLogicClassModule->GetElement("Scene"); if (pLogicClass.get()) { NFList<std::string>& list = pLogicClass->GetConfigNameList(); std::string strData; bool bRet = list.First(strData); while (bRet) { int nSceneID = boost::lexical_cast<int>(strData); const std::string& strFilePath = m_pElementInfoModule->GetPropertyString( strData, "FilePath" ); const int nActorID = m_pElementInfoModule->GetPropertyInt( strData, "ActorID" ); #ifdef NF_USE_ACTOR if ( nActorID == nSelfActorID && nSceneID > 0 ) #else if ( nSceneID > 0 ) #endif { LoadInitFileResource( nSceneID ); m_pKernelModule->CreateContainer( nSceneID, strData ); if ( E_SCENE_TYPE::SCENE_TYPE_NORMAL == GetCloneSceneType(nSceneID) ) { for (int i = 1; i <= mnContainerLine; ++i) { const int nTargetGroupID = m_pKernelModule->RequestGroupScene( nSceneID); const int nCreateGroupID = CreateCloneScene( nSceneID, nTargetGroupID, "File.xml", NFCDataList() ); if ( nCreateGroupID == nTargetGroupID) { CreateContinerObjectByFile( nSceneID, nTargetGroupID, "File.xml" ); } } } } bRet = list.Next(strData); } } return true; }
bool NFCSceneProcessModule::ApplyCloneGroup(const int nSceneID, int& nGroupID) { nGroupID = CreateCloneScene( nSceneID ); return true; }
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 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; }