AzeorthCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
ReputationMgr Class Reference

#include "ReputationMgr.h"

Public Member Functions

 ReputationMgr (Player *owner)
 
 ~ReputationMgr ()
 
void SaveToDB (CharacterDatabaseTransaction trans)
 
void LoadFromDB (PreparedQueryResult result)
 
uint8 GetVisibleFactionCount () const
 
uint8 GetHonoredFactionCount () const
 
uint8 GetReveredFactionCount () const
 
uint8 GetExaltedFactionCount () const
 
FactionStateList const & GetStateList () const
 
FactionState const * GetState (FactionEntry const *factionEntry) const
 
FactionState const * GetState (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 const * GetForcedRankIfAny (FactionTemplateEntry const *factionTemplateEntry) const
 
bool SetReputation (FactionEntry const *factionEntry, float standing)
 
bool ModifyReputation (FactionEntry const *factionEntry, float standing, bool noSpillOver=false, Optional< ReputationRank > repMaxCap={})
 
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, float standing, bool incremental, Optional< ReputationRank > repMaxCap={ })
 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 int32 ReputationRankToStanding (ReputationRank rank)
 

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, float standing, bool incremental, bool noSpillOver=false, Optional< ReputationRank > repMaxCap={ })
 
void SetVisible (FactionState *faction)
 
void SetAtWar (FactionState *faction, bool atWar) const
 
void SetInactive (FactionState *faction, bool inactive) const
 
void SendVisible (FactionState const *faction) 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
 

Detailed Description

Constructor & Destructor Documentation

◆ ReputationMgr()

ReputationMgr::ReputationMgr ( Player owner)
inlineexplicit
60 : _player(owner),
uint8 _honoredFactionCount
Definition: ReputationMgr.h:153
uint8 _visibleFactionCount
Definition: ReputationMgr.h:152
uint8 _exaltedFactionCount
Definition: ReputationMgr.h:155
uint8 _reveredFactionCount
Definition: ReputationMgr.h:154
bool _sendFactionIncreased
Definition: ReputationMgr.h:156
Player * _player
Definition: ReputationMgr.h:149

◆ ~ReputationMgr()

ReputationMgr::~ReputationMgr ( )
inline
62{}

Member Function Documentation

◆ ApplyForceReaction()

void ReputationMgr::ApplyForceReaction ( uint32  faction_id,
ReputationRank  rank,
bool  apply 
)
138{
139 if (apply)
140 _forcedReactions[faction_id] = rank;
141 else
142 _forcedReactions.erase(faction_id);
143}
ForcedReactions _forcedReactions
Definition: ReputationMgr.h:151

References _forcedReactions.

Referenced by AuraEffect::HandleForceReaction().

◆ GetBaseRank()

ReputationRank ReputationMgr::GetBaseRank ( FactionEntry const *  factionEntry) const
132{
133 int32 reputation = GetBaseReputation(factionEntry);
134 return ReputationToRank(reputation);
135}
std::int32_t int32
Definition: Define.h:104
int32 GetBaseReputation(FactionEntry const *factionEntry) const
Definition: ReputationMgr.cpp:91
static ReputationRank ReputationToRank(int32 standing)
Definition: ReputationMgr.cpp:32

References GetBaseReputation(), and ReputationToRank().

Referenced by Initialize().

◆ GetBaseReputation()

int32 ReputationMgr::GetBaseReputation ( FactionEntry const *  factionEntry) const
92{
93 if (!factionEntry)
94 return 0;
95
96 uint32 raceMask = _player->getRaceMask();
97 uint32 classMask = _player->getClassMask();
98 for (int i = 0; i < 4; i++)
99 {
100 if ((factionEntry->BaseRepRaceMask[i] & raceMask ||
101 (factionEntry->BaseRepRaceMask[i] == 0 &&
102 factionEntry->BaseRepClassMask[i] != 0)) &&
103 (factionEntry->BaseRepClassMask[i] & classMask ||
104 factionEntry->BaseRepClassMask[i] == 0))
105
106 return factionEntry->BaseRepValue[i];
107 }
108
109 // in faction.dbc exist factions with (RepListId >=0, listed in character reputation list) with all BaseRepRaceMask[i] == 0
110 return 0;
111}
std::uint32_t uint32
Definition: Define.h:108
uint32 getRaceMask() const
Definition: Unit.h:1426
uint32 getClassMask() const
Definition: Unit.h:1428

References _player, FactionEntry::BaseRepClassMask, FactionEntry::BaseRepRaceMask, FactionEntry::BaseRepValue, Unit::getClassMask(), and Unit::getRaceMask().

Referenced by GetBaseRank(), GetReputation(), LoadFromDB(), and SetOneFactionReputation().

◆ GetDefaultStateFlags()

uint32 ReputationMgr::GetDefaultStateFlags ( FactionEntry const *  factionEntry) const
private
146{
147 if (!factionEntry)
148 return 0;
149
150 uint32 raceMask = _player->getRaceMask();
151 uint32 classMask = _player->getClassMask();
152 for (int i = 0; i < 4; i++)
153 {
154 if ((factionEntry->BaseRepRaceMask[i] & raceMask ||
155 (factionEntry->BaseRepRaceMask[i] == 0 &&
156 factionEntry->BaseRepClassMask[i] != 0)) &&
157 (factionEntry->BaseRepClassMask[i] & classMask ||
158 factionEntry->BaseRepClassMask[i] == 0))
159
160 return factionEntry->ReputationFlags[i];
161 }
162 return 0;
163}

