TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ReputationMgr Class Reference

#include <ReputationMgr.h>

Public Member Functions

 ReputationMgr (Player *owner)
 
 ~ReputationMgr ()
 
void SaveToDB (SQLTransaction &trans)
 
void LoadFromDB (PreparedQueryResult result)
 
uint8 GetVisibleFactionCount () const
 
uint8 GetHonoredFactionCount () const
 
uint8 GetReveredFactionCount () const
 
uint8 GetExaltedFactionCount () const
 
FactionStateList constGetStateList () const
 
FactionState constGetState (FactionEntry const *factionEntry) const
 
FactionState constGetState (RepListID id) const
 
bool IsAtWar (uint32 faction_id) const
 
bool IsAtWar (FactionEntry const *factionEntry) const
 
int32 GetReputation (uint32 faction_id) const
 
int32 GetReputation (FactionEntry const *factionEntry) const
 
int32 GetBaseReputation (FactionEntry const *factionEntry) const
 
ReputationRank GetRank (FactionEntry const *factionEntry) const
 
ReputationRank GetBaseRank (FactionEntry const *factionEntry) const
 
uint32 GetReputationRankStrIndex (FactionEntry const *factionEntry) const
 
ReputationRank constGetForcedRankIfAny (FactionTemplateEntry const *factionTemplateEntry) const
 
ReputationRank constGetForcedRankIfAny (uint32 factionId) const
 
bool SetReputation (FactionEntry const *factionEntry, int32 standing)
 
bool ModifyReputation (FactionEntry const *factionEntry, int32 standing)
 
void SetVisible (FactionTemplateEntry const *factionTemplateEntry)
 
void SetVisible (FactionEntry const *factionEntry)
 
void SetAtWar (RepListID repListID, bool on)
 
void SetInactive (RepListID repListID, bool on)
 
void ApplyForceReaction (uint32 faction_id, ReputationRank rank, bool apply)
 
bool SetOneFactionReputation (FactionEntry const *factionEntry, int32 standing, bool incremental)
 Public for chat command needs. More...
 
void SendInitialReputations ()
 
void SendForceReactions ()
 
void SendState (FactionState const *faction)
 
void SendStates ()
 

Static Public Member Functions

static ReputationRank ReputationToRank (int32 standing)
 

Static Public Attributes

static const int32 PointsInRank [MAX_REPUTATION_RANK] = {36000, 3000, 3000, 3000, 6000, 12000, 21000, 1000}
 
static const int32 Reputation_Cap = 42999
 
static const int32 Reputation_Bottom = -42000
 

Private Member Functions

void Initialize ()
 
uint32 GetDefaultStateFlags (FactionEntry const *factionEntry) const
 
bool SetReputation (FactionEntry const *factionEntry, int32 standing, bool incremental)
 
void SetVisible (FactionState *faction)
 
void SetAtWar (FactionState *faction, bool atWar) const
 
void SetInactive (FactionState *faction, bool inactive) const
 
void SendVisible (FactionState const *faction, bool visible=true) const
 
void UpdateRankCounters (ReputationRank old_rank, ReputationRank new_rank)
 

Private Attributes

Player_player
 
FactionStateList _factions
 
ForcedReactions _forcedReactions
 
uint8 _visibleFactionCount:8
 
uint8 _honoredFactionCount:8
 
uint8 _reveredFactionCount:8
 
uint8 _exaltedFactionCount:8
 
bool _sendFactionIncreased
 

Constructor & Destructor Documentation

ReputationMgr::ReputationMgr ( Player owner)
inlineexplicit
67  : _player(owner),
uint8 _visibleFactionCount
Definition: ReputationMgr.h:162
bool _sendFactionIncreased
Definition: ReputationMgr.h:166
uint8 _reveredFactionCount
Definition: ReputationMgr.h:164
uint8 _exaltedFactionCount
Definition: ReputationMgr.h:165
Player * _player
Definition: ReputationMgr.h:159
uint8 _honoredFactionCount
Definition: ReputationMgr.h:163
ReputationMgr::~ReputationMgr ( )
inline
69 { }

Member Function Documentation

void ReputationMgr::ApplyForceReaction ( uint32  faction_id,
ReputationRank  rank,
bool  apply 
)
132 {
133  if (apply)
134  _forcedReactions[faction_id] = rank;
135  else
136  _forcedReactions.erase(faction_id);
137 }
void apply(T *val)
Definition: ByteConverter.h:41
ForcedReactions _forcedReactions
Definition: ReputationMgr.h:161
ReputationRank ReputationMgr::GetBaseRank ( FactionEntry const factionEntry) const
126 {
127  int32 reputation = GetBaseReputation(factionEntry);
128  return ReputationToRank(reputation);
129 }
static ReputationRank ReputationToRank(int32 standing)
Definition: ReputationMgr.cpp:37
int32 GetBaseReputation(FactionEntry const *factionEntry) const
Definition: ReputationMgr.cpp:85
int32_t int32
Definition: Define.h:146

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int32 ReputationMgr::GetBaseReputation ( FactionEntry const factionEntry) const
86 {
87  if (!factionEntry)
88  return 0;
89 
90  uint32 raceMask = _player->getRaceMask();
91  uint32 classMask = _player->getClassMask();
92  for (int i=0; i < 4; i++)
93  {
94  if ((factionEntry->ReputationRaceMask[i] & raceMask ||
95  (factionEntry->ReputationRaceMask[i] == 0 &&
96  factionEntry->ReputationClassMask[i] != 0)) &&
97  (factionEntry->ReputationClassMask[i] & classMask ||
98  factionEntry->ReputationClassMask[i] == 0))
99 
100  return factionEntry->ReputationBase[i];
101  }
102 
103  // in faction.dbc exist factions with (RepListId >=0, listed in character reputation list) with all BaseRepRaceMask[i] == 0
104  return 0;
105 }
uint32_t uint32
Definition: Define.h:150
Player * _player
Definition: ReputationMgr.h:159

