⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 field.cpp

📁 奇迹世界 部分源代码奇迹世界 部分源代码奇迹世界 部分源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:

		POS pos = pInfo->GetNeighborSectorInfoList().GetFirstPos();
		SectorInfo * pNextInfo = NULL;
		while( (pNextInfo = pInfo->GetNeighborSectorInfoList().GetNextPos( pos )) != NULL )
		{
			pSector = GetSector( pNextInfo->GetSectorIndex() );
			if( !pSector )	continue;

			pSector->SendExPacketToSector( dwNumberOfMessages, pMsg, pwSize );
		}
	}
	else
	{
		return SendExPacketToAll( dwNumberOfMessages, pMsg, pwSize, dwMyObjKey );
	}

	return RC::RC_SEND_SUCCESS;
}

RC::ePACKET_SEND_RESULT Field::SendExPacketToAll( DWORD dwNumberOfMessages, BYTE **pMsg, WORD *pwSize, DWORD dwMyObjKey )
{
	Sector *pSector;	SectorGroup *pSectorGroup;
	for( SECTORGROUP_ITERATOR it = m_pSectorGroupList->Begin(); it != m_pSectorGroupList->End(); ++it )
	{
		pSectorGroup = *it;
		if( !pSectorGroup->GetReferenceCount() )	continue;

		for( SECTOR_ITERATOR itr = pSectorGroup->Begin(); itr != pSectorGroup->End(); ++itr )
		{
			pSector = *itr;
			pSector->SendExPacketToSectorExceptMe( dwNumberOfMessages, pMsg, pwSize, dwMyObjKey );
		}
	}

	return RC::RC_SEND_SUCCESS;
}