References _player, FactionEntry::BaseRepClassMask, FactionEntry::BaseRepRaceMask, Unit::getClassMask(), Unit::getRaceMask(), and FactionEntry::ReputationFlags.

Referenced by Initialize().

◆ GetExaltedFactionCount()

uint8 ReputationMgr::GetExaltedFactionCount ( ) const
inline
78{ return _exaltedFactionCount; }

References _exaltedFactionCount.

◆ GetForcedRankIfAny()

ReputationRank const * ReputationMgr::GetForcedRankIfAny ( FactionTemplateEntry const *  factionTemplateEntry) const
inline
108 {
109 ForcedReactions::const_iterator forceItr = _forcedReactions.find(factionTemplateEntry->faction);
110 return forceItr != _forcedReactions.end() ? &forceItr->second : nullptr;
111 }

References _forcedReactions, and FactionTemplateEntry::faction.

Referenced by Unit::_IsValidAttackTarget(), and Unit::GetReactionTo().

◆ GetHonoredFactionCount()

uint8 ReputationMgr::GetHonoredFactionCount ( ) const
inline
76{ return _honoredFactionCount; }

References _honoredFactionCount.

◆ GetRank()

ReputationRank ReputationMgr::GetRank ( FactionEntry const *  factionEntry) const
126{
127 int32 reputation = GetReputation(factionEntry);
128 return ReputationToRank(reputation);
129}
int32 GetReputation(uint32 faction_id) const
Definition: ReputationMgr.cpp:78

References GetReputation(), and ReputationToRank().

Referenced by Player::GetReputationRank(), GetReputationRankStrIndex(), character_commandscript::HandleCharacterReputationCommand(), LoadFromDB(), and SetReputation().

◆ GetReputation() [1/2]

int32 ReputationMgr::GetReputation ( FactionEntry const *  factionEntry) const
114{
115 // Faction without recorded reputation. Just ignore.
116 if (!factionEntry)
117 return 0;
118
119 if (FactionState const* state = GetState(factionEntry))
120 return GetBaseReputation(factionEntry) + state->Standing;
121
122 return 0;
123}
Definition: ReputationMgr.h:42
FactionState const * GetState(FactionEntry const *factionEntry) const
Definition: ReputationMgr.h:82

References GetBaseReputation(), and GetState().

◆ GetReputation() [2/2]

int32 ReputationMgr::GetReputation ( uint32  faction_id) const
79{
80 FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id);
81
82 if (!factionEntry)
83 {
84 LOG_ERROR("reputation", "ReputationMgr::GetReputation: Can't get reputation of {} for unknown faction (faction id) #{}.", _player->GetName(), faction_id);
85 return 0;
86 }
87
88 return GetReputation(factionEntry);
89}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:159
DBCStorage< FactionEntry > sFactionStore(FactionEntryfmt)
std::string const & GetName() const
Definition: Object.h:446
Definition: DBCStructure.h:898

References _player, WorldObject::GetName(), GetReputation(), LOG_ERROR, and sFactionStore.

Referenced by GetRank(), GetReputation(), Player::GetReputation(), character_commandscript::HandleCharacterReputationCommand(), spell_gen_oracle_wolvar_reputation::HandleDummy(), lookup_commandscript::HandleLookupFactionCommand(), modify_commandscript::HandleModifyRepCommand(), and AchievementMgr::UpdateAchievementCriteria().

◆ GetReputationRankStrIndex()

uint32 ReputationMgr::GetReputationRankStrIndex ( FactionEntry const *  factionEntry) const
inline
103 {
104 return ReputationRankStrIndex[GetRank(factionEntry)];
105 };
constexpr std::array< uint32, MAX_REPUTATION_RANK > ReputationRankStrIndex
Definition: ReputationMgr.h:28
ReputationRank GetRank(FactionEntry const *factionEntry) const
Definition: ReputationMgr.cpp:125

References GetRank(), and ReputationRankStrIndex.

Referenced by lookup_commandscript::HandleLookupFactionCommand().

◆ GetReveredFactionCount()

uint8 ReputationMgr::GetReveredFactionCount ( ) const
inline
77{ return _reveredFactionCount; }

References _reveredFactionCount.

◆ GetState() [1/2]

FactionState const * ReputationMgr::GetState ( FactionEntry const *  factionEntry) const
inline

◆ GetState() [2/2]

FactionState const * ReputationMgr::GetState ( RepListID  id) const
inline
88 {
89 FactionStateList::const_iterator repItr = _factions.find (id);
90 return repItr != _factions.end() ? &repItr->second : nullptr;
91 }
FactionStateList _factions
Definition: ReputationMgr.h:150

References _factions.

◆ GetStateList()

FactionStateList const & ReputationMgr::GetStateList ( ) const
inline

◆ GetVisibleFactionCount()

uint8 ReputationMgr::GetVisibleFactionCount ( ) const
inline
75{ return _visibleFactionCount; }

References _visibleFactionCount.

◆ Initialize()

