Ejemplo n.º 1
0
//---------------------------------------------------
// leagueJoinProposal :
//---------------------------------------------------
void CTeamManager::joinLeagueProposal( CCharacter * leader, const CEntityId &targetId)
{
	//check already done
	nlassert(leader);

	const NLMISC::CEntityId &leaderId = leader->getId();
	if (targetId == leaderId )
	{
		CCharacter::sendDynamicSystemMessage( leader->getId(),"INVALID_LEAGUE_TARGET" );
		return;
	}

	// get targeted player
	CCharacter *invitedPlayer = PlayerManager.getOnlineChar( targetId );
	if ( invitedPlayer == NULL )
	{
		CCharacter::sendDynamicSystemMessage( leader->getId(),"INVALID_LEAGUE_TARGET" );
		return;
	}
	
	// god player are forbidden to team
	if (leader->godMode() || invitedPlayer->godMode())
	{
		nlwarning("<CTeamManager joinLeagueProposal> Player %s invited %s, but at least on of them is god, forbidden", 
			leaderId.toString().c_str(),
			targetId.toString().c_str());
		CCharacter::sendDynamicSystemMessage( leader->getId(),"TEAM_GOD_FORBIDDEN" );
		return;
	}

	TInviteRetCode code = isLeagueInvitableBy(invitedPlayer,leader);
	if ( code == AlreadyInvited )
	{
		CCharacter::sendDynamicSystemMessage( leader->getId(),"LEAGUE_ALREADY_INVITED" );
		return;
	}
	else if ( code == AlreadyInLeague )
	{
		CTeam * team = getRealTeam( invitedPlayer->getTeamId() );
		CCharacter::sendDynamicSystemMessage( leader->getId(),"LEAGUE_ALREADY_IN_LEAGUE" );
		return;
	}
	else if ( code == NotLeader )
	{
		CTeam * team = getRealTeam( invitedPlayer->getTeamId() );
		joinLeagueProposal(leader, team->getLeader());
		return;
	}
	else if ( code == CantInvite )
	{
		CCharacter::sendDynamicSystemMessage( leader->getId(),"LEAGUE_INVITOR_NOT_LEADER" );
		return;
	}

	/// the invitor must not be in the ignore list of the target
	if(invitedPlayer->hasInIgnoreList(leaderId))
	{
		SM_STATIC_PARAMS_1( params1, STRING_MANAGER::player );
		params1[0].setEIdAIAlias( targetId, CAIAliasTranslator::getInstance()->getAIAlias( targetId) );
		// Use the standard "player declines your offer". Don't use specific message because
		// maybe not a good idea to inform a player that someone ignores him
		CCharacter::sendDynamicSystemMessage( leaderId, "TEAM_DECLINE", params1 );
		return;
	}

	//set the target's invitor
	invitedPlayer->setLeagueInvitor(leaderId);

	CEntityId msgTargetEId = targetId;
	
	//send the appropriate string to the client
	SM_STATIC_PARAMS_1(params, STRING_MANAGER::player);
	params[0].setEIdAIAlias( leaderId, CAIAliasTranslator::getInstance()->getAIAlias(leaderId) );
	uint32 txt = STRING_MANAGER::sendStringToClient(TheDataset.getDataSetRow(targetId), "LEAGUE_PROPOSAL", params );
	
	CMessage msgout( "IMPULSION_ID" );
	msgout.serial( const_cast<CEntityId&>(msgTargetEId) );
	CBitMemStream bms;
	nlverify ( GenericMsgManager.pushNameToStream( "PVP_CHALLENGE:INVITATION", bms) );
	bms.serial( txt );
	msgout.serialBufferWithSize((uint8*)bms.buffer(), bms.length());
	sendMessageViaMirror( NLNET::TServiceId(msgTargetEId.getDynamicId()), msgout );

	params[0].setEIdAIAlias( targetId, CAIAliasTranslator::getInstance()->getAIAlias( targetId ) );
	PHRASE_UTILITIES::sendDynamicSystemMessage(leader->getEntityRowId(), "LEAGUE_INVITE", params);
	
	leader->updateTarget();	
}
Ejemplo n.º 2
0
//---------------------------------------------------
// joinProposal :
//---------------------------------------------------
void CTeamManager::joinProposal( CCharacter * leader, const CEntityId &targetId)
{
	//check already done
	nlassert(leader);

	const NLMISC::CEntityId &leaderId = leader->getId();
	if (targetId == leaderId )
	{
		nlwarning("<CTeamManager joinProposal> Player %s invited himself in his team, cancel", leaderId.toString().c_str() );
		return;
	}

	// get targeted player
	CCharacter *invitedPlayer = PlayerManager.getOnlineChar( targetId );
	if ( invitedPlayer == NULL )
	{
		CCharacter::sendDynamicSystemMessage( leader->getId(),"INVALID_LEAGUE_TARGET" );
		return;
	}
	
	// god player are forbidden to team
	if (leader->godMode() || invitedPlayer->godMode())
	{
		nlwarning("<CTeamManager joinProposal> Player %s invited %s, but at least on of them is god, forbidden", 
			leaderId.toString().c_str(),
			targetId.toString().c_str());
		CCharacter::sendDynamicSystemMessage( leader->getId(),"TEAM_GOD_FORBIDDEN" );
		return;
	}

	TInviteRetCode code = isInvitableBy(invitedPlayer,leader);
	if ( code == AlreadyInvited )
	{
		CCharacter::sendDynamicSystemMessage( leader->getId(),"TEAM_ALREADY_INVITED" );
		return;
	}
	else if ( code == AlreadyInTeam )
	{
		CCharacter::sendDynamicSystemMessage( leader->getId(),"TEAM_TARGET_ALREADY_IN_TEAM" );
		return;
	}
	else if ( code == CantInviteEnemy )
	{
		CCharacter::sendDynamicSystemMessage( leader->getId(),"TEAM_CANT_INVITE_ENEMY" );
		return;
	}
	else if ( code == CantInvite )
	{
		CCharacter::sendDynamicSystemMessage( leader->getId(),"TEAM_CANT_INVITE" );
		return;
	}

	/// the invitor must not be in the ignore list of the target
	if(invitedPlayer->hasInIgnoreList(leaderId))
	{
		SM_STATIC_PARAMS_1( params1, STRING_MANAGER::player );
		params1[0].setEIdAIAlias( targetId, CAIAliasTranslator::getInstance()->getAIAlias( targetId) );
		// Use the standard "player declines your offer". Don't use specific message because
		// maybe not a good idea to inform a player that someone ignores him
		CCharacter::sendDynamicSystemMessage( leaderId, "TEAM_DECLINE", params1 );
		return;
	}

	//set the target's invitor
	invitedPlayer->setTeamInvitor(leaderId);


	//send the appropriate string to the client
	SM_STATIC_PARAMS_1(params, STRING_MANAGER::player);
	params[0].setEIdAIAlias( leaderId, CAIAliasTranslator::getInstance()->getAIAlias( leaderId ) );
	uint32 strId = STRING_MANAGER::sendStringToClient(TheDataset.getDataSetRow(targetId),"TEAM_PROPOSAL", params);

	//send the invitation msg to the target, with the id of the built string
	CMessage msgout( "IMPULSION_ID" );
	CBitMemStream bms;
	CEntityId targetIdToSerial = targetId;
	msgout.serial( targetIdToSerial );
	if ( ! GenericMsgManager.pushNameToStream( "TEAM:INVITATION", bms) )
	{
		nlwarning("<CTeamManager joinProposal> Msg name TEAM:INVITATION not found");
		return;
	}

	bms.serial(strId);
	msgout.serialBufferWithSize((uint8*)bms.buffer(), bms.length());
	sendMessageViaMirror( NLNET::TServiceId(targetId.getDynamicId()), msgout );

//	TVectorParamCheck params;
//	params.resize(1);

	// inform the team leader	
//	params[0].Type = STRING_MANAGER::player;	
	params[0].setEIdAIAlias( targetId, CAIAliasTranslator::getInstance()->getAIAlias( targetId ) );
	PHRASE_UTILITIES::sendDynamicSystemMessage(leader->getEntityRowId(), "TEAM_INVITE", params);
	
	leader->updateTarget();
} // joinProposal //