//////////////////////////////////////////////////////////////////////////
/// 矫唱府坷
/// 1. 单捞磐 檬扁拳父 肯丰等 Object客 Field俊 困摹且 困摹甫 逞变促.
/// 2. 捞悼苞 包访等 Object悸泼阑 窍绊 Field俊档 沥焊甫 悸泼茄促.
//////////////////////////////////////////////////////////////////////////
BOOL Field::EnterField( Object* pObject, WzVector * pwzVec )
{
	ASSERT( pObject );

	// MapNpc老 版快俊绰 谅钎蜡瓤己阑 眉农救茄促.
	if( (pObject->GetObjectType() & MAPNPC_OBJECT) != MAPNPC_OBJECT )
	{
		// 努扼捞攫飘啊 焊辰 谅钎狼 蜡瓤己 八荤 => 泅犁 哎 荐 乐绰 镑牢瘤 酒囱 瘤 眉农 鞘夸!!!
		if( !IsMovableCoordinates( pwzVec ) )
		{
			SUNLOG( eCRITICAL_LOG, "[EnterField] 肋给等 困摹氦磐啊 逞绢吭促" );
			return FALSE;
		}
	}

	pObject->OnEnterField(this, pwzVec);	

	DWORD dwSectorIndex = pObject->GetSectorIndex();
	Sector *pSector = GetSector( dwSectorIndex );
	if( !pSector )
	{
		SUNLOG( eCRITICAL_LOG,  "[Field::EnterField] Invalid SectorIndex[%d/%d] ", dwSectorIndex, m_vecTotalSector.size() );
		return FALSE;
	}

	RC::eSECTOR_REULT result = pSector->AddObject( pObject, TRUE );
	if( result != RC::RC_SECTOR_ADD_SUCCESS )
	{
		SUNLOG( eCRITICAL_LOG,  "[Field::EnterField] AddObject Fail![%d],[type:%u]", result, pObject->GetObjectKey() );
		return TRUE;
	}

	// 泅犁 Zone 鸥涝阑 掘绢辑 付阑牢瘤 眉农茄促.
	SERVER_ENV * pServerEnv = g_pGameServer->GetFileParser()->GetServerEnv();
	BOOL bVillage = FALSE;
	if( pServerEnv->bVillageRenderInfo )
	{
		const sMAPINFO *pMapInfo = m_pMap->GetMapInfo()->GetMapInfo();
		bVillage = pMapInfo->byMKind == eZONETYPE_VILLAGE;
	}

	if( m_pFieldInfo->GetViewPort() )
	{
		// 货肺款 某腐磐啊 殿厘沁澜阑 冀磐俊 舅妨霖促.
		pSector->SendAddObject( pObject, bVillage );

		// 冀磐狼 沥焊甫 殿厘某腐磐俊霸 舅妨霖促.
		pSector->SendAddSectorInfo( pObject, bVillage );

		// 冀磐狼 曼炼 敲饭捞绢 荐甫 刘啊矫挪促.
		IncreasePlayerReferenceCount( dwSectorIndex, pObject );

		// 牢立 冀磐俊霸 舅妨林绰 风凭
		SectorInfo * pInfo = m_pFieldInfo->GetSectorInfo( dwSectorIndex );
		ASSERT( pInfo );
		POS pos = pInfo->GetNeighborSectorInfoList().GetFirstPos();
		SectorInfo * pNextInfo = NULL;
		while( (pNextInfo = pInfo->GetNeighborSectorInfoList().GetNextPos( pos )) != NULL )
		{
			pSector = GetSector( pNextInfo->GetSectorIndex() );
			if( !pSector )	continue;

			pSector->SendAddObject( pObject, bVillage );
			pSector->SendAddSectorInfo( pObject, bVillage );
			IncreasePlayerReferenceCount( pNextInfo->GetSectorIndex(), pObject );
		}
	}
	else
	{
		Sector *pSector;	SectorGroup *pSectorGroup;
		for( SECTORGROUP_ITERATOR it = m_pSectorGroupList->Begin(); it != m_pSectorGroupList->End(); ++it )
		{
			pSectorGroup = *it;

			// NPC牢 版快俊绰 林函俊 敲饭捞绢啊 绝阑 版快 菩哦阑 焊尘 鞘夸啊 绝促.
			if( ( pObject->GetObjectType() & PLAYER_OBJECT ) != PLAYER_OBJECT )
			{
				if( !pSectorGroup->GetReferenceCount() )	continue;
			}

			for( SECTOR_ITERATOR itr = pSectorGroup->Begin(); itr != pSectorGroup->End(); ++itr )
			{
				pSector = *itr;
				// 货肺款 某腐磐啊 殿厘沁澜阑 冀磐俊 舅妨霖促.
				pSector->SendAddObject( pObject, bVillage );

				// 冀磐狼 沥焊甫 殿厘某腐磐俊霸 舅妨霖促.
				pSector->SendAddSectorInfo( pObject, bVillage );
			}
		}

		// 冀磐狼 曼炼 敲饭捞绢 荐甫 刘啊矫挪促.
		IncreasePlayerReferenceCount( dwSectorIndex, pObject );
		
		SectorInfo * pInfo = m_pFieldInfo->GetSectorInfo( dwSectorIndex );
		ASSERT( pInfo );
		POS pos = pInfo->GetNeighborSectorInfoList().GetFirstPos();
		SectorInfo * pNextInfo = NULL;
		while( (pNextInfo = pInfo->GetNeighborSectorInfoList().GetNextPos( pos )) != NULL )
		{
			IncreasePlayerReferenceCount( pNextInfo->GetSectorIndex(), pObject );
		}
	}

	return TRUE;
}