void ReputationMgr::Initialize ( )
private
264{
265 _factions.clear();
270 _sendFactionIncreased = false;
271
272 for (unsigned int i = 1; i < sFactionStore.GetNumRows(); i++)
273 {
274 FactionEntry const* factionEntry = sFactionStore.LookupEntry(i);
275
276 if (factionEntry && (factionEntry->reputationListID >= 0))
277 {
278 FactionState newFaction;
279 newFaction.ID = factionEntry->ID;
280 newFaction.ReputationListID = factionEntry->reputationListID;
281 newFaction.Standing = 0;
282 newFaction.Flags = GetDefaultStateFlags(factionEntry);
283 newFaction.needSend = true;
284 newFaction.needSave = true;
285 newFaction.roundedUp = false;
286
287 if (newFaction.Flags & FACTION_FLAG_VISIBLE)
289
291
292 _factions[newFaction.ReputationListID] = newFaction;
293 }
294 }
295}
@ FACTION_FLAG_VISIBLE
Definition: DBCEnums.h:312
@ REP_HOSTILE
Definition: SharedDefines.h:153
RepListID ReputationListID
Definition: ReputationMgr.h:44
bool roundedUp
Definition: ReputationMgr.h:49
uint32 ID
Definition: ReputationMgr.h:43
bool needSave
Definition: ReputationMgr.h:48
bool needSend
Definition: ReputationMgr.h:47
uint8 Flags
Definition: ReputationMgr.h:46
int32 Standing
Definition: ReputationMgr.h:45
ReputationRank GetBaseRank(FactionEntry const *factionEntry) const
Definition: ReputationMgr.cpp:131
uint32 GetDefaultStateFlags(FactionEntry const *factionEntry) const
Definition: ReputationMgr.cpp:145
void UpdateRankCounters(ReputationRank old_rank, ReputationRank new_rank)
Definition: ReputationMgr.cpp:648
uint32 ID
Definition: DBCStructure.h:899
int32 reputationListID
Definition: DBCStructure.h:900

References _exaltedFactionCount, _factions, _honoredFactionCount, _reveredFactionCount, _sendFactionIncreased, _visibleFactionCount, FACTION_FLAG_VISIBLE, FactionState::Flags, GetBaseRank(), GetDefaultStateFlags(), FactionState::ID, FactionEntry::ID, FactionState::needSave, FactionState::needSend, REP_HOSTILE, FactionState::ReputationListID, FactionEntry::reputationListID, FactionState::roundedUp, sFactionStore, FactionState::Standing, and UpdateRankCounters().

Referenced by LoadFromDB().

◆ IsAtWar() [1/2]

bool ReputationMgr::IsAtWar ( FactionEntry const *  factionEntry) const
69{
70 if (!factionEntry)
71 return false;
72
73 if (FactionState const* factionState = GetState(factionEntry))
74 return (factionState->Flags & FACTION_FLAG_AT_WAR);
75 return false;
76}
@ FACTION_FLAG_AT_WAR
Definition: DBCEnums.h:313

References FACTION_FLAG_AT_WAR, and GetState().

◆ IsAtWar() [2/2]

bool ReputationMgr::IsAtWar ( uint32  faction_id) const
56{
57 FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id);
58
59 if (!factionEntry)
60 {
61 LOG_ERROR("reputation", "ReputationMgr::IsAtWar: Can't get AtWar flag of {} for unknown faction (faction id) #{}.", _player->GetName(), faction_id);
62 return 0;
63 }
64
65 return IsAtWar(factionEntry);
66}
bool IsAtWar(uint32 faction_id) const
Definition: ReputationMgr.cpp:55

References _player, WorldObject::GetName(), IsAtWar(), LOG_ERROR, and sFactionStore.

Referenced by Unit::GetReactionTo(), and IsAtWar().

◆ LoadFromDB()

void ReputationMgr::LoadFromDB ( PreparedQueryResult  result)
562{
563 // Set initial reputations (so everything is nifty before DB data load)
564 Initialize();
565
566 //QueryResult* result = CharacterDatabase.Query("SELECT faction, standing, flags FROM character_reputation WHERE guid = '{}'", GetGUID().GetCounter());
567
568 if (result)
569 {
570 do
571 {
572 Field* fields = result->Fetch();
573
574 FactionEntry const* factionEntry = sFactionStore.LookupEntry(fields[0].Get<uint16>());
575 if (factionEntry && (factionEntry->reputationListID >= 0))
576 {
577 FactionState* faction = &_factions[factionEntry->reputationListID];
578
579 // update standing to current
580 faction->Standing = fields[1].Get<int32>();
581
582 // update counters
583 int32 BaseRep = GetBaseReputation(factionEntry);
584 ReputationRank old_rank = ReputationToRank(BaseRep);
585 ReputationRank new_rank = ReputationToRank(BaseRep + faction->Standing);
586 UpdateRankCounters(old_rank, new_rank);
587
588 uint32 dbFactionFlags = fields[2].Get<uint16>();
589
590 if (dbFactionFlags & FACTION_FLAG_VISIBLE)
591 SetVisible(faction); // have internal checks for forced invisibility
592
593 if (dbFactionFlags & FACTION_FLAG_INACTIVE)
594 SetInactive(faction, true); // have internal checks for visibility requirement
595
596 if (dbFactionFlags & FACTION_FLAG_AT_WAR) // DB at war
597 {
598 // Xinef: dont set at war for friendly hidden reputations
599 SetAtWar(faction, bool(!(dbFactionFlags & FACTION_FLAG_HIDDEN) || GetRank(factionEntry) < REP_NEUTRAL)); // have internal checks for FACTION_FLAG_PEACE_FORCED
600 }
601 else // DB not at war
602 {
603 // allow remove if visible (and then not FACTION_FLAG_INVISIBLE_FORCED or FACTION_FLAG_HIDDEN)
604 if (faction->Flags & FACTION_FLAG_VISIBLE)
605 SetAtWar(faction, false); // have internal checks for FACTION_FLAG_PEACE_FORCED
606 }
607
608 // set atWar for hostile
609 if (GetRank(factionEntry) <= REP_HOSTILE)
610 SetAtWar(faction, true);
611
612 // reset changed flag if values similar to saved in DB
613 if (faction->Flags == dbFactionFlags)
614 {
615 faction->needSend = false;
616 faction->needSave = false;
617 }
618
619 faction->roundedUp = false;
620 }
621 } while (result->NextRow());
622 }
623}
std::uint16_t uint16
Definition: Define.h:109
@ FACTION_FLAG_INACTIVE
Definition: DBCEnums.h:317
@ FACTION_FLAG_HIDDEN
Definition: DBCEnums.h:314
ReputationRank
Definition: SharedDefines.h:151
@ REP_NEUTRAL
Definition: SharedDefines.h:155
Class used to access individual fields of database query result.
Definition: Field.h:99
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113
void SetVisible(FactionTemplateEntry const *factionTemplateEntry)
Definition: ReputationMgr.cpp:458
void SetAtWar(RepListID repListID, bool on)
Definition: ReputationMgr.cpp:501
void Initialize()
Definition: ReputationMgr.cpp:263
void SetInactive(RepListID repListID, bool on)
Definition: ReputationMgr.cpp:533

