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

#include <LootMgr.h>

Public Member Functions

 LootStore (char const *name, char const *entryName, bool ratesAllowed)
 
virtual ~LootStore ()
 
void Verify () const
 
uint32 LoadAndCollectLootIds (LootIdSet &ids_set)
 
void CheckLootRefs (LootIdSet *ref_set=NULL) const
 
void ReportUnusedIds (LootIdSet const &ids_set) const
 
void ReportNonExistingId (uint32 lootId) const
 
void ReportNonExistingId (uint32 lootId, const char *ownerType, uint32 ownerId) const
 
bool HaveLootFor (uint32 loot_id) const
 
bool HaveQuestLootFor (uint32 loot_id) const
 
bool HaveQuestLootForPlayer (uint32 loot_id, Player *player) const
 
LootTemplate constGetLootFor (uint32 loot_id) const
 
void ResetConditions ()
 
LootTemplateGetLootForConditionFill (uint32 loot_id)
 
char constGetName () const
 
char constGetEntryName () const
 
bool IsRatesAllowed () const
 

Protected Member Functions

uint32 LoadLootTable ()
 
void Clear ()
 

Private Attributes

LootTemplateMap m_LootTemplates
 
char constm_name
 
char constm_entryName
 
bool m_ratesAllowed
 

Constructor & Destructor Documentation

LootStore::LootStore ( char const name,
char const entryName,
bool  ratesAllowed 
)
inlineexplicit
217  : m_name(name), m_entryName(entryName), m_ratesAllowed(ratesAllowed) { }
char const * m_entryName
Definition: LootMgr.h:246
bool m_ratesAllowed
Definition: LootMgr.h:247
char const * m_name
Definition: LootMgr.h:245
virtual LootStore::~LootStore ( )
inlinevirtual
219 { Clear(); }
void Clear()
Definition: LootMgr.cpp:112

Member Function Documentation

void LootStore::CheckLootRefs ( LootIdSet ref_set = NULL) const
258 {
259  for (LootTemplateMap::const_iterator ltItr = m_LootTemplates.begin(); ltItr != m_LootTemplates.end(); ++ltItr)
260  ltItr->second->CheckLootRefs(m_LootTemplates, ref_set);
261 }
LootTemplateMap m_LootTemplates
Definition: LootMgr.h:244

+ Here is the caller graph for this function:

void LootStore::Clear ( )
protected
113 {
114  for (LootTemplateMap::const_iterator itr=m_LootTemplates.begin(); itr != m_LootTemplates.end(); ++itr)
115  delete itr->second;
116  m_LootTemplates.clear();
117 }
LootTemplateMap m_LootTemplates
Definition: LootMgr.h:244

+ Here is the caller graph for this function:

char const* LootStore::GetEntryName ( ) const
inline
238 { return m_entryName; }
char const * m_entryName
Definition: LootMgr.h:246

+ Here is the caller graph for this function:

LootTemplate const * LootStore::GetLootFor ( uint32  loot_id) const
228 {
229  LootTemplateMap::const_iterator tab = m_LootTemplates.find(loot_id);
230 
231  if (tab == m_LootTemplates.end())
232  return NULL;
233 
234  return tab->second;
235 }
arena_t NULL
Definition: jemalloc_internal.h:624
LootTemplateMap m_LootTemplates
Definition: LootMgr.h:244

+ Here is the caller graph for this function:

LootTemplate * LootStore::GetLootForConditionFill ( uint32  loot_id)
238 {
239  LootTemplateMap::iterator tab = m_LootTemplates.find(loot_id);
240 
241  if (tab == m_LootTemplates.end())
242  return NULL;
243 
244  return tab->second;
245 }
arena_t NULL
Definition: jemalloc_internal.h:624
LootTemplateMap m_LootTemplates
Definition: LootMgr.h:244

+ Here is the caller graph for this function:

char const* LootStore::GetName ( ) const
inline
237 { return m_name; }
char const * m_name
Definition: LootMgr.h:245