BOOL Field::EnterField_Dir( Object* pObject, WzVector * pwzVec, WORD wAngle )
{
	ASSERT( pObject );
//	ASSERT( NULL != pObject->GetField() );

	// 努扼捞攫飘啊 焊辰 谅钎狼 蜡瓤己 八荤 => 泅犁 哎 荐 乐绰 镑牢瘤 酒囱 瘤 眉农 鞘夸!!!
	if( !IsMovableCoordinates( pwzVec ) )
	{
		SUNLOG( eCRITICAL_LOG, "[EnterField_Dir] 肋给等 困摹氦磐啊 逞绢吭促" );
		return FALSE;
	}

	pObject->OnEnterField(this, pwzVec);	

	DWORD dwSectorIndex = pObject->GetSectorIndex();
	Sector *pSector = GetSector( dwSectorIndex );
	if( !pSector )
	{
		SUNLOG( eCRITICAL_LOG,  "[Field::EnterField_Dir] Invalid SectorIndex[%d/%d] ", dwSectorIndex, m_vecTotalSector.size() );
		return FALSE;
	}

	RC::eSECTOR_REULT result = pSector->AddObject( pObject, TRUE );
	if( result != RC::RC_SECTOR_ADD_SUCCESS )
	{
		SUNLOG( eCRITICAL_LOG, "[Field::EnterField] AddObject Fail![%d],[type:%u]", result, pObject->GetObjectKey() );
		return TRUE;
	}

	if( m_pFieldInfo->GetViewPort() )
	{
		// 货肺款 某腐磐啊 殿厘沁澜阑 冀磐俊 舅妨霖促.
		pSector->SendAddObject_Dir( pObject, wAngle );

		// 冀磐狼 沥焊甫 殿厘某腐磐俊霸 舅妨霖促.
		pSector->SendAddSectorInfo( pObject );

		// 冀磐狼 曼炼 敲饭捞绢 荐甫 刘啊矫挪促.
		IncreasePlayerReferenceCount( dwSectorIndex, pObject );

		// 牢立 冀磐俊霸 舅妨林绰 风凭
		SectorInfo * pInfo = m_pFieldInfo->GetSectorInfo( dwSectorIndex );
		ASSERT( pInfo );
		POS pos = pInfo->GetNeighborSectorInfoList().GetFirstPos();
		SectorInfo * pNextInfo = NULL;
		while( (pNextInfo = pInfo->GetNeighborSectorInfoList().GetNextPos( pos )) != NULL )
		{
			pSector = GetSector( pNextInfo->GetSectorIndex() );
			if( !pSector )	continue;

			pSector->SendAddObject_Dir( pObject, wAngle );
			pSector->SendAddSectorInfo( pObject );
			IncreasePlayerReferenceCount( pNextInfo->GetSectorIndex(), pObject );
		}
	}
	else
	{
		Sector *pSector;	SectorGroup *pSectorGroup;
		for( SECTORGROUP_ITERATOR it = m_pSectorGroupList->Begin(); it != m_pSectorGroupList->End(); ++it )
		{
			pSectorGroup = *it;

			// NPC牢 版快俊绰 林函俊 敲饭捞绢啊 绝阑 版快 菩哦阑 焊尘 鞘夸啊 绝促.
			if( ( pObject->GetObjectType() & PLAYER_OBJECT ) != PLAYER_OBJECT )
			{
				if( !pSectorGroup->GetReferenceCount() )	continue;
			}

			for( SECTOR_ITERATOR itr = pSectorGroup->Begin(); itr != pSectorGroup->End(); ++itr )
			{
				pSector = *itr;
				// 货肺款 某腐磐啊 殿厘沁澜阑 冀磐俊 舅妨霖促.
				pSector->SendAddObject_Dir( pObject, wAngle );

				// 冀磐狼 沥焊甫 殿厘某腐磐俊霸 舅妨霖促.
				pSector->SendAddSectorInfo( pObject );
			}
		}

		// 冀磐狼 曼炼 敲饭捞绢 荐甫 刘啊矫挪促.
		IncreasePlayerReferenceCount( dwSectorIndex, pObject );
		
		SectorInfo * pInfo = m_pFieldInfo->GetSectorInfo( dwSectorIndex );
		ASSERT( pInfo );
		POS pos = pInfo->GetNeighborSectorInfoList().GetFirstPos();
		SectorInfo * pNextInfo = NULL;
		while( (pNextInfo = pInfo->GetNeighborSectorInfoList().GetNextPos( pos )) != NULL )
		{
			IncreasePlayerReferenceCount( pNextInfo->GetSectorIndex(), pObject );
		}
	}

	return TRUE;
}


