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
 
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
211 : 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
213{ Clear(); }
void Clear()
Definition: LootMgr.cpp:125

References Clear().

Member Function Documentation

◆ CheckLootRefs()

◆ Clear()

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

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
247{
248 LootTemplateMap::const_iterator tab = m_LootTemplates.find(loot_id);
249
250 if (tab == m_LootTemplates.end())
251 return nullptr;
252
253 return tab->second;
254}

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
257{
258 LootTemplateMap::const_iterator tab = m_LootTemplates.find(loot_id);
259
260 if (tab == m_LootTemplates.end())
261 return nullptr;
262
263 return tab->second;
264}

References m_LootTemplates.

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

◆ GetName()

char const * LootStore::GetName ( ) const
inline

◆ HaveLootFor()

bool LootStore::HaveLootFor ( uint32  loot_id) const
inline

◆ HaveQuestLootFor()

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

References m_LootTemplates.

Referenced by ObjectMgr::LoadGameObjectForQuests().

◆ HaveQuestLootForPlayer()

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

References m_LootTemplates.

Referenced by GameObject::ActivateToQuest().

◆ IsRatesAllowed()

bool LootStore::IsRatesAllowed ( ) const
inline

◆ LoadAndCollectLootIds()

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

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

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

Referenced by LoadAndCollectLootIds().

◆ ReportNonExistingId() [1/2]

◆ ReportNonExistingId() [2/2]

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

References GetName(), and LOG_ERROR.

◆ ReportUnusedIds()

void LootStore::ReportUnusedIds ( LootIdSet const &  ids_set) const
283{
284 // all still listed ids isn't referenced
285 for (LootIdSet::const_iterator itr = lootIdSet.begin(); itr != lootIdSet.end(); ++itr)
286 LOG_ERROR("sql.sql", "Table '{}' Entry {} isn't {} and not referenced from loot, and thus useless.", GetName(), *itr, GetEntryName());
287}
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 ( )
238{
239 for (LootTemplateMap::iterator itr = m_LootTemplates.begin(); itr != m_LootTemplates.end(); ++itr)
240 {
241 ConditionList empty;
242 itr->second->CopyConditions(empty);
243 }
244}
std::list< Condition * > ConditionList
Definition: ConditionMgr.h:236

References m_LootTemplates.

Referenced by ConditionMgr::LoadConditions().

◆ Verify()

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

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().