AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
LootStore Class Reference

#include "LootMgr.h"

Public Member Functions

 LootStore (char const *name, char const *entryName, bool ratesAllowed)
 
virtual ~LootStore ()
 
uint32 LoadAndCollectLootIds (LootIdSet &ids_set)
 
void ResetConditions ()
 
void Verify () const
 
void CheckLootRefs (LootIdSet *ref_set=nullptr) const
 
void ReportUnusedIds (LootIdSet const &ids_set) const
 
void ReportNonExistingId (uint32 lootId) const
 
void ReportNonExistingId (uint32 lootId, const char *ownerType, uint32 ownerId) const
 
void ReportInvalidCount (uint32 lootId, const char *ownerType, uint32 ownerId, uint32 itemId, uint8 minCount, uint8 maxCount) const
 
bool HaveLootFor (uint32 loot_id) const
 
bool HaveQuestLootFor (uint32 loot_id) const
 
bool HaveQuestLootForPlayer (uint32 loot_id, Player const *player) const
 
LootTemplate const * GetLootFor (uint32 loot_id) const
 
LootTemplateGetLootForConditionFill (uint32 loot_id) const
 
char const * GetName () const
 
char const * GetEntryName () const
 
bool IsRatesAllowed () const
 

Protected Member Functions

uint32 LoadLootTable ()
 
void Clear ()
 

Private Attributes

LootTemplateMap m_LootTemplates
 
char const * m_name
 
char const * m_entryName
 
bool m_ratesAllowed
 

Detailed Description

Constructor & Destructor Documentation

◆ LootStore()

LootStore::LootStore ( char const *  name,
char const *  entryName,
bool  ratesAllowed 
)
inlineexplicit
210 : m_name(name), m_entryName(entryName), m_ratesAllowed(ratesAllowed) {}
char const * m_entryName
Definition: LootMgr.h:240
bool m_ratesAllowed
Definition: LootMgr.h:241
char const * m_name
Definition: LootMgr.h:239

◆ ~LootStore()

virtual LootStore::~LootStore ( )
inlinevirtual
212{ Clear(); }
void Clear()
Definition: LootMgr.cpp:126

References Clear().

Member Function Documentation

◆ CheckLootRefs()

◆ Clear()

void LootStore::Clear ( )
protected
127{
128 for (LootTemplateMap::const_iterator itr = m_LootTemplates.begin(); itr != m_LootTemplates.end(); ++itr)
129 delete itr->second;
130 m_LootTemplates.clear();
131}

References m_LootTemplates.

Referenced by LoadLootTable(), and ~LootStore().

◆ GetEntryName()

char const * LootStore::GetEntryName ( ) const
inline
232{ return m_entryName; }

References m_entryName.

Referenced by ReportUnusedIds().

◆ GetLootFor()

LootTemplate const * LootStore::GetLootFor ( uint32  loot_id) const
248{
249 LootTemplateMap::const_iterator tab = m_LootTemplates.find(loot_id);
250
251 if (tab == m_LootTemplates.end())
252 return nullptr;
253
254 return tab->second;
255}

References m_LootTemplates.

Referenced by LootTemplate::LootGroup::CheckLootRefs(), LootTemplate::CheckLootRefs(), LootTemplate::CopyConditions(), Loot::FillLoot(), LootItemStorage::LoadStoredLoot(), LootTemplate::Process(), and LootTemplate::LootGroup::Process().

◆ GetLootForConditionFill()

LootTemplate * LootStore::GetLootForConditionFill ( uint32  loot_id) const
258{
259 LootTemplateMap::const_iterator tab = m_LootTemplates.find(loot_id);
260
261 if (tab == m_LootTemplates.end())
262 return nullptr;
263
264 return tab->second;
265}

References m_LootTemplates.

Referenced by ConditionMgr::isSourceTypeValid(), and ConditionMgr::LoadConditions().

◆ GetName()

◆ HaveLootFor()

bool LootStore::HaveLootFor ( uint32  loot_id) const
inline

◆ HaveQuestLootFor()

bool LootStore::HaveQuestLootFor ( uint32  loot_id) const
219{
220 LootTemplateMap::const_iterator itr = m_LootTemplates.find(loot_id);
221 if (itr == m_LootTemplates.end())
222 return false;
223
224 // scan loot for quest items
225 return itr->second->HasQuestDrop(m_LootTemplates);
226}