+ Here is the caller graph for this function:

bool LootStore::HaveLootFor ( uint32  loot_id) const
inline
229 { return m_LootTemplates.find(loot_id) != m_LootTemplates.end(); }
LootTemplateMap m_LootTemplates
Definition: LootMgr.h:244

+ Here is the caller graph for this function:

bool LootStore::HaveQuestLootFor ( uint32  loot_id) const
199 {
200  LootTemplateMap::const_iterator itr = m_LootTemplates.find(loot_id);
201  if (itr == m_LootTemplates.end())
202  return false;
203 
204  // scan loot for quest items
205  return itr->second->HasQuestDrop(m_LootTemplates);
206 }
LootTemplateMap m_LootTemplates
Definition: LootMgr.h:244

+ Here is the caller graph for this function:

bool LootStore::HaveQuestLootForPlayer ( uint32  loot_id,
Player player 
) const
209 {
210  LootTemplateMap::const_iterator tab = m_LootTemplates.find(loot_id);
211  if (tab != m_LootTemplates.end())
212  if (tab->second->HasQuestDropForPlayer(m_LootTemplates, player))
213  return true;
214 
215  return false;
216 }
LootTemplateMap m_LootTemplates
Definition: LootMgr.h:244

+ Here is the caller graph for this function:

bool LootStore::IsRatesAllowed ( ) const
inline
239 { return m_ratesAllowed; }
bool m_ratesAllowed
Definition: LootMgr.h:247

+ Here is the caller graph for this function:

uint32 LootStore::LoadAndCollectLootIds ( LootIdSet ids_set)
248 {
249  uint32 count = LoadLootTable();
250 
251  for (LootTemplateMap::const_iterator tab = m_LootTemplates.begin(); tab != m_LootTemplates.end(); ++tab)
252  lootIdSet.insert(tab->first);
253 
254  return count;
255 }
uint32 LoadLootTable()
Definition: LootMgr.cpp:129
LootTemplateMap m_LootTemplates
Definition: LootMgr.h:244
uint32_t uint32
Definition: Define.h:150

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 LootStore::LoadLootTable ( )
protected
130 {
131  LootTemplateMap::const_iterator tab;
132 
133  // Clearing store (for reloading case)
134  Clear();
135 
136  // 0 1 2 3 4 5 6
137  QueryResult result = WorldDatabase.PQuery("SELECT Entry, Item, Reference, Chance, QuestRequired, LootMode, GroupId, MinCount, MaxCount FROM %s", GetName());
138 
139  if (!result)
140  return 0;
141 
142  uint32 count = 0;
143 
144  do
145  {
146  Field* fields = result->Fetch();
147 
148  uint32 entry = fields[0].GetUInt32();
149  uint32 item = fields[1].GetUInt32();
150  uint32 reference = fields[2].GetUInt32();
151  float chance = fields[3].GetFloat();
152  bool needsquest = fields[4].GetBool();
153  uint16 lootmode = fields[5].GetUInt16();
154  uint8 groupid = fields[6].GetUInt8();
155  uint8 mincount = fields[7].GetUInt8();
156  uint8 maxcount = fields[8].GetUInt8();
157 
158  if (groupid >= 1 << 7) // it stored in 7 bit field
159  {
160  TC_LOG_ERROR("sql.sql", "Table '%s' Entry %d Item %d: GroupId (%u) must be less %u - skipped", GetName(), entry, item, groupid, 1 << 7);
161  return 0;
162  }
163 
164  LootStoreItem* storeitem = new LootStoreItem(item, reference, chance, needsquest, lootmode, groupid, mincount, maxcount);
165 
166  if (!storeitem->IsValid(*this, entry)) // Validity checks
167  {
168  delete storeitem;
169  continue;
170  }
171 
172  // Looking for the template of the entry
173  // often entries are put together
174  if (m_LootTemplates.empty() || tab->first != entry)
175  {
176  // Searching the template (in case template Id changed)
177  tab = m_LootTemplates.find(entry);
178  if (tab == m_LootTemplates.end())
179  {
180  std::pair< LootTemplateMap::iterator, bool > pr = m_LootTemplates.insert(LootTemplateMap::value_type(entry, new LootTemplate()));
181  tab = pr.first;
182  }
183  }
184  // else is empty - template Id and iter are the same
185  // finally iter refers to already existed or just created <entry, LootTemplate>
186 
187  // Adds current row to the template
188  tab->second->AddEntry(storeitem);
189  ++count;
190  }
191  while (result->NextRow());
192 
193  Verify(); // Checks validity of the loot store
194 
195  return count;
196 }
float GetFloat() const
Definition: Field.h:222
QueryResult PQuery(Format &&sql, T *conn, Args &&...args)
Definition: DatabaseWorkerPool.h:165
Definition: LootMgr.h:134
Class used to access individual fields of database query result.
Definition: Field.h:56
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
uint8 GetUInt8() const
Definition: Field.h:70
void Verify() const
Definition: LootMgr.cpp:121
LootTemplateMap m_LootTemplates
Definition: LootMgr.h:244
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
uint16_t uint16
Definition: Define.h:151
uint16 GetUInt16() const
Definition: Field.h:108
char const * GetName() const
Definition: LootMgr.h:237
void Clear()
Definition: LootMgr.cpp:112
bool IsValid(LootStore const &store, uint32 entry) const
Definition: LootMgr.cpp:302
Definition: LootMgr.h:250
uint32 GetUInt32() const
Definition: Field.h:146
uint8_t uint8
Definition: Define.h:152
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
bool GetBool() const
Definition: Field.h:65

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void LootStore::ReportNonExistingId ( uint32  lootId) const
271 {
272  TC_LOG_ERROR("sql.sql", "Table '%s' Entry %d does not exist", GetName(), lootId);
273 }
char const * GetName() const
Definition: LootMgr.h:237
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void LootStore::ReportNonExistingId ( uint32  lootId,
const char *  ownerType,
uint32  ownerId 
) const
276 {
277  TC_LOG_ERROR("sql.sql", "Table '%s' Entry %d does not exist but it is used by %s %d", GetName(), lootId, ownerType, ownerId);
278 }
char const * GetName() const
Definition: LootMgr.h:237
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the call graph for this function:

