AzeorthCore 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:124

References Clear().

Member Function Documentation

◆ CheckLootRefs()

◆ Clear()

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

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

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

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
216{
217 LootTemplateMap::const_iterator itr = m_LootTemplates.find(loot_id);
218 if (itr == m_LootTemplates.end())
219 return false;
220
221 // scan loot for quest items
222 return itr->second->HasQuestDrop(m_LootTemplates);
223}

References m_LootTemplates.

Referenced by ObjectMgr::LoadGameObjectForQuests().

◆ HaveQuestLootForPlayer()

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

References m_LootTemplates.

Referenced by GameObject::ActivateToQuest().

◆ IsRatesAllowed()

bool LootStore::IsRatesAllowed ( ) const
inline

◆ LoadAndCollectLootIds()

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

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

References GetName(), and LOG_ERROR.

◆ ReportUnusedIds()

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

References m_LootTemplates.

Referenced by ConditionMgr::LoadConditions().

◆ Verify()

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

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