[10321] Share some code for faction related commands.

This commit is contained in:
VladimirMangos 2010-08-05 01:18:23 +04:00
parent 63bea3c422
commit 17ecab0030
3 changed files with 52 additions and 65 deletions

View file

@ -22,12 +22,15 @@
#include "SharedDefines.h"
struct AreaTrigger;
struct FactionEntry;
struct FactionState;
struct GameTele;
class ChatHandler;
class WorldSession;
class Creature;
class Player;
class Unit;
struct GameTele;
class ChatCommand
{
@ -263,8 +266,6 @@ class ChatHandler
bool HandleLookupPlayerAccountCommand(const char* args);
bool HandleLookupPlayerEmailCommand(const char* args);
bool HandleLookupQuestCommand(const char* args);
void ShowQuestListHelper(uint32 questId, int32 loc_idx, Player* target = NULL);
bool HandleLookupSkillCommand(const char* args);
bool HandleLookupSpellCommand(const char* args);
bool HandleLookupTaxiNodeCommand(const char * args);
@ -573,10 +574,13 @@ class ChatHandler
GameObject* GetObjectGlobalyWithGuidOrNearWithDbGuid(uint32 lowguid,uint32 entry);
// Utility methods for commands
void ShowTicket(uint64 guid, char const* text, char const* time);
bool ShowAccountListHelper(QueryResult* result, uint32* limit = NULL, bool title = true, bool error = true);
bool ShowPlayerListHelper(QueryResult* result, uint32* limit = NULL, bool title = true, bool error = true);
void ShowFactionListHelper(FactionEntry const * factionEntry, LocaleConstant loc, FactionState const* repState = NULL, Player * target = NULL );
void ShowItemListHelper(uint32 itemId, int loc_idx, Player* target = NULL);
void ShowQuestListHelper(uint32 questId, int32 loc_idx, Player* target = NULL);
bool ShowPlayerListHelper(QueryResult* result, uint32* limit = NULL, bool title = true, bool error = true);
void ShowSpellListHelper(Player* target, SpellEntry const* spellInfo, LocaleConstant loc);
void ShowTicket(uint64 guid, char const* text, char const* time);
void ShowTriggerListHelper(AreaTriggerEntry const * atEntry);
void ShowTriggerTargetListHelper(uint32 id, AreaTrigger const* at, bool subpart = false);
bool LookupPlayerSearchCommand(QueryResult* result, uint32* limit = NULL);
@ -586,7 +590,6 @@ class ChatHandler
bool HandleUnBanHelper(BanMode mode,char const* args);
void HandleCharacterLevel(Player* player, uint64 player_guid, uint32 oldlevel, uint32 newlevel);
void HandleLearnSkillRecipesHelper(Player* player,uint32 skill_id);
void ShowSpellListHelper(Player* target, SpellEntry const* spellInfo, LocaleConstant loc);
bool HandleGoHelper(Player* _player, uint32 mapid, float x, float y, float const* zPtr = NULL, float const* ortPtr = NULL);
template<typename T>
void ShowNpcOrGoSpawnInformation(uint32 guid);

View file

@ -1170,6 +1170,45 @@ bool ChatHandler::HandleGUIDCommand(const char* /*args*/)
return true;
}
void ChatHandler::ShowFactionListHelper( FactionEntry const * factionEntry, LocaleConstant loc, FactionState const* repState /*= NULL*/, Player * target /*= NULL */ )
{
std::string name = factionEntry->name[loc];
// send faction in "id - [faction] rank reputation [visible] [at war] [own team] [unknown] [invisible] [inactive]" format
// or "id - [faction] [no reputation]" format
std::ostringstream ss;
if (m_session)
ss << factionEntry->ID << " - |cffffffff|Hfaction:" << factionEntry->ID << "|h[" << name << " " << localeNames[loc] << "]|h|r";
else
ss << factionEntry->ID << " - " << name << " " << localeNames[loc];
if (repState) // and then target!=NULL also
{
ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry);
std::string rankName = GetMangosString(ReputationRankStrIndex[rank]);
ss << " " << rankName << "|h|r (" << target->GetReputationMgr().GetReputation(factionEntry) << ")";
if (repState->Flags & FACTION_FLAG_VISIBLE)
ss << GetMangosString(LANG_FACTION_VISIBLE);
if (repState->Flags & FACTION_FLAG_AT_WAR)
ss << GetMangosString(LANG_FACTION_ATWAR);
if (repState->Flags & FACTION_FLAG_PEACE_FORCED)
ss << GetMangosString(LANG_FACTION_PEACE_FORCED);
if (repState->Flags & FACTION_FLAG_HIDDEN)
ss << GetMangosString(LANG_FACTION_HIDDEN);
if (repState->Flags & FACTION_FLAG_INVISIBLE_FORCED)
ss << GetMangosString(LANG_FACTION_INVISIBLE_FORCED);
if (repState->Flags & FACTION_FLAG_INACTIVE)
ss << GetMangosString(LANG_FACTION_INACTIVE);
}
else if (target)
ss << GetMangosString(LANG_FACTION_NOREPUTATION);
SendSysMessage(ss.str().c_str());
}
bool ChatHandler::HandleLookupFactionCommand(const char* args)
{
if (!*args)
@ -1194,8 +1233,6 @@ bool ChatHandler::HandleLookupFactionCommand(const char* args)
FactionEntry const *factionEntry = sFactionStore.LookupEntry(id);
if (factionEntry)
{
FactionState const* repState = target ? target->GetReputationMgr().GetState(factionEntry) : NULL;
int loc = GetSessionDbcLocale();
std::string name = factionEntry->name[loc];
if (name.empty())
@ -1220,38 +1257,8 @@ bool ChatHandler::HandleLookupFactionCommand(const char* args)
if (loc < MAX_LOCALE)
{
// send faction in "id - [faction] rank reputation [visible] [at war] [own team] [unknown] [invisible] [inactive]" format
// or "id - [faction] [no reputation]" format
std::ostringstream ss;
if (m_session)
ss << id << " - |cffffffff|Hfaction:" << id << "|h[" << name << " " << localeNames[loc] << "]|h|r";
else
ss << id << " - " << name << " " << localeNames[loc];
if (repState) // and then target!=NULL also
{
ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry);
std::string rankName = GetMangosString(ReputationRankStrIndex[rank]);
ss << " " << rankName << "|h|r (" << target->GetReputationMgr().GetReputation(factionEntry) << ")";
if (repState->Flags & FACTION_FLAG_VISIBLE)
ss << GetMangosString(LANG_FACTION_VISIBLE);
if (repState->Flags & FACTION_FLAG_AT_WAR)
ss << GetMangosString(LANG_FACTION_ATWAR);
if (repState->Flags & FACTION_FLAG_PEACE_FORCED)
ss << GetMangosString(LANG_FACTION_PEACE_FORCED);
if (repState->Flags & FACTION_FLAG_HIDDEN)
ss << GetMangosString(LANG_FACTION_HIDDEN);
if (repState->Flags & FACTION_FLAG_INVISIBLE_FORCED)
ss << GetMangosString(LANG_FACTION_INVISIBLE_FORCED);
if (repState->Flags & FACTION_FLAG_INACTIVE)
ss << GetMangosString(LANG_FACTION_INACTIVE);
}
else
ss << GetMangosString(LANG_FACTION_NOREPUTATION);
SendSysMessage(ss.str().c_str());
FactionState const* repState = target ? target->GetReputationMgr().GetState(factionEntry) : NULL;
ShowFactionListHelper(factionEntry, LocaleConstant(loc), repState, target);
counter++;
}
}
@ -3934,31 +3941,8 @@ bool ChatHandler::HandleCharacterReputationCommand(const char* args)
for(FactionStateList::const_iterator itr = targetFSL.begin(); itr != targetFSL.end(); ++itr)
{
FactionEntry const *factionEntry = sFactionStore.LookupEntry(itr->second.ID);
char const* factionName = factionEntry ? factionEntry->name[loc] : "#Not found#";
ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry);
std::string rankName = GetMangosString(ReputationRankStrIndex[rank]);
std::ostringstream ss;
if (m_session)
ss << itr->second.ID << " - |cffffffff|Hfaction:" << itr->second.ID << "|h[" << factionName << " " << localeNames[loc] << "]|h|r";
else
ss << itr->second.ID << " - " << factionName << " " << localeNames[loc];
ss << " " << rankName << " (" << target->GetReputationMgr().GetReputation(factionEntry) << ")";
if (itr->second.Flags & FACTION_FLAG_VISIBLE)
ss << GetMangosString(LANG_FACTION_VISIBLE);
if (itr->second.Flags & FACTION_FLAG_AT_WAR)
ss << GetMangosString(LANG_FACTION_ATWAR);
if (itr->second.Flags & FACTION_FLAG_PEACE_FORCED)
ss << GetMangosString(LANG_FACTION_PEACE_FORCED);
if (itr->second.Flags & FACTION_FLAG_HIDDEN)
ss << GetMangosString(LANG_FACTION_HIDDEN);
if (itr->second.Flags & FACTION_FLAG_INVISIBLE_FORCED)
ss << GetMangosString(LANG_FACTION_INVISIBLE_FORCED);
if (itr->second.Flags & FACTION_FLAG_INACTIVE)
ss << GetMangosString(LANG_FACTION_INACTIVE);
SendSysMessage(ss.str().c_str());
ShowFactionListHelper(factionEntry, loc, &itr->second, target);
}
return true;
}

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10320"
#define REVISION_NR "10321"
#endif // __REVISION_NR_H__