References m_LootTemplates.

Referenced by ObjectMgr::LoadGameObjectForQuests().

◆ HaveQuestLootForPlayer()

bool LootStore::HaveQuestLootForPlayer ( uint32  loot_id,
Player const *  player 
) const
229{
230 LootTemplateMap::const_iterator tab = m_LootTemplates.find(loot_id);
231 if (tab != m_LootTemplates.end())
232 if (tab->second->HasQuestDropForPlayer(m_LootTemplates, player))
233 return true;
234
235 return false;
236}

References m_LootTemplates.

Referenced by GameObject::ActivateToQuest().

◆ IsRatesAllowed()

bool LootStore::IsRatesAllowed ( ) const
inline

◆ LoadAndCollectLootIds()

uint32 LootStore::LoadAndCollectLootIds ( LootIdSet ids_set)
268{
269 uint32 count = LoadLootTable();
270
271 for (LootTemplateMap::const_iterator tab = m_LootTemplates.begin(); tab != m_LootTemplates.end(); ++tab)
272 lootIdSet.insert(tab->first);
273
274 return count;
275}
std::uint32_t uint32
Definition: Define.h:107
uint32 LoadLootTable()
Definition: LootMgr.cpp:143

References LoadLootTable(), and m_LootTemplates.

Referenced by LoadLootTemplates_Creature(), LoadLootTemplates_Disenchant(), LoadLootTemplates_Fishing(), LoadLootTemplates_Gameobject(), LoadLootTemplates_Item(), LoadLootTemplates_Mail(), LoadLootTemplates_Milling(), LoadLootTemplates_Pickpocketing(), LoadLootTemplates_Player(), LoadLootTemplates_Prospecting(), LoadLootTemplates_Reference(), LoadLootTemplates_Skinning(), and LoadLootTemplates_Spell().

◆ LoadLootTable()

uint32 LootStore::LoadLootTable ( )
protected
144{
145 LootTemplateMap::const_iterator tab;
146
147 // Clearing store (for reloading case)
148 Clear();
149
150 // 0 1 2 3 4 5 6
151 QueryResult result = WorldDatabase.Query("SELECT Entry, Item, Reference, Chance, QuestRequired, LootMode, GroupId, MinCount, MaxCount FROM {}", GetName());
152
153 if (!result)
154 return 0;
155
156 uint32 count = 0;
157
158 do
159 {
160 Field* fields = result->Fetch();
161
162 uint32 entry = fields[0].Get<uint32>();
163 uint32 item = fields[1].Get<uint32>();
164 int32 reference = fields[2].Get<int32>();
165 float chance = fields[3].Get<float>();
166 bool needsquest = fields[4].Get<bool>();
167 uint16 lootmode = fields[5].Get<uint16>();
168 uint8 groupid = fields[6].Get<uint8>();
169 int32 mincount = fields[7].Get<uint8>();
170 int32 maxcount = fields[8].Get<uint8>();
171
172 if (maxcount > std::numeric_limits<uint8>::max())
173 {
174 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: MaxCount value ({}) to large. must be less {} - skipped", GetName(), entry, item, maxcount, std::numeric_limits<uint8>::max());
175 continue; // error already printed to log/console.
176 }
177
178 if (lootmode == 0)
179 {
180 LOG_ERROR("sql.sql", "Table '{}' Entry {} Item {}: LootMode is equal to 0, item will never drop - setting mode 1", GetName(), entry, item);
181 lootmode = 1;
182 }
183
184 LootStoreItem* storeitem = new LootStoreItem(item, reference, chance, needsquest, lootmode, groupid, mincount, maxcount);
185
186 if (!storeitem->IsValid(*this, entry)) // Validity checks
187 {
188 delete storeitem;
189 continue;
190 }
191
192 // Looking for the template of the entry
193 // often entries are put together
194 // cppcheck-suppress eraseDereference
195 if (m_LootTemplates.empty() || tab->first != entry)
196 {
197 // Searching the template (in case template Id changed)
198 tab = m_LootTemplates.find(entry);
199 if (tab == m_LootTemplates.end())
200 {
201 std::pair< LootTemplateMap::iterator, bool > pr = m_LootTemplates.insert(LootTemplateMap::value_type(entry, new LootTemplate()));
202 tab = pr.first;
203 }
204 }
205 // else is empty - template Id and iter are the same
206 // finally iter refers to already existed or just created <entry, LootTemplate>
207
208 // Adds current row to the template
209 tab->second->AddEntry(storeitem);
210 ++count;
211 } while (result->NextRow());
212
213 Verify(); // Checks validity of the loot store
214
215 return count;
216}
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
std::int32_t int32
Definition: Define.h:103
std::uint8_t uint8
Definition: Define.h:109
std::uint16_t uint16
Definition: Define.h:108
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Class used to access individual fields of database query result.
Definition: Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:112
Definition: LootMgr.h:128
bool IsValid(LootStore const &store, uint32 entry) const
Definition: LootMgr.cpp:332
char const * GetName() const
Definition: LootMgr.h:231
void Verify() const
Definition: LootMgr.cpp:135
Definition: LootMgr.h:245