void LootStore::ReportUnusedIds ( LootIdSet const ids_set) const
264 {
265  // all still listed ids isn't referenced
266  for (LootIdSet::const_iterator itr = lootIdSet.begin(); itr != lootIdSet.end(); ++itr)
267  TC_LOG_ERROR("sql.sql", "Table '%s' Entry %d isn't %s and not referenced from loot, and thus useless.", GetName(), *itr, GetEntryName());
268 }
char const * GetEntryName() const
Definition: LootMgr.h:238
char const * GetName() const
Definition: LootMgr.h:237
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void LootStore::ResetConditions ( )
219 {
220  for (LootTemplateMap::iterator itr = m_LootTemplates.begin(); itr != m_LootTemplates.end(); ++itr)
221  {
222  ConditionContainer empty;
223  itr->second->CopyConditions(empty);
224  }
225 }
LootTemplateMap m_LootTemplates
Definition: LootMgr.h:244
std::vector< Condition * > ConditionContainer
Definition: ConditionMgr.h:239

+ Here is the caller graph for this function:

void LootStore::Verify ( ) const
122 {
123  for (LootTemplateMap::const_iterator i = m_LootTemplates.begin(); i != m_LootTemplates.end(); ++i)
124  i->second->Verify(*this, i->first);
125 }
LootTemplateMap m_LootTemplates
Definition: LootMgr.h:244

+ Here is the caller graph for this function:

Member Data Documentation

char const* LootStore::m_entryName
private
LootTemplateMap LootStore::m_LootTemplates
private
char const* LootStore::m_name
private
bool LootStore::m_ratesAllowed
private

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