Пример #1
0
//---------------------------------------------------
// removeCharacter :
//---------------------------------------------------
void CTeamManager::removeCharacter( const CEntityId &charId )
{
	CCharacter * player = PlayerManager.getOnlineChar( charId );
	if ( player == NULL )
	{
		nlwarning("<CTeamManager removeCharacter> Player %s is invalid", charId.toString().c_str() );
		return;
	}
	player->setAfkState(false);
	CTeam * team = getRealTeam( player->getTeamId() );	
	if ( team == NULL )
	{
		nlwarning("<CTeamManager removeCharacter> Player %s has an invalid team id %d", charId.toString().c_str(), player->getTeamId() );
		return;
	}

	uint16 nbMembers = team->getTeamSize();
	// send message to former member
	SM_STATIC_PARAMS_1(params, STRING_MANAGER::player);
	if (nbMembers > 2)
	{
		if (charId != team->getLeader())
		{
			params[0].setEIdAIAlias( team->getLeader(), CAIAliasTranslator::getInstance()->getAIAlias(team->getLeader()) );
			PHRASE_UTILITIES::sendDynamicSystemMessage(TheDataset.getDataSetRow(charId), "TEAM_YOU_LEAVE", params);
		}
		else
		{
			const list<CEntityId> &members = team->getTeamMembers();
			
			CEntityId eId(team->getSuccessor());
			params[0].setEIdAIAlias( eId, CAIAliasTranslator::getInstance()->getAIAlias(eId) );
			PHRASE_UTILITIES::sendDynamicSystemMessage(TheDataset.getDataSetRow(charId), "TEAM_YOU_LEAVE_LEADER", params);
		}
	}
	else if(nbMembers==2)
	{
		params[0].setEIdAIAlias( team->getLeader(), CAIAliasTranslator::getInstance()->getAIAlias(team->getLeader()) );
		PHRASE_UTILITIES::sendDynamicSystemMessage(TheDataset.getDataSetRow(charId), "TEAM_YOU_LEAVE_DISOLVE", params);
	}

	// send message to all other team members
	params[0].setEIdAIAlias( charId, CAIAliasTranslator::getInstance()->getAIAlias(charId) );
	set<CEntityId> exclude;
	exclude.insert( charId );
	team->sendDynamicMessageToMembers("TEAM_LEAVE", params, exclude);

	// remove the player from his team
	team->removeCharacter( player );

	/*
	TGroupId groupId =CHAT_GROUPS_IDS::getTeamChatGroupId(player->getTeamId());
	string msgName = "OPS_LEAVE_TEAM_E";
	CMessage msggroup("STATIC_STRING");
	msggroup.serial( groupId );
	std::set<CEntityId> exclude;
	exclude.insert( charId );
	msggroup.serialCont( exclude);
	msggroup.serial( msgName );
	msggroup.serial( (CEntityId&) charId );
	sendMessageViaMirror( "IOS", msggroup );
	*/
} // removeCharacter //
Пример #2
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 //