References _factions, FACTION_FLAG_AT_WAR, FACTION_FLAG_HIDDEN, FACTION_FLAG_INACTIVE, FACTION_FLAG_VISIBLE, FactionState::Flags, Field::Get(), GetBaseReputation(), GetRank(), Initialize(), FactionState::needSave, FactionState::needSend, REP_HOSTILE, REP_NEUTRAL, FactionEntry::reputationListID, ReputationToRank(), FactionState::roundedUp, SetAtWar(), SetInactive(), SetVisible(), sFactionStore, FactionState::Standing, and UpdateRankCounters().

Referenced by Player::LoadFromDB().

◆ ModifyReputation()

bool ReputationMgr::ModifyReputation ( FactionEntry const *  factionEntry,
float  standing,
bool  noSpillOver = false,
Optional< ReputationRank repMaxCap = {} 
)
inline
118 {})
119 {
120 return SetReputation(factionEntry, standing, true, noSpillOver, repMaxCap);
121 }
bool SetReputation(FactionEntry const *factionEntry, float standing)
Definition: ReputationMgr.h:114

Referenced by Spell::EffectReputation(), OutdoorPvPSI::HandleAreaTrigger(), and Player::RewardReputation().

◆ ReputationRankToStanding()

int32 ReputationMgr::ReputationRankToStanding ( ReputationRank  rank)
static
45{
46 int32 standing = Reputation_Bottom;
47 for (uint8 i = MIN_REPUTATION_RANK; i <= rank; ++i)
48 {
49 standing += PointsInRank[i];
50 }
51
52 return std::max(standing - 1, Reputation_Bottom);
53}
std::uint8_t uint8
Definition: Define.h:110
#define MIN_REPUTATION_RANK
Definition: SharedDefines.h:216
static const int32 PointsInRank[MAX_REPUTATION_RANK]
Definition: ReputationMgr.h:67
static const int32 Reputation_Bottom
Definition: ReputationMgr.h:69

References MIN_REPUTATION_RANK, PointsInRank, and Reputation_Bottom.

Referenced by SetOneFactionReputation().

◆ ReputationToRank()

ReputationRank ReputationMgr::ReputationToRank ( int32  standing)
static
33{
34 int32 limit = Reputation_Cap + 1;
35 for (int i = MAX_REPUTATION_RANK - 1; i >= MIN_REPUTATION_RANK; --i)
36 {
37 limit -= PointsInRank[i];
38 if (standing >= limit)
39 return ReputationRank(i);
40 }
42}
#define MAX_REPUTATION_RANK
Definition: SharedDefines.h:217
static const int32 Reputation_Cap
Definition: ReputationMgr.h:68

References MAX_REPUTATION_RANK, MIN_REPUTATION_RANK, PointsInRank, and Reputation_Cap.

Referenced by GetBaseRank(), GetRank(), LoadFromDB(), and SetOneFactionReputation().

◆ SaveToDB()

void ReputationMgr::SaveToDB ( CharacterDatabaseTransaction  trans)
626{
627 for (FactionStateList::iterator itr = _factions.begin(); itr != _factions.end(); ++itr)
628 {
629 if (itr->second.needSave)
630 {
632 stmt->SetData(0, _player->GetGUID().GetCounter());
633 stmt->SetData(1, uint16(itr->second.ID));
634 trans->Append(stmt);
635
636 stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_REPUTATION_BY_FACTION);
637 stmt->SetData(0, _player->GetGUID().GetCounter());
638 stmt->SetData(1, uint16(itr->second.ID));
639 stmt->SetData(2, itr->second.Standing);
640 stmt->SetData(3, uint16(itr->second.Flags));
641 trans->Append(stmt);
642
643 itr->second.needSave = false;
644 }
645 }
646}
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
@ CHAR_INS_CHAR_REPUTATION_BY_FACTION
Definition: CharacterDatabase.h:369
@ CHAR_DEL_CHAR_REPUTATION_BY_FACTION
Definition: CharacterDatabase.h:368
Definition: PreparedStatement.h:158
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:78
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
LowType GetCounter() const
Definition: ObjectGuid.h:147