+ Here is the caller graph for this function:

uint32 ReputationMgr::GetDefaultStateFlags ( FactionEntry const factionEntry) const
private
140 {
141  if (!factionEntry)
142  return 0;
143 
144  uint32 raceMask = _player->getRaceMask();
145  uint32 classMask = _player->getClassMask();
146  for (int i=0; i < 4; i++)
147  {
148  if ((factionEntry->ReputationRaceMask[i] & raceMask ||
149  (factionEntry->ReputationRaceMask[i] == 0 &&
150  factionEntry->ReputationClassMask[i] != 0)) &&
151  (factionEntry->ReputationClassMask[i] & classMask ||
152  factionEntry->ReputationClassMask[i] == 0))
153 
154  return factionEntry->ReputationFlags[i];
155  }
156  return 0;
157 }
uint32_t uint32
Definition: Define.h:150
Player * _player
Definition: ReputationMgr.h:159

+ Here is the caller graph for this function:

uint8 ReputationMgr::GetExaltedFactionCount ( ) const
inline
83 { return _exaltedFactionCount; }
uint8 _exaltedFactionCount
Definition: ReputationMgr.h:165
ReputationRank const* ReputationMgr::GetForcedRankIfAny ( FactionTemplateEntry const factionTemplateEntry) const
inline
113  {
114  return GetForcedRankIfAny(factionTemplateEntry->Faction);
115  }
ReputationRank const * GetForcedRankIfAny(FactionTemplateEntry const *factionTemplateEntry) const
Definition: ReputationMgr.h:112
ReputationRank const* ReputationMgr::GetForcedRankIfAny ( uint32  factionId) const
inline
118  {
119  ForcedReactions::const_iterator forceItr = _forcedReactions.find(factionId);
120  return forceItr != _forcedReactions.end() ? &forceItr->second : NULL;
121  }
arena_t NULL
Definition: jemalloc_internal.h:624
ForcedReactions _forcedReactions
Definition: ReputationMgr.h:161
uint8 ReputationMgr::GetHonoredFactionCount ( ) const
inline
81 { return _honoredFactionCount; }
uint8 _honoredFactionCount
Definition: ReputationMgr.h:163
ReputationRank ReputationMgr::GetRank ( FactionEntry const factionEntry) const
120 {
121  int32 reputation = GetReputation(factionEntry);
122  return ReputationToRank(reputation);
123 }
static ReputationRank ReputationToRank(int32 standing)
Definition: ReputationMgr.cpp:37
int32 GetReputation(uint32 faction_id) const
Definition: ReputationMgr.cpp:72
int32_t int32
Definition: Define.h:146

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int32 ReputationMgr::GetReputation ( uint32  faction_id) const
73 {
74  FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id);
75 
76  if (!factionEntry)
77  {
78  TC_LOG_ERROR("misc", "ReputationMgr::GetReputation: Can't get reputation of %s for unknown faction (faction id) #%u.", _player->GetName().c_str(), faction_id);
79  return 0;
80  }
81 
82  return GetReputation(factionEntry);
83 }
int32 GetReputation(uint32 faction_id) const
Definition: ReputationMgr.cpp:72
Definition: DBCStructure.h:405
DBCStorage< FactionEntry > sFactionStore(Factionfmt)
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Player * _player
Definition: ReputationMgr.h:159

+ Here is the caller graph for this function:

int32 ReputationMgr::GetReputation ( FactionEntry const factionEntry) const
108 {
109  // Faction without recorded reputation. Just ignore.
110  if (!factionEntry)
111  return 0;
112 
113  if (FactionState const* state = GetState(factionEntry))
114  return GetBaseReputation(factionEntry) + state->Standing;
115 
116  return 0;
117 }
int32 GetBaseReputation(FactionEntry const *factionEntry) const
Definition: ReputationMgr.cpp:85
FactionState const * GetState(FactionEntry const *factionEntry) const
Definition: ReputationMgr.h:87
Definition: ReputationMgr.h:49

+ Here is the call graph for this function:

uint32 ReputationMgr::GetReputationRankStrIndex ( FactionEntry const factionEntry) const
inline
108  {
109  return ReputationRankStrIndex[GetRank(factionEntry)];
110  };
static uint32 ReputationRankStrIndex[MAX_REPUTATION_RANK]
Definition: ReputationMgr.h:29
ReputationRank GetRank(FactionEntry const *factionEntry) const
Definition: ReputationMgr.cpp:119
uint8 ReputationMgr::GetReveredFactionCount ( ) const
inline
82 { return _reveredFactionCount; }
uint8 _reveredFactionCount
Definition: ReputationMgr.h:164
FactionState const* ReputationMgr::GetState ( FactionEntry const factionEntry) const
inline
88  {
89  return factionEntry->CanHaveReputation() ? GetState(factionEntry->ReputationIndex) : NULL;
90  }
arena_t NULL
Definition: jemalloc_internal.h:624
FactionState const * GetState(FactionEntry const *factionEntry) const
Definition: ReputationMgr.h:87

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

