TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ReputationMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __TRINITY_REPUTATION_MGR_H
20 #define __TRINITY_REPUTATION_MGR_H
21 
22 #include "Common.h"
23 #include "SharedDefines.h"
24 #include "Language.h"
25 #include "DBCStructure.h"
26 #include "QueryResult.h"
27 #include <map>
28 
30 {
33 };
34 
36 {
37  FACTION_FLAG_NONE = 0x00, // no faction flag
38  FACTION_FLAG_VISIBLE = 0x01, // makes visible in client (set or can be set at interaction with target of this faction)
39  FACTION_FLAG_AT_WAR = 0x02, // enable AtWar-button in client. player controlled (except opposition team always war state), Flag only set on initial creation
40  FACTION_FLAG_HIDDEN = 0x04, // hidden faction from reputation pane in client (player can gain reputation, but this update not sent to client)
41  FACTION_FLAG_INVISIBLE_FORCED = 0x08, // always overwrite FACTION_FLAG_VISIBLE and hide faction in rep.list, used for hide opposite team factions
42  FACTION_FLAG_PEACE_FORCED = 0x10, // always overwrite FACTION_FLAG_AT_WAR, used for prevent war with own team factions
43  FACTION_FLAG_INACTIVE = 0x20, // player controlled, state stored in characters.data (CMSG_SET_FACTION_INACTIVE)
44  FACTION_FLAG_RIVAL = 0x40, // flag for the two competing outland factions
45  FACTION_FLAG_SPECIAL = 0x80 // horde and alliance home cities and their northrend allies have this flag
46 };
47 
48 typedef uint32 RepListID;
50 {
55  bool needSend;
56  bool needSave;
57 };
58 
59 typedef std::map<RepListID, FactionState> FactionStateList;
60 typedef std::map<uint32, ReputationRank> ForcedReactions;
61 
62 class Player;
63 
65 {
66  public: // constructors and global modifiers
67  explicit ReputationMgr(Player* owner) : _player(owner),
68  _visibleFactionCount(0), _honoredFactionCount(0), _reveredFactionCount(0), _exaltedFactionCount(0), _sendFactionIncreased(false) { }
70 
71  void SaveToDB(SQLTransaction& trans);
72  void LoadFromDB(PreparedQueryResult result);
73  public: // statics
74  static const int32 PointsInRank[MAX_REPUTATION_RANK];
75  static const int32 Reputation_Cap;
76  static const int32 Reputation_Bottom;
77 
78  static ReputationRank ReputationToRank(int32 standing);
79  public: // accessors
80  uint8 GetVisibleFactionCount() const { return _visibleFactionCount; }
81  uint8 GetHonoredFactionCount() const { return _honoredFactionCount; }
82  uint8 GetReveredFactionCount() const { return _reveredFactionCount; }
83  uint8 GetExaltedFactionCount() const { return _exaltedFactionCount; }
84 
85  FactionStateList const& GetStateList() const { return _factions; }
86 
87  FactionState const* GetState(FactionEntry const* factionEntry) const
88  {
89  return factionEntry->CanHaveReputation() ? GetState(factionEntry->ReputationIndex) : NULL;
90  }
91 
92  FactionState const* GetState(RepListID id) const
93  {
94  FactionStateList::const_iterator repItr = _factions.find (id);
95  return repItr != _factions.end() ? &repItr->second : NULL;
96  }
97 
98  bool IsAtWar(uint32 faction_id) const;
99  bool IsAtWar(FactionEntry const* factionEntry) const;
100 
101  int32 GetReputation(uint32 faction_id) const;
102  int32 GetReputation(FactionEntry const* factionEntry) const;
103  int32 GetBaseReputation(FactionEntry const* factionEntry) const;
104 
105  ReputationRank GetRank(FactionEntry const* factionEntry) const;
106  ReputationRank GetBaseRank(FactionEntry const* factionEntry) const;
107  uint32 GetReputationRankStrIndex(FactionEntry const* factionEntry) const
108  {
109  return ReputationRankStrIndex[GetRank(factionEntry)];
110  };
111 
112  ReputationRank const* GetForcedRankIfAny(FactionTemplateEntry const* factionTemplateEntry) const
113  {
114  return GetForcedRankIfAny(factionTemplateEntry->Faction);
115  }
116 
117  ReputationRank const* GetForcedRankIfAny(uint32 factionId) const
118  {
119  ForcedReactions::const_iterator forceItr = _forcedReactions.find(factionId);
120  return forceItr != _forcedReactions.end() ? &forceItr->second : NULL;
121  }
122 
123  public: // modifiers
124  bool SetReputation(FactionEntry const* factionEntry, int32 standing)
125  {
126  return SetReputation(factionEntry, standing, false);
127  }
128  bool ModifyReputation(FactionEntry const* factionEntry, int32 standing)
129  {
130  return SetReputation(factionEntry, standing, true);
131  }
132 
133  void SetVisible(FactionTemplateEntry const* factionTemplateEntry);
134  void SetVisible(FactionEntry const* factionEntry);
135  void SetAtWar(RepListID repListID, bool on);
136  void SetInactive(RepListID repListID, bool on);
137 
138  void ApplyForceReaction(uint32 faction_id, ReputationRank rank, bool apply);
139 
141  bool SetOneFactionReputation(FactionEntry const* factionEntry, int32 standing, bool incremental);
142 
143  public: // senders
144  void SendInitialReputations();
145  void SendForceReactions();
146  void SendState(FactionState const* faction);
147  void SendStates();
148 
149  private: // internal helper functions
150  void Initialize();
151  uint32 GetDefaultStateFlags(FactionEntry const* factionEntry) const;
152  bool SetReputation(FactionEntry const* factionEntry, int32 standing, bool incremental);
153  void SetVisible(FactionState* faction);
154  void SetAtWar(FactionState* faction, bool atWar) const;
155  void SetInactive(FactionState* faction, bool inactive) const;
156  void SendVisible(FactionState const* faction, bool visible = true) const;
157  void UpdateRankCounters(ReputationRank old_rank, ReputationRank new_rank);
158  private:
162  uint8 _visibleFactionCount :8;
163  uint8 _honoredFactionCount :8;
164  uint8 _reveredFactionCount :8;
165  uint8 _exaltedFactionCount :8;
167 };
168 
169 #endif
Definition: ReputationMgr.h:41
uint32 GetReputationRankStrIndex(FactionEntry const *factionEntry) const
Definition: ReputationMgr.h:107
FactionState const * GetState(RepListID id) const
Definition: ReputationMgr.h:92
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
ReputationRank
Definition: SharedDefines.h:211
Definition: ReputationMgr.h:43
uint32 ID
Definition: ReputationMgr.h:51
Definition: ReputationMgr.h:64
Definition: ReputationMgr.h:39
FactionStateList _factions
Definition: ReputationMgr.h:160
void LoadFromDB()
Definition: AddonMgr.cpp:40
Definition: Language.h:352
Definition: ReputationMgr.h:37
static const int32 Reputation_Cap
Definition: ReputationMgr.h:75
Definition: Language.h:346
int32 Standing
Definition: ReputationMgr.h:53
arena_t NULL
Definition: jemalloc_internal.h:624
Definition: Language.h:348
#define false
Definition: CascPort.h:18
uint32 RepListID
Definition: ReputationMgr.h:48
uint8 GetReveredFactionCount() const
Definition: ReputationMgr.h:82
void apply(T *val)
Definition: ByteConverter.h:41
FactionState const * GetState(FactionEntry const *factionEntry) const
Definition: ReputationMgr.h:87
Definition: ReputationMgr.h:42
Definition: Language.h:351
#define MAX_REPUTATION_RANK
Definition: SharedDefines.h:224
ForcedReactions _forcedReactions
Definition: ReputationMgr.h:161
bool _sendFactionIncreased
Definition: ReputationMgr.h:166
Definition: Language.h:347
Definition: ReputationMgr.h:40
std::map< uint32, ReputationRank > ForcedReactions
Definition: ReputationMgr.h:60
int32_t int32
Definition: Define.h:146
ReputationRank const * GetForcedRankIfAny(FactionTemplateEntry const *factionTemplateEntry) const
Definition: ReputationMgr.h:112
uint32_t uint32
Definition: Define.h:150
static void Initialize(PCASC_SALSA20 pState, LPBYTE pbKey, DWORD cbKeyLength, LPBYTE pbVector)
Definition: CascDecrypt.cpp:81
Definition: ReputationMgr.h:45
static uint32 ReputationRankStrIndex[MAX_REPUTATION_RANK]
Definition: ReputationMgr.h:29
bool needSend
Definition: ReputationMgr.h:55
FactionStateList const & GetStateList() const
Definition: ReputationMgr.h:85
Definition: DBCStructure.h:433
Definition: DBCStructure.h:405
static const int32 Reputation_Bottom
Definition: ReputationMgr.h:76
Definition: ReputationMgr.h:44
#define TC_GAME_API
Definition: Define.h:134
uint8 Flags
Definition: ReputationMgr.h:54
ReputationRank const * GetForcedRankIfAny(uint32 factionId) const
Definition: ReputationMgr.h:117
Definition: Language.h:350
uint8_t uint8
Definition: Define.h:152
Definition: ReputationMgr.h:38
bool needSave
Definition: ReputationMgr.h:56
std::map< RepListID, FactionState > FactionStateList
Definition: ReputationMgr.h:59
ReputationMgr(Player *owner)
Definition: ReputationMgr.h:67
Definition: Language.h:349
bool ModifyReputation(FactionEntry const *factionEntry, int32 standing)
Definition: ReputationMgr.h:128
int32 ReputationIndex
Definition: DBCStructure.h:408
uint8 GetHonoredFactionCount() const
Definition: ReputationMgr.h:81
uint8 GetExaltedFactionCount() const
Definition: ReputationMgr.h:83
Player * _player
Definition: ReputationMgr.h:159
FactionFlags
Definition: ReputationMgr.h:35
bool CanHaveReputation() const
Definition: DBCStructure.h:425
uint8 GetVisibleFactionCount() const
Definition: ReputationMgr.h:80
bool SetReputation(FactionEntry const *factionEntry, int32 standing)
Definition: ReputationMgr.h:124
Definition: Language.h:353
~ReputationMgr()
Definition: ReputationMgr.h:69
Definition: ReputationMgr.h:49
RepListID ReputationListID
Definition: ReputationMgr.h:52
uint32 Faction
Definition: DBCStructure.h:436
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58