References _factions, _player, CHAR_DEL_CHAR_REPUTATION_BY_FACTION, CHAR_INS_CHAR_REPUTATION_BY_FACTION, CharacterDatabase, ObjectGuid::GetCounter(), Object::GetGUID(), and PreparedStatementBase::SetData().

Referenced by Player::SaveToDB().

◆ SendForceReactions()

void ReputationMgr::SendForceReactions ( )
166{
167 WorldPacket data;
168 data.Initialize(SMSG_SET_FORCED_REACTIONS, 4 + _forcedReactions.size() * (4 + 4));
169 data << uint32(_forcedReactions.size());
170 for (ForcedReactions::const_iterator itr = _forcedReactions.begin(); itr != _forcedReactions.end(); ++itr)
171 {
172 data << uint32(itr->first); // faction_id (Faction.dbc)
173 data << uint32(itr->second); // reputation rank
174 }
176}
@ SMSG_SET_FORCED_REACTIONS
Definition: Opcodes.h:707
void SendDirectMessage(WorldPacket const *data) const
Definition: Player.cpp:5578
Definition: WorldPacket.h:27
void Initialize(uint16 opcode, size_t newres=200)
Definition: WorldPacket.h:69

References _forcedReactions, _player, WorldPacket::Initialize(), Player::SendDirectMessage(), and SMSG_SET_FORCED_REACTIONS.

Referenced by AuraEffect::HandleForceReaction(), and Player::SendInitialPacketsBeforeAddToMap().

◆ SendInitialReputations()

void ReputationMgr::SendInitialReputations ( )
212{
213 WorldPacket data(SMSG_INITIALIZE_FACTIONS, (4 + 128 * 5));
214 data << uint32 (0x00000080);
215
216 RepListID a = 0;
217
218 for (FactionStateList::iterator itr = _factions.begin(); itr != _factions.end(); ++itr)
219 {
220 // fill in absent fields
221 for (; a != itr->first; a++)
222 {
223 data << uint8 (0x00);
224 data << uint32 (0x00000000);
225 }
226
227 // fill in encountered data
228 data << uint8 (itr->second.Flags);
229 data << uint32 (itr->second.Standing);
230
231 itr->second.needSend = false;
232
233 ++a;
234 }
235
236 // fill in absent fields
237 for (; a != 128; a++)
238 {
239 data << uint8 (0x00);
240 data << uint32 (0x00000000);
241 }
242
244}
uint32 RepListID
Definition: ReputationMgr.h:40
@ SMSG_INITIALIZE_FACTIONS
Definition: Opcodes.h:320

References _factions, _player, Player::SendDirectMessage(), and SMSG_INITIALIZE_FACTIONS.

Referenced by Player::SendInitialPacketsBeforeAddToMap().

◆ SendState()

void ReputationMgr::SendState ( FactionState const *  faction)
179{
180 uint32 count = 1;
181
183 data << float(0);
185 _sendFactionIncreased = false; // Reset
186
187 size_t p_count = data.wpos();
188 data << uint32(count);
189
190 data << uint32(faction->ReputationListID);
191 data << uint32(faction->Standing);
192
193 for (FactionStateList::iterator itr = _factions.begin(); itr != _factions.end(); ++itr)
194 {
195 if (itr->second.needSend)
196 {
197 itr->second.needSend = false;
198 if (itr->second.ReputationListID != faction->ReputationListID)
199 {
200 data << uint32(itr->second.ReputationListID);
201 data << uint32(itr->second.Standing);
202 ++count;
203 }
204 }
205 }
206
207 data.put<uint32>(p_count, count);
209}
@ SMSG_SET_FACTION_STANDING
Definition: Opcodes.h:322

References _factions, _player, _sendFactionIncreased, ByteBuffer::put(), FactionState::ReputationListID, Player::SendDirectMessage(), SMSG_SET_FACTION_STANDING, FactionState::Standing, and ByteBuffer::wpos().

Referenced by modify_commandscript::HandleModifyRepCommand(), SendStates(), and SetReputation().

◆ SendStates()

void ReputationMgr::SendStates ( )
247{
248 for (FactionStateList::iterator itr = _factions.begin(); itr != _factions.end(); ++itr)
249 SendState(&(itr->second));
250}
void SendState(FactionState const *faction)
Definition: ReputationMgr.cpp:178

References _factions, and SendState().

Referenced by WorldSession::HandlePlayerLoginFromDB(), and WorldSession::HandleSetFactionCheat().

◆ SendVisible()

void ReputationMgr::SendVisible ( FactionState const *  faction) const
private
253{
255 return;
256
257 // make faction visible in reputation list at client
259 data << faction->ReputationListID;
261}
@ SMSG_SET_FACTION_VISIBLE
Definition: Opcodes.h:321
WorldSession * GetSession() const
Definition: Player.h:1947
bool PlayerLoading() const
Definition: WorldSession.h:335

References _player, Player::GetSession(), WorldSession::PlayerLoading(), FactionState::ReputationListID, Player::SendDirectMessage(), and SMSG_SET_FACTION_VISIBLE.

Referenced by SetVisible().

◆ SetAtWar() [1/2]

void ReputationMgr::SetAtWar ( FactionState faction,
bool  atWar 
) const
private
515{
516 // not allow declare war to own faction
517 if (atWar && (faction->Flags & FACTION_FLAG_PEACE_FORCED))
518 return;
519
520 // already set
521 if (((faction->Flags & FACTION_FLAG_AT_WAR) != 0) == atWar)
522 return;
523
524 if (atWar)
525 faction->Flags |= FACTION_FLAG_AT_WAR;
526 else
527 faction->Flags &= ~FACTION_FLAG_AT_WAR;
528
529 faction->needSend = true;
530 faction->needSave = true;
531}
@ FACTION_FLAG_PEACE_FORCED
Definition: DBCEnums.h:316

