Changed: #1304: Implementation of the cbClientGroupAbandonMission for the guilds

This commit is contained in:
Fabien_HENON 2011-07-18 19:37:59 +02:00
parent 4a2a66b03d
commit bdbd53266e
3 changed files with 112 additions and 33 deletions

View file

@ -35,6 +35,7 @@
#include "primitives_parser.h" #include "primitives_parser.h"
#include "modules/shard_unifier_client.h" #include "modules/shard_unifier_client.h"
#include "mission_manager/mission_manager.h" #include "mission_manager/mission_manager.h"
#include "phrase_manager/phrase_utilities_functions.h"
/// todo guild remove entity id translator /// todo guild remove entity id translator
#include "nel/misc/eid_translator.h" #include "nel/misc/eid_translator.h"
@ -745,6 +746,22 @@ void CGuild::updateMissionHistories(TAIAlias missionAlias, uint32 result)
} }
} }
//----------------------------------------------------------------------------
void CGuild::sendDynamicMessageToMembers(const string &msgName, const TVectorParamCheck &params, const set<CEntityId> &excluded) const
{
for ( std::map<EGSPD::TCharacterId, EGSPD::CGuildMemberPD*>::const_iterator it = getMembersBegin();
it != getMembersEnd();++it )
{
CCharacter * user = PlayerManager.getChar( it->first );
if ( excluded.find(it->first) == excluded.end())
{
const uint32 stringId = STRING_MANAGER::sendStringToClient(TheDataset.getDataSetRow(it->first), msgName, params );
PHRASE_UTILITIES::sendDynamicSystemMessage(TheDataset.getDataSetRow(it->first), stringId);
}
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool CGuild::processMissionEvent( CMissionEvent & event, TAIAlias alias) bool CGuild::processMissionEvent( CMissionEvent & event, TAIAlias alias)
{ {

View file

@ -200,6 +200,7 @@ public:
bool processGuildMissionStepEvent(std::list< CMissionEvent* > & eventList, TAIAlias missionAlias, uint32 stepIndex); bool processGuildMissionStepEvent(std::list< CMissionEvent* > & eventList, TAIAlias missionAlias, uint32 stepIndex);
CMissionGuild* getMissionByAlias( TAIAlias missionAlias ); CMissionGuild* getMissionByAlias( TAIAlias missionAlias );
bool isMissionSuccessfull(TAIAlias alias); bool isMissionSuccessfull(TAIAlias alias);
void sendDynamicMessageToMembers(const std::string &msgName, const TVectorParamCheck &params, const std::set<NLMISC::CEntityId> &excluded) const;
///\return the mission ///\return the mission
inline std::vector<CMissionGuild*> & getMissions() inline std::vector<CMissionGuild*> & getMissions()
{ {

View file

@ -26,6 +26,9 @@
#include "team_manager/team_manager.h" #include "team_manager/team_manager.h"
#include "mission_manager/mission_team.h" #include "mission_manager/mission_team.h"
#include "mission_manager/mission_log.h" #include "mission_manager/mission_log.h"
#include "guild_manager/guild_manager.h"
#include "guild_manager/guild.h"
#include "guild_manager/guild_member.h"
using namespace std; using namespace std;
@ -222,50 +225,108 @@ void cbClientGroupAbandonMission( NLNET::CMessage& msgin, const std::string &ser
CCharacter * user = PlayerManager.getChar( userId ); CCharacter * user = PlayerManager.getChar( userId );
user->setAfkState(false); user->setAfkState(false);
CTeam * team = TeamManager.getRealTeam( user->getTeamId() );
if ( !team )
{
MISLOG("user:%s cbClientGroupAbandonMission : Invalid team", userId.toString().c_str());
return;
}
if ( team->getLeader() != userId )
{
CCharacter::sendDynamicSystemMessage( user->getEntityRowId(), "REQ_LEADER_TO_ABANDON_MISSION" );
return;
}
if ( index >= team->getMissions().size() ) // We check if it's a guild or team mission
if (index < MaxGroupMissionCount)
{ {
MISLOG("user:%s cbClientGroupAbandonMission : Invalid group mission %u ( count %u )", // Team
userId.toString().c_str(), index, team->getMissions().size());
return;
}
CMissionTeam* mission = team->getMissions()[index]; CTeam * team = TeamManager.getRealTeam( user->getTeamId() );
nlassert(mission); if ( !team )
if ( mission->getFinished() == false )
{
CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( mission->getTemplateId() );
if ( !templ )
{ {
MISLOG("user:%s cbClientGroupAbandonMission : invalid group mission alias %u", MISLOG("user:%s cbClientGroupAbandonMission : Invalid team", userId.toString().c_str());
userId.toString().c_str(), mission->getTemplateId());
return; return;
} }
if ( templ->Tags.NonAbandonnable ) if ( team->getLeader() != userId )
{ {
MISLOG("user:%s cbClientGroupAbandonMission : group mission alias %u is not abandonnable but user tries to abandon it", CCharacter::sendDynamicSystemMessage( user->getEntityRowId(), "REQ_LEADER_TO_ABANDON_MISSION" );
userId.toString().c_str(), mission->getTemplateId()); return;
}
if ( index >= team->getMissions().size() )
{
MISLOG("user:%s cbClientGroupAbandonMission : Invalid group mission %u ( count %u )",
userId.toString().c_str(), index, team->getMissions().size());
return; return;
} }
set<CEntityId> excluded;
excluded.insert( userId );
team->sendDynamicMessageToMembers( "ABANDON_GROUP_MISSION",TVectorParamCheck(), excluded );
CMissionTeam* mission = team->getMissions()[index];
nlassert(mission);
if ( mission->getFinished() == false )
{
CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( mission->getTemplateId() );
if ( !templ )
{
MISLOG("user:%s cbClientGroupAbandonMission : invalid group mission alias %u",
userId.toString().c_str(), mission->getTemplateId());
return;
}
if ( templ->Tags.NonAbandonnable )
{
MISLOG("user:%s cbClientGroupAbandonMission : group mission alias %u is not abandonnable but user tries to abandon it",
userId.toString().c_str(), mission->getTemplateId());
return;
}
set<CEntityId> excluded;
excluded.insert( userId );
team->sendDynamicMessageToMembers( "ABANDON_GROUP_MISSION",TVectorParamCheck(), excluded );
}
team->removeMission( index, mr_abandon );
}
else
{
// Guild
// We set the correct index
index = MaxGroupMissionCount - index;
CGuild * guild = CGuildManager::getInstance()->getGuildFromId( user->getGuildId() );
if ( !guild )
{
MISLOG("user:%s cbClientGroupAbandonMission : Invalid team", userId.toString().c_str());
return;
}
if ( guild->getLeader()->getIngameEId() != userId )
{
CCharacter::sendDynamicSystemMessage( user->getEntityRowId(), "REQ_LEADER_TO_ABANDON_MISSION" );
return;
}
if ( index >= guild->getMissions().size() )
{
MISLOG("user:%s cbClientGroupAbandonMission : Invalid group mission %u ( count %u )",
userId.toString().c_str(), index, guild->getMissions().size());
return;
}
CMissionGuild* mission = guild->getMissions()[index];
nlassert(mission);
if ( mission->getFinished() == false )
{
CMissionTemplate * templ = CMissionManager::getInstance()->getTemplate( mission->getTemplateId() );
if ( !templ )
{
MISLOG("user:%s cbClientGroupAbandonMission : invalid group mission alias %u",
userId.toString().c_str(), mission->getTemplateId());
return;
}
if ( templ->Tags.NonAbandonnable )
{
MISLOG("user:%s cbClientGroupAbandonMission : group mission alias %u is not abandonnable but user tries to abandon it",
userId.toString().c_str(), mission->getTemplateId());
return;
}
set<CEntityId> excluded;
excluded.insert( userId );
guild->sendDynamicMessageToMembers( "ABANDON_GROUP_MISSION",TVectorParamCheck(), excluded );
}
guild->removeMission( index, mr_abandon );
} }
team->removeMission( index, mr_abandon );
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------