VOID Field::LeaveField( Object* pObject )
{
	ASSERT( pObject );

	DWORD dwSectorIndex = pObject->GetSectorIndex();
	Sector *pSector = GetSector( dwSectorIndex );
	if( !pSector )
	{
		SUNLOG( eCRITICAL_LOG,  "[Field::LeaveField] Invalid SectorIndex[%d/%d] ", dwSectorIndex, m_vecTotalSector.size() );
		return;
	}

	pObject->OnLeaveField();

	// NPC 府胶飘俊辑 力芭( NPC狼 OnLeaveField()救俊辑 RemoveNPC()甫 龋免窍搁 救等促. RemoveAllNPC() 龋免 矫 巩力啊 瞪 荐 乐促.)
	if( ( pObject->GetObjectType() & NPC_OBJECT ) == NPC_OBJECT )
	{
		RemoveNPC( (NPC*)pObject );
	}

	// 冀磐狼 坷宏璃飘 府胶飘俊辑 昏力
	RC::eSECTOR_REULT result = pSector->RemoveObject( pObject );
	if( result != RC::RC_SECTOR_REMOVE_SUCCESS )
	{
		SUNLOG( eCRITICAL_LOG,  "[Field::LeaveField] RemoveObject Fail![%d] ", result );
		SASSERT( NULL, "刮宽阑 阂矾 林技夸!" );
	}

	if( m_pFieldInfo->GetViewPort() )
	{
		pSector->SendRemoveObject( pObject );

		// 冀磐 曼炼 墨款泼阑 皑家矫挪促.
		DecreasePlayerReferenceCount( dwSectorIndex, pObject );

		// 牢立 冀磐俊霸 舅妨林绰 风凭
		SectorInfo * pInfo = m_pFieldInfo->GetSectorInfo( dwSectorIndex );
		ASSERT( pInfo );
		POS pos = pInfo->GetNeighborSectorInfoList().GetFirstPos();
		SectorInfo * pNextInfo = NULL;
		while( (pNextInfo = pInfo->GetNeighborSectorInfoList().GetNextPos( pos )) != NULL )
		{
			pSector = GetSector( pNextInfo->GetSectorIndex() );
			if( !pSector )	continue;

			if( RC::RC_SEND_SUCCESS != pSector->SendRemoveObject( pObject ) )
				continue;

			DecreasePlayerReferenceCount( pNextInfo->GetSectorIndex(), pObject );
		}
	}
	else
	{
		Sector *pSector;	SectorGroup *pSectorGroup;
		for( SECTORGROUP_ITERATOR it = m_pSectorGroupList->Begin(); it != m_pSectorGroupList->End(); ++it )
		{
			pSectorGroup = *it;
			if( !pSectorGroup->GetReferenceCount() )	continue;

			for( SECTOR_ITERATOR itr = pSectorGroup->Begin(); itr != pSectorGroup->End(); ++itr )
			{
				pSector = *itr;
				pSector->SendRemoveObject( pObject );
			}
		}

		// 冀磐 曼炼 墨款泼阑 皑家矫挪促.
		DecreasePlayerReferenceCount( dwSectorIndex, pObject );

		// 牢立 冀磐俊霸 舅妨林绰 风凭
		SectorInfo * pInfo = m_pFieldInfo->GetSectorInfo( dwSectorIndex );
		ASSERT( pInfo );
		POS pos = pInfo->GetNeighborSectorInfoList().GetFirstPos();
		SectorInfo * pNextInfo = NULL;
		while( (pNextInfo = pInfo->GetNeighborSectorInfoList().GetNextPos( pos )) != NULL )
		{
			DecreasePlayerReferenceCount( pNextInfo->GetSectorIndex(), pObject );
		}
	}
}