References Clear(), Field::Get(), GetName(), LootStoreItem::IsValid(), LOG_ERROR, m_LootTemplates, Verify(), and WorldDatabase.

Referenced by LoadAndCollectLootIds().

◆ ReportInvalidCount()

void LootStore::ReportInvalidCount ( uint32  lootId,
const char *  ownerType,
uint32  ownerId,
uint32  itemId,
uint8  minCount,
uint8  maxCount 
) const
301{
302 LOG_ERROR("sql.sql", "Table '{}' Entry {} used by {} entry {} item {} has minCount ( {} ) != maxCount ( {} ) which is not supported for this loot type.", GetName(), lootId, ownerType, ownerId, itemId, minCount, maxCount);
303}

References GetName(), and LOG_ERROR.

Referenced by LootTemplate::LootGroup::CheckLootRefs(), and LootTemplate::CheckLootRefs().

◆ ReportNonExistingId() [1/2]

◆ ReportNonExistingId() [2/2]

void LootStore::ReportNonExistingId ( uint32  lootId,
const char *  ownerType,
uint32  ownerId 
) const
296{
297 LOG_ERROR("sql.sql", "Table '{}' Entry {} does not exist but it is used by {} {}", GetName(), lootId, ownerType, ownerId);
298}

References GetName(), and LOG_ERROR.

◆ ReportUnusedIds()

void LootStore::ReportUnusedIds ( LootIdSet const &  ids_set) const
284{
285 // all still listed ids isn't referenced
286 for (LootIdSet::const_iterator itr = lootIdSet.begin(); itr != lootIdSet.end(); ++itr)
287 LOG_ERROR("sql.sql", "Table '{}' Entry {} isn't {} and not referenced from loot, and thus useless.", GetName(), *itr, GetEntryName());
288}
char const * GetEntryName() const
Definition: LootMgr.h:232

References GetEntryName(), GetName(), and LOG_ERROR.

Referenced by LoadLootTemplates_Creature(), LoadLootTemplates_Disenchant(), LoadLootTemplates_Fishing(), LoadLootTemplates_Gameobject(), LoadLootTemplates_Item(), LoadLootTemplates_Mail(), LoadLootTemplates_Milling(), LoadLootTemplates_Pickpocketing(), LoadLootTemplates_Prospecting(), LoadLootTemplates_Reference(), LoadLootTemplates_Skinning(), and LoadLootTemplates_Spell().

◆ ResetConditions()

void LootStore::ResetConditions ( )
239{
240 for (LootTemplateMap::iterator itr = m_LootTemplates.begin(); itr != m_LootTemplates.end(); ++itr)
241 {
242 ConditionList empty;
243 itr->second->CopyConditions(empty);
244 }
245}
std::list< Condition * > ConditionList
Definition: ConditionMgr.h:237

References m_LootTemplates.

Referenced by ConditionMgr::LoadConditions().

◆ Verify()

void LootStore::Verify ( ) const
136{
137 for (LootTemplateMap::const_iterator i = m_LootTemplates.begin(); i != m_LootTemplates.end(); ++i)
138 i->second->Verify(*this, i->first);
139}

References m_LootTemplates.

Referenced by LoadLootTable().

Member Data Documentation

◆ m_entryName

char const* LootStore::m_entryName
private

Referenced by GetEntryName().

◆ m_LootTemplates

◆ m_name

char const* LootStore::m_name
private

Referenced by GetName().

◆ m_ratesAllowed

bool LootStore::m_ratesAllowed
private

Referenced by IsRatesAllowed().