References FACTION_FLAG_AT_WAR, FACTION_FLAG_PEACE_FORCED, FactionState::Flags, FactionState::needSave, and FactionState::needSend.

◆ SetAtWar() [2/2]

void ReputationMgr::SetAtWar ( RepListID  repListID,
bool  on 
)
502{
503 FactionStateList::iterator itr = _factions.find(repListID);
504 if (itr == _factions.end())
505 return;
506
507 // always invisible or hidden faction can't change war state
508 if (itr->second.Flags & (FACTION_FLAG_INVISIBLE_FORCED | FACTION_FLAG_HIDDEN))
509 return;
510
511 SetAtWar(&itr->second, on);
512}
@ FACTION_FLAG_INVISIBLE_FORCED
Definition: DBCEnums.h:315

References _factions, FACTION_FLAG_HIDDEN, FACTION_FLAG_INVISIBLE_FORCED, and SetAtWar().

Referenced by WorldSession::HandleSetFactionAtWar(), LoadFromDB(), SetAtWar(), and SetOneFactionReputation().

◆ SetInactive() [1/2]

void ReputationMgr::SetInactive ( FactionState faction,
bool  inactive 
) const
private
543{
544 // always invisible or hidden faction can't be inactive
545 if (inactive && ((faction->Flags & (FACTION_FLAG_INVISIBLE_FORCED | FACTION_FLAG_HIDDEN)) || !(faction->Flags & FACTION_FLAG_VISIBLE)))
546 return;
547
548 // already set
549 if (((faction->Flags & FACTION_FLAG_INACTIVE) != 0) == inactive)
550 return;
551
552 if (inactive)
553 faction->Flags |= FACTION_FLAG_INACTIVE;
554 else
555 faction->Flags &= ~FACTION_FLAG_INACTIVE;
556
557 faction->needSend = true;
558 faction->needSave = true;
559}

References FACTION_FLAG_HIDDEN, FACTION_FLAG_INACTIVE, FACTION_FLAG_INVISIBLE_FORCED, FACTION_FLAG_VISIBLE, FactionState::Flags, FactionState::needSave, and FactionState::needSend.

◆ SetInactive() [2/2]

void ReputationMgr::SetInactive ( RepListID  repListID,
bool  on 
)
534{
535 FactionStateList::iterator itr = _factions.find(repListID);
536 if (itr == _factions.end())
537 return;
538
539 SetInactive(&itr->second, on);
540}

References _factions, and SetInactive().

Referenced by WorldSession::HandleSetFactionInactiveOpcode(), LoadFromDB(), and SetInactive().

◆ SetOneFactionReputation()

bool ReputationMgr::SetOneFactionReputation ( FactionEntry const *  factionEntry,
float  standing,
bool  incremental,
Optional< ReputationRank repMaxCap = { } 
)

Public for chat command needs.

379{
380 FactionStateList::iterator itr = _factions.find(factionEntry->reputationListID);
381 if (itr != _factions.end())
382 {
383 int32 BaseRep = GetBaseReputation(factionEntry);
384
385 if (incremental)
386 {
387 stand *= sWorld->getRate(RATE_REPUTATION_GAIN);
388 }
389
390 int32 standing = 0;
391 float stand2;
392 if (fabs(modff(stand, &stand2)) < 1.f)
393 {
394 if (itr->second.roundedUp)
395 {
396 standing = static_cast<int32>(ceil(stand));
397 }
398 else
399 {
400 standing = static_cast<int32>(stand);
401 }
402
403 itr->second.roundedUp = !itr->second.roundedUp;
404 }
405
406 if (incremental)
407 {
408 standing += itr->second.Standing + BaseRep;
409 }
410
411 if (standing > Reputation_Cap)
412 standing = Reputation_Cap;
413 else if (standing < Reputation_Bottom)
414 standing = Reputation_Bottom;
415
416 ReputationRank old_rank = ReputationToRank(itr->second.Standing + BaseRep);
417 ReputationRank new_rank = ReputationToRank(standing);
418 if (repMaxCap && new_rank > *repMaxCap)
419 {
420 standing = ReputationRankToStanding(*repMaxCap);
421 new_rank = *repMaxCap;
422 }
423
424 if (sScriptMgr->OnPlayerReputationChange(_player, factionEntry->ID, standing, incremental))
425 {
426 itr->second.Standing = standing - BaseRep;
427 itr->second.needSend = true;
428 itr->second.needSave = true;
429
430 SetVisible(&itr->second);
431
432 if (new_rank <= REP_HOSTILE)
433 SetAtWar(&itr->second, true);
434
435 if (new_rank > old_rank)
437
438 if (new_rank != old_rank)
439 {
440 sScriptMgr->OnPlayerReputationRankChange(_player, factionEntry->ID, new_rank, old_rank, _sendFactionIncreased);
441 }
442
443 UpdateRankCounters(old_rank, new_rank);
444
445 _player->ReputationChanged(factionEntry);
451
452 return true;
453 }
454 }
455 return false;
456}
#define sScriptMgr
Definition: ScriptMgr.h:2690
@ RATE_REPUTATION_GAIN
Definition: IWorld.h:467
@ ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION
Definition: DBCEnums.h:167
@ ACHIEVEMENT_CRITERIA_TYPE_GAIN_REVERED_REPUTATION
Definition: DBCEnums.h:201
@ ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION
Definition: DBCEnums.h:166
@ ACHIEVEMENT_CRITERIA_TYPE_KNOWN_FACTIONS
Definition: DBCEnums.h:203
@ ACHIEVEMENT_CRITERIA_TYPE_GAIN_HONORED_REPUTATION
Definition: DBCEnums.h:202
#define sWorld
Definition: World.h:458
void ReputationChanged(FactionEntry const *factionEntry)
Definition: PlayerQuest.cpp:2185
void UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscValue1=0, uint32 miscValue2=0, Unit *unit=nullptr)
Definition: PlayerUpdates.cpp:2128
static int32 ReputationRankToStanding(ReputationRank rank)
Definition: ReputationMgr.cpp:44

References _factions, _player, _sendFactionIncreased, ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION, ACHIEVEMENT_CRITERIA_TYPE_GAIN_HONORED_REPUTATION, ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION, ACHIEVEMENT_CRITERIA_TYPE_GAIN_REVERED_REPUTATION, ACHIEVEMENT_CRITERIA_TYPE_KNOWN_FACTIONS, GetBaseReputation(), FactionEntry::ID, RATE_REPUTATION_GAIN, REP_HOSTILE, Reputation_Bottom, Reputation_Cap, Player::ReputationChanged(), FactionEntry::reputationListID, ReputationRankToStanding(), ReputationToRank(), SetAtWar(), SetVisible(), sScriptMgr, sWorld, Player::UpdateAchievementCriteria(), and UpdateRankCounters().

Referenced by modify_commandscript::HandleModifyRepCommand(), WorldSession::HandlePlayerLoginFromDB(), and SetReputation().

◆ SetReputation() [1/2]

bool ReputationMgr::SetReputation ( FactionEntry const *  factionEntry,
float  standing 
)
inline
115 {
116 return SetReputation(factionEntry, standing, false);
117 }

References SetReputation().

Referenced by spell_gen_oracle_wolvar_reputation::HandleDummy(), SetReputation(), and Player::SetReputation().

◆ SetReputation() [2/2]

bool ReputationMgr::SetReputation ( FactionEntry const *  factionEntry,
float  standing,
bool  incremental,
bool  noSpillOver = false,
Optional< ReputationRank repMaxCap = { } 
)
private
298{
299 bool res = false;
300
301 if (!noSpillOver)
302 {
303 // if spillover definition exists in DB, override DBC
304 if (const RepSpilloverTemplate* repTemplate = sObjectMgr->GetRepSpilloverTemplate(factionEntry->ID))
305 {
306 for (uint32 i = 0; i < MAX_SPILLOVER_FACTIONS; ++i)
307 {
308 if (repTemplate->faction[i])
309 {
310 if (_player->GetReputationRank(repTemplate->faction[i]) <= ReputationRank(repTemplate->faction_rank[i]))
311 {
312 // bonuses are already given, so just modify standing by rate
313 float spilloverRep = standing * repTemplate->faction_rate[i];
314 SetOneFactionReputation(sFactionStore.LookupEntry(repTemplate->faction[i]), spilloverRep, incremental);
315 }
316 }
317 }
318 }
319 else
320 {
321 float spillOverRepOut = float(standing);
322 // check for sub-factions that receive spillover
323 SimpleFactionsList const* flist = GetFactionTeamList(factionEntry->ID);
324 // if has no sub-factions, check for factions with same parent
325 if (!flist && factionEntry->team && factionEntry->spilloverRateOut != 0.0f)
326 {
327 spillOverRepOut *= factionEntry->spilloverRateOut;
328 if (FactionEntry const* parent = sFactionStore.LookupEntry(factionEntry->team))
329 {
330 FactionStateList::iterator parentState = _factions.find(parent->reputationListID);
331 // some team factions have own reputation standing, in this case do not spill to other sub-factions
332 if (parentState != _factions.end() && (parentState->second.Flags & FACTION_FLAG_SPECIAL))
333 {
334 SetOneFactionReputation(parent, spillOverRepOut, incremental);
335 }
336 else // spill to "sister" factions
337 {
338 flist = GetFactionTeamList(factionEntry->team);
339 }
340 }
341 }
342 if (flist)
343 {
344 // Spillover to affiliated factions
345 for (SimpleFactionsList::const_iterator itr = flist->begin(); itr != flist->end(); ++itr)
346 {
347 if (FactionEntry const* factionEntryCalc = sFactionStore.LookupEntry(*itr))
348 {
349 if (factionEntryCalc == factionEntry || GetRank(factionEntryCalc) > ReputationRank(factionEntryCalc->spilloverMaxRankIn))
350 continue;
351 float spilloverRep = spillOverRepOut * factionEntryCalc->spilloverRateIn;
352 if (spilloverRep != 0 || !incremental)
353 res = SetOneFactionReputation(factionEntryCalc, spilloverRep, incremental);
354 }
355 }
356 }
357 }
358 }
359
360 bool spillOverOnly = repMaxCap ? GetRank(factionEntry) > *repMaxCap : false;
361
362 // spillover done, update faction itself
363 FactionStateList::iterator faction = _factions.find(factionEntry->reputationListID);
364 if (faction != _factions.end())
365 {
366 // Xinef: if we update spillover only, do not update main reputation (rank exceeds creature reward rate)
367 if (!spillOverOnly)
368 {
369 res = SetOneFactionReputation(factionEntry, standing, incremental, repMaxCap);
370 }
371
372 // only this faction gets reported to client, even if it has no own visible standing
373 SendState(&faction->second);
374 }
375 return res;
376}
SimpleFactionsList const * GetFactionTeamList(uint32 faction)
Definition: DBCStores.cpp:644
std::list< uint32 > SimpleFactionsList
Definition: DBCStores.h:28
#define sObjectMgr
Definition: ObjectMgr.h:1606
@ FACTION_FLAG_SPECIAL
Definition: DBCEnums.h:319
#define MAX_SPILLOVER_FACTIONS
Definition: SharedDefines.h:219
ReputationRank GetReputationRank(uint32 faction_id) const
Definition: Player.cpp:5747
Definition: ObjectMgr.h:575
bool SetOneFactionReputation(FactionEntry const *factionEntry, float standing, bool incremental, Optional< ReputationRank > repMaxCap={ })
Public for chat command needs.
Definition: ReputationMgr.cpp:378

References _factions, _player, FACTION_FLAG_SPECIAL, GetFactionTeamList(), GetRank(), Player::GetReputationRank(), FactionEntry::ID, MAX_SPILLOVER_FACTIONS, FactionEntry::reputationListID, SendState(), SetOneFactionReputation(), sFactionStore, sObjectMgr, FactionEntry::spilloverRateOut, and FactionEntry::team.

◆ SetVisible() [1/3]

void ReputationMgr::SetVisible ( FactionEntry const *  factionEntry)
470{
471 if (factionEntry->reputationListID < 0)
472 return;
473
474 FactionStateList::iterator itr = _factions.find(factionEntry->reputationListID);
475 if (itr == _factions.end())
476 return;
477
478 SetVisible(&itr->second);
479}

References _factions, FactionEntry::reputationListID, and SetVisible().

◆ SetVisible() [2/3]

void ReputationMgr::SetVisible ( FactionState faction)
private
482{
483 // always invisible or hidden faction can't be make visible
484 // except if faction has FACTION_FLAG_SPECIAL
486 return;
487
488 // already set
489 if (faction->Flags & FACTION_FLAG_VISIBLE)
490 return;
491
492 faction->Flags |= FACTION_FLAG_VISIBLE;
493 faction->needSend = true;
494 faction->needSave = true;
495
497
498 SendVisible(faction);
499}
void SendVisible(FactionState const *faction) const
Definition: ReputationMgr.cpp:252

References _visibleFactionCount, FACTION_FLAG_HIDDEN, FACTION_FLAG_INVISIBLE_FORCED, FACTION_FLAG_SPECIAL, FACTION_FLAG_VISIBLE, FactionState::Flags, FactionState::needSave, FactionState::needSend, and SendVisible().

◆ SetVisible() [3/3]

void ReputationMgr::SetVisible ( FactionTemplateEntry const *  factionTemplateEntry)
459{
460 if (!factionTemplateEntry->faction)
461 return;
462
463 if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionTemplateEntry->faction))
464 // Never show factions of the opposing team
465 if (!(factionEntry->BaseRepRaceMask[1] & _player->getRaceMask() && factionEntry->BaseRepValue[1] == Reputation_Bottom))
466 SetVisible(factionEntry);
467}

References _player, FactionTemplateEntry::faction, Unit::getRaceMask(), Reputation_Bottom, SetVisible(), and sFactionStore.

Referenced by Player::AddQuest(), WorldSession::HandleGossipHelloOpcode(), LoadFromDB(), SetOneFactionReputation(), and SetVisible().

◆ UpdateRankCounters()

void ReputationMgr::UpdateRankCounters ( ReputationRank  old_rank,
ReputationRank  new_rank 
)
private
649{
650 if (old_rank >= REP_EXALTED)
652 if (old_rank >= REP_REVERED)
654 if (old_rank >= REP_HONORED)
656
657 if (new_rank >= REP_EXALTED)
659 if (new_rank >= REP_REVERED)
661 if (new_rank >= REP_HONORED)
663}
@ REP_EXALTED
Definition: SharedDefines.h:159
@ REP_HONORED
Definition: SharedDefines.h:157
@ REP_REVERED
Definition: SharedDefines.h:158

References _exaltedFactionCount, _honoredFactionCount, _reveredFactionCount, REP_EXALTED, REP_HONORED, and REP_REVERED.

Referenced by Initialize(), LoadFromDB(), and SetOneFactionReputation().

Member Data Documentation

◆ _exaltedFactionCount

uint8 ReputationMgr::_exaltedFactionCount
private

◆ _factions

◆ _forcedReactions

ForcedReactions ReputationMgr::_forcedReactions
private

◆ _honoredFactionCount

uint8 ReputationMgr::_honoredFactionCount
private

◆ _player

◆ _reveredFactionCount

uint8 ReputationMgr::_reveredFactionCount
private

◆ _sendFactionIncreased

bool ReputationMgr::_sendFactionIncreased
private

◆ _visibleFactionCount

uint8 ReputationMgr::_visibleFactionCount
private

◆ PointsInRank

const int32 ReputationMgr::PointsInRank = {36000, 3000, 3000, 3000, 6000, 12000, 21000, 1000}
static

◆ Reputation_Bottom

const int32 ReputationMgr::Reputation_Bottom = -42000
static

◆ Reputation_Cap

const int32 ReputationMgr::Reputation_Cap = 42999
static