FactionState const* ReputationMgr::GetState ( RepListID  id) const
inline
93  {
94  FactionStateList::const_iterator repItr = _factions.find (id);
95  return repItr != _factions.end() ? &repItr->second : NULL;
96  }
FactionStateList _factions
Definition: ReputationMgr.h:160
arena_t NULL
Definition: jemalloc_internal.h:624
FactionStateList const& ReputationMgr::GetStateList ( ) const
inline
85 { return _factions; }
FactionStateList _factions
Definition: ReputationMgr.h:160
uint8 ReputationMgr::GetVisibleFactionCount ( ) const
inline
80 { return _visibleFactionCount; }
uint8 _visibleFactionCount
Definition: ReputationMgr.h:162
void ReputationMgr::Initialize ( void  )
private
230 {
231  _factions.clear();
236  _sendFactionIncreased = false;
237 
238  for (unsigned int i = 1; i < sFactionStore.GetNumRows(); i++)
239  {
240  FactionEntry const* factionEntry = sFactionStore.LookupEntry(i);
241 
242  if (factionEntry && factionEntry->CanHaveReputation())
243  {
244  FactionState newFaction;
245  newFaction.ID = factionEntry->ID;
246  newFaction.ReputationListID = factionEntry->ReputationIndex;
247  newFaction.Standing = 0;
248  newFaction.Flags = GetDefaultStateFlags(factionEntry);
249  newFaction.needSend = true;
250  newFaction.needSave = true;
251 
252  if (newFaction.Flags & FACTION_FLAG_VISIBLE)
254 
256 
257  _factions[newFaction.ReputationListID] = newFaction;
258  }
259  }
260 }
uint32 ID
Definition: ReputationMgr.h:51
uint8 _visibleFactionCount
Definition: ReputationMgr.h:162
FactionStateList _factions
Definition: ReputationMgr.h:160
uint32 GetDefaultStateFlags(FactionEntry const *factionEntry) const
Definition: ReputationMgr.cpp:139
int32 Standing
Definition: ReputationMgr.h:53
void UpdateRankCounters(ReputationRank old_rank, ReputationRank new_rank)
Definition: ReputationMgr.cpp:567
bool _sendFactionIncreased
Definition: ReputationMgr.h:166
Definition: SharedDefines.h:214
bool needSend
Definition: ReputationMgr.h:55
uint8 _reveredFactionCount
Definition: ReputationMgr.h:164
Definition: DBCStructure.h:405
uint8 Flags
Definition: ReputationMgr.h:54
uint8 _exaltedFactionCount
Definition: ReputationMgr.h:165
Definition: ReputationMgr.h:38
bool needSave
Definition: ReputationMgr.h:56
DBCStorage< FactionEntry > sFactionStore(Factionfmt)
ReputationRank GetBaseRank(FactionEntry const *factionEntry) const
Definition: ReputationMgr.cpp:125
int32 ReputationIndex
Definition: DBCStructure.h:408
bool CanHaveReputation() const
Definition: DBCStructure.h:425
Definition: ReputationMgr.h:49
RepListID ReputationListID
Definition: ReputationMgr.h:52
uint32 ID
Definition: DBCStructure.h:407
uint8 _honoredFactionCount
Definition: ReputationMgr.h:163

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ReputationMgr::IsAtWar ( uint32  faction_id) const
50 {
51  FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id);
52 
53  if (!factionEntry)
54  {
55  TC_LOG_ERROR("misc", "ReputationMgr::IsAtWar: Can't get AtWar flag of %s for unknown faction (faction id) #%u.", _player->GetName().c_str(), faction_id);
56  return false;
57  }
58 
59  return IsAtWar(factionEntry);
60 }
bool IsAtWar(uint32 faction_id) const
Definition: ReputationMgr.cpp:49
Definition: DBCStructure.h:405
DBCStorage< FactionEntry > sFactionStore(Factionfmt)
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Player * _player
Definition: ReputationMgr.h:159
bool ReputationMgr::IsAtWar ( FactionEntry const factionEntry) const
63 {
64  if (!factionEntry)
65  return false;
66 
67  if (FactionState const* factionState = GetState(factionEntry))
68  return (factionState->Flags & FACTION_FLAG_AT_WAR) != 0;
69  return false;
70 }
Definition: ReputationMgr.h:39
FactionState const * GetState(FactionEntry const *factionEntry) const
Definition: ReputationMgr.h:87
Definition: ReputationMgr.h:49

+ Here is the call graph for this function:

