示例#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
//---------------------------------------------------
// kickCharacter :
//---------------------------------------------------
void CTeamManager::kickCharacter( CCharacter * leader, uint8 memberIndex )
{
	// check must be done before
	nlassert(leader);
	const NLMISC::CEntityId & leaderId = leader->getId();
	
	// get the leader's team
	CTeam * team = getRealTeam( leader->getTeamId() );	
	if ( team == NULL )
	{
		nlwarning("<CTeamManager kickCharacter> Player %s has an invalid team id %d", leaderId.toString().c_str(), leader->getTeamId() );
		return;
	}
	// only leaders can kick
	if ( leaderId != team->getLeader() )
	{
		nlwarning("<CTeamManager kickCharacter> Player %s tries kicking but is not the leader", leaderId.toString().c_str() );
		return;
	}

	// increment the target index as the leader is not in its team list
	memberIndex++;
	const std::list< NLMISC::CEntityId >  & members = team->getTeamMembers();
	std::list< NLMISC::CEntityId >::const_iterator it = members.begin();
	uint i = 0;
	for (; i < memberIndex; i++ )
	{
		if ( it == members.end() )
		{
			nlwarning("<CTeamManager kickCharacter> Player %s kicks teammate %d but there are %d members", leaderId.toString().c_str(), memberIndex,i+1 );
			return;
		}
		++it;
	}
	if ( it == members.end() )
	{
		nlwarning("<CTeamManager kickCharacter> Player %s kicks teammate %d but there are %d members", leaderId.toString().c_str(), memberIndex,i+1 );
		return;
	}

	CCharacter * kickedChar = PlayerManager.getOnlineChar( (*it) );
	if ( kickedChar == NULL )
	{
		nlwarning("<CTeamManager kickCharacter> kicked Player %d is invalid", memberIndex );
		return;
	}


	// inform the kicked player
	SM_STATIC_PARAMS_1(params, STRING_MANAGER::player);	
	params[0].setEIdAIAlias( leaderId, CAIAliasTranslator::getInstance()->getAIAlias( leaderId ) );
	PHRASE_UTILITIES::sendDynamicSystemMessage(TheDataset.getDataSetRow(*it), "TEAM_KICKED_YOU", params);
	
	// inform other team members
	params[0].setEIdAIAlias( *it, CAIAliasTranslator::getInstance()->getAIAlias( *it ) );
	set<CEntityId> exclude;
	exclude.insert(*it);
	team->sendDynamicMessageToMembers("TEAM_KICKED", params, exclude);

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

	leader->updateTarget();
	/*
	TGroupId groupId = CEntityId(RYZOMID::chatGroup, leader->getTeamId() + 1);
	string msgName = "OPS_KICKED_TEAM_E";
	CMessage msggroup("STATIC_STRING");
	msggroup.serial( groupId );
	std::set<CEntityId> exclude;
	exclude.insert(*it);
	msggroup.serialCont( exclude);
	msggroup.serial( msgName );
	msggroup.serial( (CEntityId&)(*it) );
	sendMessageViaMirror( "IOS", msggroup );
	*/

	CMissionManager::getInstance()->updateEscortTeam( kickedChar->getId() );
	
}// kickCharacter