Example #1
0
//---------------------------------------------------
// joinAccept :
//---------------------------------------------------
void CTeamManager::joinAccept( const NLMISC::CEntityId &charId)
{
	// get the invited char
	CCharacter * invited = PlayerManager.getOnlineChar(charId);
	if ( invited == NULL )
	{
		nlwarning("<CTeamManager joinAccept>Invalid char %s",charId.toString().c_str());
		return;
	}

	// get the invitor id
	const NLMISC::CEntityId & invitorId = invited->getTeamInvitor();

	if ( invitorId == CEntityId::Unknown )
	{
		nlwarning("<CTeamManager joinAccept>character %s has an Invalid invitor",charId.toString().c_str());
		return;
	}
	//get the invitor char
	CCharacter * invitor = PlayerManager.getOnlineChar(invitorId);
	if ( invitor == NULL  )
	{
		nlwarning("<CTeamManager joinAccept>character %s, Invalid invitor id %s",charId.toString().c_str(),invitorId.toString().c_str());
		invited->setTeamInvitor( CEntityId::Unknown );
		return;
	}
	invitor->setAfkState(false);
	//cancel the proposal
	invited->setTeamInvitor( CEntityId::Unknown );

	CTeam *team;
	//if the invited player had a fake team, remove it
	team = getTeam( invited->getTeamId() );
	
	if ( team )
	{
		// if the team is not fake, there is a problem...
		if ( !team->isFake() )
		{
			nlwarning("<CTeamManager joinAccept>character %s, invitor id %s, the invited player is in a valid team. ",charId.toString().c_str(),invitor->getId().toString().c_str() );
			return ;
		}
		else
		{
			team->release();
			removeTeam( invited->getTeamId() );
		}
	}

	team = getTeam(invitor->getTeamId());
	//  create the team if it does not exist
	if ( !team )
	{
		//check for reallocation
		if ( _FirstFreeTeamId >= (uint16)_Teams.size() )
		{
			_Teams.resize( _TeamAllocStep + _FirstFreeTeamId );
			for (uint i = _FirstFreeTeamId; i < _Teams.size(); i++)
			{
				_Teams[i].setNextFreeId( i + 1 );
			}
		}
		//get a pointer on the new team
		team = &_Teams[_FirstFreeTeamId];
		// set the invitor team id
		invitor->setTeamId(_FirstFreeTeamId);
		//init the team
		team->init( invitor,_FirstFreeTeamId );
		// update alloc data
		_FirstFreeTeamId = team->getNextFreeId();
	}
	// If the team is fake transform it in an unfake team
	else if ( team->isFake() )
	{
		// init the team
		team->init( invitor,invitor->getTeamId() );
	}

	// check the team size
	if ( team->getTeamSize() < CTEAM::TeamMaxNbMembers )
	{
		//add the new character to the team
		team->addCharacter(invited);
	}
	else
	{
		CCharacter::sendDynamicSystemMessage(charId,"OPS_TEAM_MAX_SIZE_REACHED");
//		CCharacter::sendMessageToClient(charId,"OPS_TEAM_MAX_SIZE_REACHED");
	}

	CMissionManager::getInstance()->updateEscortTeam( charId );
} // joinAccept //