void ReputationMgr::LoadFromDB ( PreparedQueryResult  result)
485 {
486  // Set initial reputations (so everything is nifty before DB data load)
487  Initialize();
488 
489  //QueryResult* result = CharacterDatabase.PQuery("SELECT faction, standing, flags FROM character_reputation WHERE guid = '%u'", GetGUIDLow());
490 
491  if (result)
492  {
493  do
494  {
495  Field* fields = result->Fetch();
496 
497  FactionEntry const* factionEntry = sFactionStore.LookupEntry(fields[0].GetUInt16());
498  if (factionEntry && factionEntry->CanHaveReputation())
499  {
500  FactionState* faction = &_factions[factionEntry->ReputationIndex];
501 
502  // update standing to current
503  faction->Standing = fields[1].GetInt32();
504 
505  // update counters
506  int32 BaseRep = GetBaseReputation(factionEntry);
507  ReputationRank old_rank = ReputationToRank(BaseRep);
508  ReputationRank new_rank = ReputationToRank(BaseRep + faction->Standing);
509  UpdateRankCounters(old_rank, new_rank);
510 
511  uint32 dbFactionFlags = fields[2].GetUInt16();
512 
513  if (dbFactionFlags & FACTION_FLAG_VISIBLE)
514  SetVisible(faction); // have internal checks for forced invisibility
515 
516  if (dbFactionFlags & FACTION_FLAG_INACTIVE)
517  SetInactive(faction, true); // have internal checks for visibility requirement
518 
519  if (dbFactionFlags & FACTION_FLAG_AT_WAR) // DB at war
520  SetAtWar(faction, true); // have internal checks for FACTION_FLAG_PEACE_FORCED
521  else // DB not at war
522  {
523  // allow remove if visible (and then not FACTION_FLAG_INVISIBLE_FORCED or FACTION_FLAG_HIDDEN)
524  if (faction->Flags & FACTION_FLAG_VISIBLE)
525  SetAtWar(faction, false); // have internal checks for FACTION_FLAG_PEACE_FORCED
526  }
527 
528  // set atWar for hostile
529  if (GetRank(factionEntry) <= REP_HOSTILE)
530  SetAtWar(faction, true);
531 
532  // reset changed flag if values similar to saved in DB
533  if (faction->Flags == dbFactionFlags)
534  {
535  faction->needSend = false;
536  faction->needSave = false;
537  }
538  }
539  }
540  while (result->NextRow());
541  }
542 }
static ReputationRank ReputationToRank(int32 standing)
Definition: ReputationMgr.cpp:37
void Initialize()
Definition: ReputationMgr.cpp:229
ReputationRank
Definition: SharedDefines.h:211
Definition: ReputationMgr.h:43
Definition: ReputationMgr.h:39
FactionStateList _factions
Definition: ReputationMgr.h:160
Class used to access individual fields of database query result.
Definition: Field.h:56
int32 Standing
Definition: ReputationMgr.h:53
void SetAtWar(RepListID repListID, bool on)
Definition: ReputationMgr.cpp:424
int32 GetBaseReputation(FactionEntry const *factionEntry) const
Definition: ReputationMgr.cpp:85
void SetInactive(RepListID repListID, bool on)
Definition: ReputationMgr.cpp:456
void UpdateRankCounters(ReputationRank old_rank, ReputationRank new_rank)
Definition: ReputationMgr.cpp:567
Definition: SharedDefines.h:214
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
bool needSend
Definition: ReputationMgr.h:55
void SetVisible(FactionTemplateEntry const *factionTemplateEntry)
Definition: ReputationMgr.cpp:381
uint16 GetUInt16() const
Definition: Field.h:108
Definition: DBCStructure.h:405
int32 GetInt32() const
Definition: Field.h:165
uint8 Flags
Definition: ReputationMgr.h:54
ReputationRank GetRank(FactionEntry const *factionEntry) const
Definition: ReputationMgr.cpp:119
Definition: ReputationMgr.h:38
bool needSave
Definition: ReputationMgr.h:56
DBCStorage< FactionEntry > sFactionStore(Factionfmt)
int32 ReputationIndex
Definition: DBCStructure.h:408
bool CanHaveReputation() const
Definition: DBCStructure.h:425
Definition: ReputationMgr.h:49

+ Here is the call graph for this function:

bool ReputationMgr::ModifyReputation ( FactionEntry const factionEntry,
int32  standing 
)
inline
129  {
130  return SetReputation(factionEntry, standing, true);
131  }
bool SetReputation(FactionEntry const *factionEntry, int32 standing)
Definition: ReputationMgr.h:124
ReputationRank ReputationMgr::ReputationToRank ( int32  standing)
static
38 {
39  int32 limit = Reputation_Cap + 1;
40  for (int i = MAX_REPUTATION_RANK-1; i >= MIN_REPUTATION_RANK; --i)
41  {
42  limit -= PointsInRank[i];
43  if (standing >= limit)
44  return ReputationRank(i);
45  }
46  return MIN_REPUTATION_RANK;
47 }
static const int32 PointsInRank[MAX_REPUTATION_RANK]
Definition: ReputationMgr.h:74
ReputationRank
Definition: SharedDefines.h:211
static const int32 Reputation_Cap
Definition: ReputationMgr.h:75
#define MAX_REPUTATION_RANK
Definition: SharedDefines.h:224
#define MIN_REPUTATION_RANK
Definition: SharedDefines.h:223
int32_t int32
Definition: Define.h:146

+ Here is the caller graph for this function:

void ReputationMgr::SaveToDB ( SQLTransaction trans)
545 {
546  for (FactionStateList::iterator itr = _factions.begin(); itr != _factions.end(); ++itr)
547  {
548  if (itr->second.needSave)
549  {
551  stmt->setUInt64(0, _player->GetGUID().GetCounter());
552  stmt->setUInt16(1, uint16(itr->second.ID));
553  trans->Append(stmt);
554 
556  stmt->setUInt64(0, _player->GetGUID().GetCounter());
557  stmt->setUInt16(1, uint16(itr->second.ID));
558  stmt->setInt32(2, itr->second.Standing);
559  stmt->setUInt16(3, uint16(itr->second.Flags));
560  trans->Append(stmt);
561 
562  itr->second.needSave = false;
563  }
564  }
565 }
FactionStateList _factions
Definition: ReputationMgr.h:160
Definition: CharacterDatabase.h:413
uint16_t uint16
Definition: g3dmath.h:166
Definition: PreparedStatement.h:74
Definition: CharacterDatabase.h:412
void setUInt16(const uint8 index, const uint16 value)
Definition: PreparedStatement.cpp:106
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setInt32(const uint8 index, const int32 value)
Definition: PreparedStatement.cpp:151
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
Player * _player
Definition: ReputationMgr.h:159

+ Here is the call graph for this function:

void ReputationMgr::SendForceReactions ( )
160 {
162  setForcedReactions.Reactions.resize(_forcedReactions.size());
163 
164  std::size_t i = 0;
165  for (ForcedReactions::const_iterator itr = _forcedReactions.begin(); itr != _forcedReactions.end(); ++itr)
166  {
167  WorldPackets::Reputation::ForcedReaction& forcedReaction = setForcedReactions.Reactions[i++];
168  forcedReaction.Faction = int32(itr->first);
169  forcedReaction.Reaction = int32(itr->second);
170  }
171 
172  _player->SendDirectMessage(setForcedReactions.Write());
173 }
Definition: ReputationPackets.h:63
int32 Faction
Definition: ReputationPackets.h:59
WorldPacket const * Write() override
Definition: ReputationPackets.cpp:43
ForcedReactions _forcedReactions
Definition: ReputationMgr.h:161
int32 Reaction
Definition: ReputationPackets.h:60
Definition: ReputationPackets.h:57
std::vector< ForcedReaction > Reactions
Definition: ReputationPackets.h:70
int32_t int32
Definition: g3dmath.h:167
Player * _player
Definition: ReputationMgr.h:159

+ Here is the call graph for this function:

void ReputationMgr::SendInitialReputations ( )
Todo:
faction bonus
198 {
200 
201  for (FactionStateList::iterator itr = _factions.begin(); itr != _factions.end(); ++itr)
202  {
203  initFactions.FactionFlags[itr->first] = itr->second.Flags;
204  initFactions.FactionStandings[itr->first] = itr->second.Standing;
206  itr->second.needSend = false;
207  }
208 
209  _player->SendDirectMessage(initFactions.Write());
210 }
FactionStateList _factions
Definition: ReputationMgr.h:160
uint8 FactionFlags[FactionCount]
Definition: ReputationPackets.h:46
Definition: ReputationPackets.h:29
WorldPacket const * Write() override
Definition: ReputationPackets.cpp:20
Player * _player
Definition: ReputationMgr.h:159
int32 FactionStandings[FactionCount]
Definition: ReputationPackets.h:44

+ Here is the call graph for this function:

void ReputationMgr::SendState ( FactionState const faction)
176 {
178  setFactionStanding.ReferAFriendBonus = 0.0f;
179  setFactionStanding.BonusFromAchievementSystem = 0.0f;
180  setFactionStanding.Faction.emplace_back(int32(faction->ReputationListID), faction->Standing);
181  for (FactionStateList::iterator itr = _factions.begin(); itr != _factions.end(); ++itr)
182  {
183  if (itr->second.needSend)
184  {
185  itr->second.needSend = false;
186  if (itr->second.ReputationListID != faction->ReputationListID)
187  setFactionStanding.Faction.emplace_back(int32(itr->second.ReputationListID), itr->second.Standing);
188  }
189  }
190 
191  setFactionStanding.ShowVisual = _sendFactionIncreased;
192  _player->SendDirectMessage(setFactionStanding.Write());
193 
194  _sendFactionIncreased = false; // Reset
195 }
float ReferAFriendBonus
Definition: ReputationPackets.h:89
FactionStateList _factions
Definition: ReputationMgr.h:160
std::vector< FactionStandingData > Faction
Definition: ReputationPackets.h:91
bool ShowVisual
Definition: ReputationPackets.h:92
bool _sendFactionIncreased
Definition: ReputationMgr.h:166
Definition: ReputationPackets.h:82
WorldPacket const * Write() override
Definition: ReputationPackets.cpp:61
int32_t int32
Definition: g3dmath.h:167
float BonusFromAchievementSystem
Definition: ReputationPackets.h:90
Player * _player
Definition: ReputationMgr.h:159

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ReputationMgr::SendStates ( )
213 {
214  for (FactionStateList::iterator itr = _factions.begin(); itr != _factions.end(); ++itr)
215  SendState(&(itr->second));
216 }
void SendState(FactionState const *faction)
Definition: ReputationMgr.cpp:175
FactionStateList _factions
Definition: ReputationMgr.h:160