//=================================================================================================
/**
	@remarks
			抛胶飘甫 窍咯 弥利拳啊 鞘夸茄 何盒
	@param	pObject
			冀磐甫 捞悼且 坷宏璃飘
*/
//=================================================================================================

VOID Field::ChangeSector( Object * pObject )
{
	DWORD dwOldIndex = pObject->GetOldSectorIndex();
	DWORD dwNewIndex = pObject->GetSectorIndex();

	Sector *pOldSector = GetSector( dwOldIndex );
	Sector *pNewSector = GetSector( dwNewIndex );

	if( !pOldSector || !pNewSector )	
	{
		SUNLOG( eCRITICAL_LOG,  "[Field::ChangeSector] dwOldIndex[%d/%d], dwNewIndex[%d/%d] ", dwOldIndex, m_vecTotalSector.size(), dwNewIndex, m_vecTotalSector.size() );
		return;
	}

	if( dwOldIndex == dwNewIndex )	return;

	// 捞傈 冀磐俊辑 某腐磐 力芭
	pOldSector->RemoveObject( pObject );

	// 货肺款 冀磐俊 某腐磐 眠啊
	pNewSector->AddObject( pObject, FALSE );
	
	// 牢立 冀磐俊霸 舅妨林绰 风凭
	m_setPrevSector.clear();
	m_setCurrSector.clear();

	SectorInfo * pInfo = m_pFieldInfo->GetSectorInfo( dwOldIndex );
	POS pos = pInfo->GetNeighborSectorInfoList().GetFirstPos();
	SectorInfo * pNextInfo = NULL;
	m_setPrevSector.insert( m_setPrevSector.end(), dwOldIndex );
	while( (pNextInfo = pInfo->GetNeighborSectorInfoList().GetNextPos( pos )) != NULL )
	{
		m_setPrevSector.insert( m_setPrevSector.end(), pNextInfo->GetSectorIndex() );
	}

	pInfo = m_pFieldInfo->GetSectorInfo( dwNewIndex );
	pos = pInfo->GetNeighborSectorInfoList().GetFirstPos();
	m_setCurrSector.insert( m_setCurrSector.end(), dwNewIndex );
	while( (pNextInfo = pInfo->GetNeighborSectorInfoList().GetNextPos( pos )) != NULL )
	{
		m_setCurrSector.insert( m_setCurrSector.end(), pNextInfo->GetSectorIndex() );
	}

	m_setEnterSector.clear();
	set_difference(	m_setCurrSector.begin(),
					m_setCurrSector.end(),
					m_setPrevSector.begin(),
					m_setPrevSector.end(),
   					inserter(m_setEnterSector, m_setEnterSector.end()) );


	m_setLeaveSector.clear();
	set_difference(	m_setPrevSector.begin(),
					m_setPrevSector.end(),
					m_setCurrSector.begin(),
					m_setCurrSector.end(),
					inserter(m_setLeaveSector, m_setLeaveSector.end()) );

	SET_SECTOR_ITR  it;

	// 肯傈洒 栋唱绰 冀磐 贸府
	int index = 0;
	for( it = m_setLeaveSector.begin() ; it != m_setLeaveSector.end() ; ++it )
	{
		index = *it;

		if( m_pFieldInfo->GetViewPort() )
		{
			// 某腐磐啊 栋车澜阑 冀磐俊 舅妨霖促.
			m_vecTotalSector[index]->SendRemoveObject( pObject );

			// 冀磐狼 沥焊甫 栋唱绰 某腐磐肺何磐 力芭茄促.
			m_vecTotalSector[index]->SendDelSectorInfo( pObject );
		}

		// 冀磐 曼炼 墨款泼阑 皑家矫挪促.
		DecreasePlayerReferenceCount( index, pObject );
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -