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

#include <CollectionMgr.h>

Public Member Functions

 CollectionMgr (WorldSession *owner)
 
WorldSessionGetOwner () const
 
void LoadToys ()
 
void LoadAccountToys (PreparedQueryResult result)
 
void SaveAccountToys (SQLTransaction &trans)
 
void ToySetFavorite (uint32 itemId, bool favorite)
 
bool AddToy (uint32 itemId, bool isFavourite)
 
bool UpdateAccountToys (uint32 itemId, bool isFavourite)
 
ToyBoxContainer constGetAccountToys () const
 
void LoadHeirlooms ()
 
void LoadAccountHeirlooms (PreparedQueryResult result)
 
void SaveAccountHeirlooms (SQLTransaction &trans)
 
void AddHeirloom (uint32 itemId, uint32 flags)
 
void UpgradeHeirloom (uint32 itemId, uint32 castItem)
 
void CheckHeirloomUpgrades (Item *item)
 
bool UpdateAccountHeirlooms (uint32 itemId, uint32 flags)
 
bool CanApplyHeirloomXpBonus (uint32 itemId, uint32 level)
 
uint32 GetHeirloomBonus (uint32 itemId) const
 
HeirloomContainer constGetAccountHeirlooms () const
 

Private Attributes

WorldSession_owner
 
ToyBoxContainer _toys
 
HeirloomContainer _heirlooms
 

Constructor & Destructor Documentation

CollectionMgr::CollectionMgr ( WorldSession owner)
inlineexplicit
51 : _owner(owner) { }
WorldSession * _owner
Definition: CollectionMgr.h:82

Member Function Documentation

void CollectionMgr::AddHeirloom ( uint32  itemId,
uint32  flags 
)
143 {
144  if (UpdateAccountHeirlooms(itemId, flags))
145  {
146  _owner->GetPlayer()->AddDynamicValue(PLAYER_DYNAMIC_FIELD_HEIRLOOMS, itemId);
148  }
149 }
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * _owner
Definition: CollectionMgr.h:82
Definition: UpdateFields.h:310
Definition: UpdateFields.h:309
bool UpdateAccountHeirlooms(uint32 itemId, uint32 flags)
Definition: CollectionMgr.cpp:119
uint8 flags
Definition: DisableMgr.cpp:44

+ Here is the call graph for this function:

bool CollectionMgr::AddToy ( uint32  itemId,
bool  isFavourite 
)
28 {
29  if (UpdateAccountToys(itemId, isFavourite))
30  {
31  _owner->GetPlayer()->AddDynamicValue(PLAYER_DYNAMIC_FIELD_TOYS, itemId);
32  return true;
33  }
34 
35  return false;
36 }
bool UpdateAccountToys(uint32 itemId, bool isFavourite)
Definition: CollectionMgr.cpp:66
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * _owner
Definition: CollectionMgr.h:82
Definition: UpdateFields.h:311

+ Here is the call graph for this function:

bool CollectionMgr::CanApplyHeirloomXpBonus ( uint32  itemId,
uint32  level 
)
247 {
248  if (!sDB2Manager.GetHeirloomByItemId(itemId))
249  return false;
250 
251  HeirloomContainer::iterator itr = _heirlooms.find(itemId);
252  if (itr == _heirlooms.end())
253  return false;
254 
255  if (itr->second.flags & HEIRLOOM_FLAG_BONUS_LEVEL_100)
256  return level <= 100;
257  if (itr->second.flags & HEIRLOOM_FLAG_BONUS_LEVEL_90)
258  return level <= 90;
259 
260  return level <= 60;
261 }
Definition: CollectionMgr.h:27
#define sDB2Manager
Definition: DB2Stores.h:224
HeirloomContainer _heirlooms
Definition: CollectionMgr.h:85
Definition: CollectionMgr.h:26
void CollectionMgr::CheckHeirloomUpgrades ( Item item)
192 {
193  Player* player = _owner->GetPlayer();
194  if (!player)
195  return;
196 
197  // Check already owned heirloom for upgrade kits
198  if (HeirloomEntry const* heirloom = sDB2Manager.GetHeirloomByItemId(item->GetEntry()))
199  {
200  HeirloomContainer::iterator itr = _heirlooms.find(item->GetEntry());
201  if (itr == _heirlooms.end())
202  return;
203 
204  // Check for heirloom pairs (normal - heroic, heroic - mythic)
205  uint32 heirloomItemId = heirloom->NextDifficultyItemID;
206  uint32 newItemId = 0;
207  while (HeirloomEntry const* heirloomDiff = sDB2Manager.GetHeirloomByItemId(heirloomItemId))
208  {
209  if (player->GetItemByEntry(heirloomDiff->ItemID))
210  newItemId = heirloomDiff->ItemID;
211 
212  if (HeirloomEntry const* heirloomSub = sDB2Manager.GetHeirloomByItemId(heirloomDiff->NextDifficultyItemID))
213  {
214  heirloomItemId = heirloomSub->ItemID;
215  continue;
216  }
217 
218  break;
219  }
220 
221  if (newItemId)
222  {
223  std::vector<uint32> const& fields = player->GetDynamicValues(PLAYER_DYNAMIC_FIELD_HEIRLOOMS);
224  uint8 offset = std::find(fields.begin(), fields.end(), itr->first) - fields.begin();
225 
226  player->SetDynamicValue(PLAYER_DYNAMIC_FIELD_HEIRLOOMS, offset, newItemId);
227  player->SetDynamicValue(PLAYER_DYNAMIC_FIELD_HEIRLOOM_FLAGS, offset, 0);
228 
229  _heirlooms.erase(itr);
230  _heirlooms[newItemId] = 0;
231 
232  return;
233  }
234 
235  std::vector<uint32> const& fields = item->GetDynamicValues(ITEM_DYNAMIC_FIELD_BONUSLIST_IDS);
236 
237  for (uint32 bonusId : fields)
238  if (bonusId != itr->second.bonusId)
240 
241  if (std::find(fields.begin(), fields.end(), itr->second.bonusId) == fields.end())
242  item->AddBonuses(itr->second.bonusId);
243  }
244 }
#define sDB2Manager
Definition: DB2Stores.h:224
void ClearDynamicValue(uint16 index)
Definition: Object.cpp:1370
Definition: DB2Structure.h:586
Player * GetPlayer() const
Definition: WorldSession.h:927
std::vector< uint32 > const & GetDynamicValues(uint16 index) const
Definition: Object.cpp:1338
void AddBonuses(uint32 bonusListID)
Definition: Item.cpp:1931
WorldSession * _owner
Definition: CollectionMgr.h:82
Definition: UpdateFields.h:310
Definition: UpdateFields.h:64
Definition: UpdateFields.h:309
uint32_t uint32
Definition: Define.h:150
HeirloomContainer _heirlooms
Definition: CollectionMgr.h:85
uint8_t uint8
Definition: Define.h:152
uint32 GetEntry() const
Definition: Object.h:107

+ Here is the call graph for this function:

HeirloomContainer const& CollectionMgr::GetAccountHeirlooms ( ) const
inline
77 { return _heirlooms; }
HeirloomContainer _heirlooms
Definition: CollectionMgr.h:85
ToyBoxContainer const& CollectionMgr::GetAccountToys ( ) const
inline
64 { return _toys; }
ToyBoxContainer _toys
Definition: CollectionMgr.h:84
uint32 CollectionMgr::GetHeirloomBonus ( uint32  itemId) const
125 {
126  HeirloomContainer::const_iterator itr = _heirlooms.find(itemId);
127  if (itr != _heirlooms.end())
128  return itr->second.bonusId;
129 
130  return 0;
131 }
HeirloomContainer _heirlooms
Definition: CollectionMgr.h:85

+ Here is the caller graph for this function:

WorldSession* CollectionMgr::GetOwner ( ) const
inline
53 { return _owner; }
WorldSession * _owner
Definition: CollectionMgr.h:82
void CollectionMgr::LoadAccountHeirlooms ( PreparedQueryResult  result)
81 {
82  if (!result)
83  return;
84 
85  do
86  {
87  Field* fields = result->Fetch();
88  uint32 itemId = fields[0].GetUInt32();
89  uint32 flags = fields[1].GetUInt32();
90 
91  HeirloomEntry const* heirloom = sDB2Manager.GetHeirloomByItemId(itemId);
92  if (!heirloom)
93  continue;
94 
95  uint32 bonusId = 0;
96 
97  if (flags & HEIRLOOM_FLAG_BONUS_LEVEL_90)
98  bonusId = heirloom->ItemBonusListID[0];
100  bonusId = heirloom->ItemBonusListID[1];
101 
102  _heirlooms[itemId] = HeirloomData(flags, bonusId);
103  } while (result->NextRow());
104 }
Definition: CollectionMgr.h:27
#define sDB2Manager
Definition: DB2Stores.h:224
Class used to access individual fields of database query result.
Definition: Field.h:56
Definition: DB2Structure.h:586
uint32 ItemBonusListID[2]
Definition: DB2Structure.h:596
uint32_t uint32
Definition: Define.h:150
HeirloomContainer _heirlooms
Definition: CollectionMgr.h:85
uint32 GetUInt32() const
Definition: Field.h:146
Definition: CollectionMgr.h:26
uint8 flags
Definition: DisableMgr.cpp:44
Definition: CollectionMgr.h:37

+ Here is the call graph for this function:

void CollectionMgr::LoadAccountToys ( PreparedQueryResult  result)
39 {
40  if (!result)
41  return;
42 
43  do
44  {
45  Field* fields = result->Fetch();
46  uint32 itemId = fields[0].GetUInt32();
47  bool isFavourite = fields[1].GetBool();
48 
49  _toys[itemId] = isFavourite;
50  } while (result->NextRow());
51 }
ToyBoxContainer _toys
Definition: CollectionMgr.h:84
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32_t uint32
Definition: Define.h:150
uint32 GetUInt32() const
Definition: Field.h:146
bool GetBool() const
Definition: Field.h:65

+ Here is the call graph for this function:

void CollectionMgr::LoadHeirlooms ( )
134 {
135  for (auto const& item : _heirlooms)
136  {
137  _owner->GetPlayer()->AddDynamicValue(PLAYER_DYNAMIC_FIELD_HEIRLOOMS, item.first);
138  _owner->GetPlayer()->AddDynamicValue(PLAYER_DYNAMIC_FIELD_HEIRLOOM_FLAGS, item.second.flags);
139  }
140 }
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * _owner
Definition: CollectionMgr.h:82
Definition: UpdateFields.h:310
Definition: UpdateFields.h:309
HeirloomContainer _heirlooms
Definition: CollectionMgr.h:85

+ Here is the call graph for this function:

void CollectionMgr::LoadToys ( )
22 {
23  for (auto const& t : _toys)
24  _owner->GetPlayer()->AddDynamicValue(PLAYER_DYNAMIC_FIELD_TOYS, t.first);
25 }
ToyBoxContainer _toys
Definition: CollectionMgr.h:84
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * _owner
Definition: CollectionMgr.h:82
Definition: UpdateFields.h:311

+ Here is the call graph for this function:

void CollectionMgr::SaveAccountHeirlooms ( SQLTransaction trans)
107 {
108  PreparedStatement* stmt = nullptr;
109  for (auto const& heirloom : _heirlooms)
110  {
113  stmt->setUInt32(1, heirloom.first);
114  stmt->setUInt32(2, heirloom.second.flags);
115  trans->Append(stmt);
116  }
117 }
uint32 GetBattlenetAccountId() const
Definition: WorldSession.h:925
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
WorldSession * _owner
Definition: CollectionMgr.h:82
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
Definition: LoginDatabase.h:147
HeirloomContainer _heirlooms
Definition: CollectionMgr.h:85

+ Here is the call graph for this function:

void CollectionMgr::SaveAccountToys ( SQLTransaction trans)
54 {
55  PreparedStatement* stmt = nullptr;
56  for (auto const& toy : _toys)
57  {
60  stmt->setUInt32(1, toy.first);
61  stmt->setBool(2, toy.second);
62  trans->Append(stmt);
63  }
64 }
ToyBoxContainer _toys
Definition: CollectionMgr.h:84
uint32 GetBattlenetAccountId() const
Definition: WorldSession.h:925
Definition: LoginDatabase.h:136
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
void setBool(const uint8 index, const bool value)
Definition: PreparedStatement.cpp:88
WorldSession * _owner
Definition: CollectionMgr.h:82
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115

+ Here is the call graph for this function:

void CollectionMgr::ToySetFavorite ( uint32  itemId,
bool  favorite 
)
72 {
73  ToyBoxContainer::iterator itr = _toys.find(itemId);
74  if (itr == _toys.end())
75  return;
76 
77  itr->second = favorite;
78 }
ToyBoxContainer _toys
Definition: CollectionMgr.h:84
bool CollectionMgr::UpdateAccountHeirlooms ( uint32  itemId,
uint32  flags 
)
120 {
121  return _heirlooms.insert(HeirloomContainer::value_type(itemId, HeirloomData(flags, 0))).second;
122 }
HeirloomContainer _heirlooms
Definition: CollectionMgr.h:85
uint8 flags
Definition: DisableMgr.cpp:44
Definition: CollectionMgr.h:37

+ Here is the caller graph for this function:

bool CollectionMgr::UpdateAccountToys ( uint32  itemId,
bool  isFavourite 
)
67 {
68  return _toys.insert(ToyBoxContainer::value_type(itemId, isFavourite)).second;
69 }
ToyBoxContainer _toys
Definition: CollectionMgr.h:84

+ Here is the caller graph for this function:

void CollectionMgr::UpgradeHeirloom ( uint32  itemId,
uint32  castItem 
)
152 {
153  Player* player = _owner->GetPlayer();
154  if (!player)
155  return;
156 
157  HeirloomEntry const* heirloom = sDB2Manager.GetHeirloomByItemId(itemId);
158  if (!heirloom)
159  return;
160 
161  HeirloomContainer::iterator itr = _heirlooms.find(itemId);
162  if (itr == _heirlooms.end())
163  return;
164 
165  uint32 flags = itr->second.flags;
166  uint32 bonusId = 0;
167 
168  if (heirloom->UpgradeItemID[0] == castItem)
169  {
171  bonusId = heirloom->ItemBonusListID[0];
172  }
173  if (heirloom->UpgradeItemID[1] == castItem)
174  {
176  bonusId = heirloom->ItemBonusListID[1];
177  }
178 
179  for (Item* item : player->GetItemListByEntry(itemId, true))
180  item->AddBonuses(bonusId);
181 
182  // Get heirloom offset to update only one part of dynamic field
183  std::vector<uint32> const& fields = player->GetDynamicValues(PLAYER_DYNAMIC_FIELD_HEIRLOOMS);
184  uint8 offset = std::find(fields.begin(), fields.end(), itemId) - fields.begin();
185 
186  player->SetDynamicValue(PLAYER_DYNAMIC_FIELD_HEIRLOOM_FLAGS, offset, flags);
187  itr->second.flags = flags;
188  itr->second.bonusId = bonusId;
189 }
Definition: CollectionMgr.h:27
#define sDB2Manager
Definition: DB2Stores.h:224
Definition: DB2Structure.h:586
Player * GetPlayer() const
Definition: WorldSession.h:927
uint32 ItemBonusListID[2]
Definition: DB2Structure.h:596
WorldSession * _owner
Definition: CollectionMgr.h:82
Definition: UpdateFields.h:310
Definition: Item.h:259
Definition: UpdateFields.h:309
uint32_t uint32
Definition: Define.h:150
HeirloomContainer _heirlooms
Definition: CollectionMgr.h:85
uint32 UpgradeItemID[2]
Definition: DB2Structure.h:595
Definition: CollectionMgr.h:26
uint8_t uint8
Definition: Define.h:152
uint8 flags
Definition: DisableMgr.cpp:44

+ Here is the call graph for this function:

Member Data Documentation

HeirloomContainer CollectionMgr::_heirlooms
private
WorldSession* CollectionMgr::_owner
private
ToyBoxContainer CollectionMgr::_toys
private

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