+ Here is the call graph for this function:

void ReputationMgr::SendVisible ( FactionState const faction,
bool  visible = true 
) const
private
219 {
220  if (_player->GetSession()->PlayerLoading())
221  return;
222 
223  // make faction visible/not visible in reputation list at client
225  packet.FactionIndex = faction->ReputationListID;
226  _player->SendDirectMessage(packet.Write());
227 }
Definition: CharacterPackets.h:682
Player * _player
Definition: ReputationMgr.h:159

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ReputationMgr::SetAtWar ( RepListID  repListID,
bool  on 
)
425 {
426  FactionStateList::iterator itr = _factions.find(repListID);
427  if (itr == _factions.end())
428  return;
429 
430  // always invisible or hidden faction can't change war state
431  if (itr->second.Flags & (FACTION_FLAG_INVISIBLE_FORCED|FACTION_FLAG_HIDDEN))
432  return;
433 
434  SetAtWar(&itr->second, on);
435 }
Definition: ReputationMgr.h:41
FactionStateList _factions
Definition: ReputationMgr.h:160
void SetAtWar(RepListID repListID, bool on)
Definition: ReputationMgr.cpp:424
Definition: ReputationMgr.h:40

+ Here is the caller graph for this function:

void ReputationMgr::SetAtWar ( FactionState faction,
bool  atWar 
) const
private
438 {
439  // not allow declare war to own faction
440  if (atWar && (faction->Flags & FACTION_FLAG_PEACE_FORCED))
441  return;
442 
443  // already set
444  if (((faction->Flags & FACTION_FLAG_AT_WAR) != 0) == atWar)
445  return;
446 
447  if (atWar)
448  faction->Flags |= FACTION_FLAG_AT_WAR;
449  else
450  faction->Flags &= ~FACTION_FLAG_AT_WAR;
451 
452  faction->needSend = true;
453  faction->needSave = true;
454 }
Definition: ReputationMgr.h:39
Definition: ReputationMgr.h:42
bool needSend
Definition: ReputationMgr.h:55
uint8 Flags
Definition: ReputationMgr.h:54
bool needSave
Definition: ReputationMgr.h:56
void ReputationMgr::SetInactive ( RepListID  repListID,
bool  on 
)
457 {
458  FactionStateList::iterator itr = _factions.find(repListID);
459  if (itr == _factions.end())
460  return;
461 
462  SetInactive(&itr->second, on);
463 }
FactionStateList _factions
Definition: ReputationMgr.h:160
void SetInactive(RepListID repListID, bool on)
Definition: ReputationMgr.cpp:456

+ Here is the caller graph for this function:

void ReputationMgr::SetInactive ( FactionState faction,
bool  inactive 
) const
private
466 {
467  // always invisible or hidden faction can't be inactive
468  if (inactive && ((faction->Flags & (FACTION_FLAG_INVISIBLE_FORCED|FACTION_FLAG_HIDDEN)) || !(faction->Flags & FACTION_FLAG_VISIBLE)))
469  return;
470 
471  // already set
472  if (((faction->Flags & FACTION_FLAG_INACTIVE) != 0) == inactive)
473  return;
474 
475  if (inactive)
476  faction->Flags |= FACTION_FLAG_INACTIVE;
477  else
478  faction->Flags &= ~FACTION_FLAG_INACTIVE;
479 
480  faction->needSend = true;
481  faction->needSave = true;
482 }
Definition: ReputationMgr.h:41
Definition: ReputationMgr.h:43
Definition: ReputationMgr.h:40
bool needSend
Definition: ReputationMgr.h:55
uint8 Flags
Definition: ReputationMgr.h:54
Definition: ReputationMgr.h:38
bool needSave
Definition: ReputationMgr.h:56
bool ReputationMgr::SetOneFactionReputation ( FactionEntry const factionEntry,
int32  standing,
bool  incremental 
)

Public for chat command needs.

334 {
335  FactionStateList::iterator itr = _factions.find(factionEntry->ReputationIndex);
336  if (itr != _factions.end())
337  {
338  int32 BaseRep = GetBaseReputation(factionEntry);
339 
340  if (incremental)
341  {
342  // int32 *= float cause one point loss?
343  standing = int32(floor((float)standing * sWorld->getRate(RATE_REPUTATION_GAIN) + 0.5f));
344  standing += itr->second.Standing + BaseRep;
345  }
346 
347  if (standing > Reputation_Cap)
348  standing = Reputation_Cap;
349  else if (standing < Reputation_Bottom)
350  standing = Reputation_Bottom;
351 
352  ReputationRank old_rank = ReputationToRank(itr->second.Standing + BaseRep);
353  ReputationRank new_rank = ReputationToRank(standing);
354 
355  itr->second.Standing = standing - BaseRep;
356  itr->second.needSend = true;
357  itr->second.needSave = true;
358 
359  SetVisible(&itr->second);
360 
361  if (new_rank <= REP_HOSTILE)
362  SetAtWar(&itr->second, true);
363 
364  if (new_rank > old_rank)
365  _sendFactionIncreased = true;
366 
367  UpdateRankCounters(old_rank, new_rank);
368 
369  _player->ReputationChanged(factionEntry);
370  _player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KNOWN_FACTIONS, factionEntry->ID);
371  _player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION, factionEntry->ID);
372  _player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION, factionEntry->ID);
373  _player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_REVERED_REPUTATION, factionEntry->ID);
374  _player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_GAIN_HONORED_REPUTATION, factionEntry->ID);
375 
376  return true;
377  }
378  return false;
379 }
static ReputationRank ReputationToRank(int32 standing)
Definition: ReputationMgr.cpp:37
ReputationRank
Definition: SharedDefines.h:211
FactionStateList _factions
Definition: ReputationMgr.h:160
static Vector3int16 floor(const Vector3 &v)
static const int32 Reputation_Cap
Definition: ReputationMgr.h:75
void SetAtWar(RepListID repListID, bool on)
Definition: ReputationMgr.cpp:424
#define sWorld
Definition: World.h:887
int32 GetBaseReputation(FactionEntry const *factionEntry) const
Definition: ReputationMgr.cpp:85
void UpdateRankCounters(ReputationRank old_rank, ReputationRank new_rank)
Definition: ReputationMgr.cpp:567
bool _sendFactionIncreased
Definition: ReputationMgr.h:166
Definition: SharedDefines.h:214
int32_t int32
Definition: Define.h:146
void SetVisible(FactionTemplateEntry const *factionTemplateEntry)
Definition: ReputationMgr.cpp:381
Definition: World.h:408
static const int32 Reputation_Bottom
Definition: ReputationMgr.h:76
int32_t int32
Definition: g3dmath.h:167
Player * _player
Definition: ReputationMgr.h:159

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool ReputationMgr::SetReputation ( FactionEntry const factionEntry,
int32  standing 
)
inline
125  {
126  return SetReputation(factionEntry, standing, false);
127  }
bool SetReputation(FactionEntry const *factionEntry, int32 standing)
Definition: ReputationMgr.h:124
bool ReputationMgr::SetReputation ( FactionEntry const factionEntry,
int32  standing,
bool  incremental 
)
private
263 {
264  sScriptMgr->OnPlayerReputationChange(_player, factionEntry->ID, standing, incremental);
265  bool res = false;
266  // if spillover definition exists in DB, override DBC
267  if (const RepSpilloverTemplate* repTemplate = sObjectMgr->GetRepSpilloverTemplate(factionEntry->ID))
268  {
269  for (uint32 i = 0; i < MAX_SPILLOVER_FACTIONS; ++i)
270  {
271  if (repTemplate->faction[i])
272  {
273  if (_player->GetReputationRank(repTemplate->faction[i]) <= ReputationRank(repTemplate->faction_rank[i]))
274  {
275  // bonuses are already given, so just modify standing by rate
276  int32 spilloverRep = int32(standing * repTemplate->faction_rate[i]);
277  SetOneFactionReputation(sFactionStore.AssertEntry(repTemplate->faction[i]), spilloverRep, incremental);
278  }
279  }
280  }
281  }
282  else
283  {
284  float spillOverRepOut = float(standing);
285  // check for sub-factions that receive spillover
286  std::vector<uint32> const* flist = GetFactionTeamList(factionEntry->ID);
287  // if has no sub-factions, check for factions with same parent
288  if (!flist && factionEntry->ParentFactionID && factionEntry->ParentFactionModOut != 0.0f)
289  {
290  spillOverRepOut *= factionEntry->ParentFactionModOut;
291  if (FactionEntry const* parent = sFactionStore.LookupEntry(factionEntry->ParentFactionID))
292  {
293  FactionStateList::iterator parentState = _factions.find(parent->ReputationIndex);
294  // some team factions have own reputation standing, in this case do not spill to other sub-factions
295  if (parentState != _factions.end() && (parentState->second.Flags & FACTION_FLAG_SPECIAL))
296  {
297  SetOneFactionReputation(parent, int32(spillOverRepOut), incremental);
298  }
299  else // spill to "sister" factions
300  {
301  flist = GetFactionTeamList(factionEntry->ParentFactionID);
302  }
303  }
304  }
305  if (flist)
306  {
307  // Spillover to affiliated factions
308  for (std::vector<uint32>::const_iterator itr = flist->begin(); itr != flist->end(); ++itr)
309  {
310  if (FactionEntry const* factionEntryCalc = sFactionStore.LookupEntry(*itr))
311  {
312  if (factionEntryCalc == factionEntry || GetRank(factionEntryCalc) > ReputationRank(factionEntryCalc->ParentFactionCapIn))
313  continue;
314  int32 spilloverRep = int32(spillOverRepOut * factionEntryCalc->ParentFactionModIn);
315  if (spilloverRep != 0 || !incremental)
316  res = SetOneFactionReputation(factionEntryCalc, spilloverRep, incremental);
317  }
318  }
319  }
320  }
321 
322  // spillover done, update faction itself
323  FactionStateList::iterator faction = _factions.find(factionEntry->ReputationIndex);
324  if (faction != _factions.end())
325  {
326  res = SetOneFactionReputation(factionEntry, standing, incremental);
327  // only this faction gets reported to client, even if it has no own visible standing
328  SendState(&faction->second);
329  }
330  return res;
331 }
void SendState(FactionState const *faction)
Definition: ReputationMgr.cpp:175
ReputationRank
Definition: SharedDefines.h:211
FactionStateList _factions
Definition: ReputationMgr.h:160
#define MAX_SPILLOVER_FACTIONS
Definition: SharedDefines.h:226
#define sObjectMgr
Definition: ObjectMgr.h:1567
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
Definition: ReputationMgr.h:45
Definition: DBCStructure.h:405
int32_t int32
Definition: g3dmath.h:167
ReputationRank GetRank(FactionEntry const *factionEntry) const
Definition: ReputationMgr.cpp:119
DBCStorage< FactionEntry > sFactionStore(Factionfmt)
#define sScriptMgr
Definition: ScriptMgr.h:837
bool SetOneFactionReputation(FactionEntry const *factionEntry, int32 standing, bool incremental)
Public for chat command needs.
Definition: ReputationMgr.cpp:333
Player * _player
Definition: ReputationMgr.h:159
std::vector< uint32 > const * GetFactionTeamList(uint32 faction)
Definition: DBCStores.cpp:552
Definition: ObjectMgr.h:493

+ Here is the call graph for this function:

void ReputationMgr::SetVisible ( FactionTemplateEntry const factionTemplateEntry)
382 {
383  if (!factionTemplateEntry->Faction)
384  return;
385 
386  if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionTemplateEntry->Faction))
387  // Never show factions of the opposing team
388  if (!(factionEntry->ReputationRaceMask[1] & _player->getRaceMask() && factionEntry->ReputationBase[1] == Reputation_Bottom))
389  SetVisible(factionEntry);
390 }
void SetVisible(FactionTemplateEntry const *factionTemplateEntry)
Definition: ReputationMgr.cpp:381
Definition: DBCStructure.h:405
static const int32 Reputation_Bottom
Definition: ReputationMgr.h:76
DBCStorage< FactionEntry > sFactionStore(Factionfmt)
Player * _player
Definition: ReputationMgr.h:159

+ Here is the caller graph for this function:

void ReputationMgr::SetVisible ( FactionEntry const factionEntry)
393 {
394  if (!factionEntry->CanHaveReputation())
395  return;
396 
397  FactionStateList::iterator itr = _factions.find(factionEntry->ReputationIndex);
398  if (itr == _factions.end())
399  return;
400 
401  SetVisible(&itr->second);
402 }
FactionStateList _factions
Definition: ReputationMgr.h:160
void SetVisible(FactionTemplateEntry const *factionTemplateEntry)
Definition: ReputationMgr.cpp:381

+ Here is the call graph for this function:

void ReputationMgr::SetVisible ( FactionState faction)
private
405 {
406  // always invisible or hidden faction can't be make visible
407  // except if faction has FACTION_FLAG_SPECIAL
409  return;
410 
411  // already set
412  if (faction->Flags & FACTION_FLAG_VISIBLE)
413  return;
414 
415  faction->Flags |= FACTION_FLAG_VISIBLE;
416  faction->needSend = true;
417  faction->needSave = true;
418 
420 
421  SendVisible(faction);
422 }
Definition: ReputationMgr.h:41
uint8 _visibleFactionCount
Definition: ReputationMgr.h:162
void SendVisible(FactionState const *faction, bool visible=true) const
Definition: ReputationMgr.cpp:218
Definition: ReputationMgr.h:40
Definition: ReputationMgr.h:45
bool needSend
Definition: ReputationMgr.h:55
uint8 Flags
Definition: ReputationMgr.h:54
Definition: ReputationMgr.h:38
bool needSave
Definition: ReputationMgr.h:56

+ Here is the call graph for this function:

void ReputationMgr::UpdateRankCounters ( ReputationRank  old_rank,
ReputationRank  new_rank 
)
private
568 {
569  if (old_rank >= REP_EXALTED)
571  if (old_rank >= REP_REVERED)
573  if (old_rank >= REP_HONORED)
575 
576  if (new_rank >= REP_EXALTED)
578  if (new_rank >= REP_REVERED)
580  if (new_rank >= REP_HONORED)
582 }
Definition: SharedDefines.h:220
Definition: SharedDefines.h:219
uint8 _reveredFactionCount
Definition: ReputationMgr.h:164
uint8 _exaltedFactionCount
Definition: ReputationMgr.h:165
Definition: SharedDefines.h:218
uint8 _honoredFactionCount
Definition: ReputationMgr.h:163

+ Here is the caller graph for this function:

Member Data Documentation

uint8 ReputationMgr::_exaltedFactionCount
private
FactionStateList ReputationMgr::_factions
private
ForcedReactions ReputationMgr::_forcedReactions
private
uint8 ReputationMgr::_honoredFactionCount
private
Player* ReputationMgr::_player
private
uint8 ReputationMgr::_reveredFactionCount
private
bool ReputationMgr::_sendFactionIncreased
private
uint8 ReputationMgr::_visibleFactionCount
private
const int32 ReputationMgr::PointsInRank = {36000, 3000, 3000, 3000, 6000, 12000, 21000, 1000}
static
const int32 ReputationMgr::Reputation_Bottom = -42000
static
const int32 ReputationMgr::Reputation_Cap = 42999
static

The documentation for this class was generated from the following files: