aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Loot/LootMgr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/game/Loot/LootMgr.cpp')
-rwxr-xr-xsrc/server/game/Loot/LootMgr.cpp256
1 files changed, 190 insertions, 66 deletions
diff --git a/src/server/game/Loot/LootMgr.cpp b/src/server/game/Loot/LootMgr.cpp
index be3058be2d4..b00bfd44b36 100755
--- a/src/server/game/Loot/LootMgr.cpp
+++ b/src/server/game/Loot/LootMgr.cpp
@@ -91,79 +91,75 @@ void LootStore::Verify() const
// Loads a *_loot_template DB table into loot store
// All checks of the loaded template are called from here, no error reports at loot generation required
-void LootStore::LoadLootTable()
+uint32 LootStore::LoadLootTable()
{
LootTemplateMap::const_iterator tab;
// Clearing store (for reloading case)
Clear();
- sLog.outString("%s :", GetName());
+ // 0 1 2 3 4 5 6
+ QueryResult result = WorldDatabase.PQuery("SELECT entry, item, ChanceOrQuestChance, lootmode, groupid, mincountOrRef, maxcount FROM %s", GetName());
- // 0 1 2 3 4 5 6
- QueryResult result = WorldDatabase.PQuery("SELECT entry, item, ChanceOrQuestChance, lootmode, groupid, mincountOrRef, maxcount FROM %s",GetName());
-
- if (result)
+ if (!result)
{
- uint32 count = 0;
+ barGoLink bar(1);
+ bar.step();
+ return 0;
+}
- barGoLink bar(result->GetRowCount());
+ uint32 count = 0;
+ barGoLink bar(result->GetRowCount());
- do
+ do
+ {
+ Field *fields = result->Fetch();
+ bar.step();
+
+ uint32 entry = fields[0].GetUInt32();
+ uint32 item = fields[1].GetUInt32();
+ float chanceOrQuestChance = fields[2].GetFloat();
+ uint16 lootmode = fields[3].GetUInt16();
+ uint8 group = fields[4].GetUInt8();
+ int32 mincountOrRef = fields[5].GetInt32();
+ int32 maxcount = fields[6].GetInt32();
+
+ if (maxcount > std::numeric_limits<uint8>::max())
{
- Field *fields = result->Fetch();
- bar.step();
-
- uint32 entry = fields[0].GetUInt32();
- uint32 item = fields[1].GetUInt32();
- float chanceOrQuestChance = fields[2].GetFloat();
- uint16 lootmode = fields[3].GetUInt16();
- uint8 group = fields[4].GetUInt8();
- int32 mincountOrRef = fields[5].GetInt32();
- int32 maxcount = fields[6].GetInt32();
-
- if (maxcount > std::numeric_limits<uint8>::max())
- {
- sLog.outErrorDb("Table '%s' entry %d item %d: maxcount value (%u) to large. must be less %u - skipped", GetName(), entry, item, maxcount,std::numeric_limits<uint8>::max());
- continue; // error already printed to log/console.
- }
+ sLog.outErrorDb("Table '%s' entry %d item %d: maxcount value (%u) to large. must be less %u - skipped", GetName(), entry, item, maxcount,std::numeric_limits<uint8>::max());
+ continue; // error already printed to log/console.
+ }
- LootStoreItem storeitem = LootStoreItem(item, chanceOrQuestChance, lootmode, group, mincountOrRef, maxcount);
+ LootStoreItem storeitem = LootStoreItem(item, chanceOrQuestChance, lootmode, group, mincountOrRef, maxcount);
- if (!storeitem.IsValid(*this,entry)) // Validity checks
- continue;
+ if (!storeitem.IsValid(*this,entry)) // Validity checks
+ continue;
- // Looking for the template of the entry
- // often entries are put together
- if (m_LootTemplates.empty() || tab->first != entry)
+ // Looking for the template of the entry
+ // often entries are put together
+ if (m_LootTemplates.empty() || tab->first != entry)
+ {
+ // Searching the template (in case template Id changed)
+ tab = m_LootTemplates.find(entry);
+ if (tab == m_LootTemplates.end())
{
- // Searching the template (in case template Id changed)
- tab = m_LootTemplates.find(entry);
- if (tab == m_LootTemplates.end())
- {
- std::pair< LootTemplateMap::iterator, bool > pr = m_LootTemplates.insert(LootTemplateMap::value_type(entry, new LootTemplate));
- tab = pr.first;
- }
+ std::pair< LootTemplateMap::iterator, bool > pr = m_LootTemplates.insert(LootTemplateMap::value_type(entry, new LootTemplate));
+ tab = pr.first;
}
- // else is empty - template Id and iter are the same
- // finally iter refers to already existed or just created <entry, LootTemplate>
+ }
+ // else is empty - template Id and iter are the same
+ // finally iter refers to already existed or just created <entry, LootTemplate>
- // Adds current row to the template
- tab->second->AddEntry(storeitem);
- ++count;
+ // Adds current row to the template
+ tab->second->AddEntry(storeitem);
+ ++count;
- } while (result->NextRow());
+ }
+ while (result->NextRow());
- Verify(); // Checks validity of the loot store
+ Verify(); // Checks validity of the loot store
- sLog.outString();
- sLog.outString(">> Loaded %u loot definitions (%lu templates)", count, (unsigned long)m_LootTemplates.size());
- }
- else
- {
- sLog.outString();
- sLog.outErrorDb(">> Loaded 0 loot definitions. DB table `%s` is empty.",GetName());
- }
+ return count;
}
bool LootStore::HaveQuestLootFor(uint32 loot_id) const
@@ -215,12 +211,14 @@ LootTemplate* LootStore::GetLootForConditionFill(uint32 loot_id)
return tab->second;
}
-void LootStore::LoadAndCollectLootIds(LootIdSet& ids_set)
+uint32 LootStore::LoadAndCollectLootIds(LootIdSet& ids_set)
{
- LoadLootTable();
+ uint32 count = LoadLootTable();
for (LootTemplateMap::const_iterator tab = m_LootTemplates.begin(); tab != m_LootTemplates.end(); ++tab)
ids_set.insert(tab->first);
+
+ return count;
}
void LootStore::CheckLootRefs(LootIdSet* ref_set) const
@@ -1407,8 +1405,12 @@ bool LootTemplate::isReference(uint32 id)
void LoadLootTemplates_Creature()
{
+ sLog.outString("Loading creature loot templates...");
+
+ uint32 oldMSTime = getMSTime();
+
LootIdSet ids_set, ids_setUsed;
- LootTemplates_Creature.LoadAndCollectLootIds(ids_set);
+ uint32 count = LootTemplates_Creature.LoadAndCollectLootIds(ids_set);
// remove real entries and check existence loot
for (uint32 i = 1; i < sCreatureStorage.MaxEntry; ++i)
@@ -1429,12 +1431,23 @@ void LoadLootTemplates_Creature()
// output error for any still listed (not referenced from appropriate table) ids
LootTemplates_Creature.ReportUnusedIds(ids_set);
+
+ if(count)
+ sLog.outString(">> Loaded %u creature loot templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
+ else
+ sLog.outErrorDb(">> Loaded 0 creature loot templates. DB table `creature_loot_template` is empty");
+
+ sLog.outString();
}
void LoadLootTemplates_Disenchant()
{
+ sLog.outString("Loading disenchanting loot templates...");
+
+ uint32 oldMSTime = getMSTime();
+
LootIdSet ids_set, ids_setUsed;
- LootTemplates_Disenchant.LoadAndCollectLootIds(ids_set);
+ uint32 count = LootTemplates_Disenchant.LoadAndCollectLootIds(ids_set);
// remove real entries and check existence loot
for (uint32 i = 1; i < sItemStorage.MaxEntry; ++i)
@@ -1454,12 +1467,22 @@ void LoadLootTemplates_Disenchant()
ids_set.erase(*itr);
// output error for any still listed (not referenced from appropriate table) ids
LootTemplates_Disenchant.ReportUnusedIds(ids_set);
+
+ if(count)
+ sLog.outString(">> Loaded %u disenchanting loot templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
+ else
+ sLog.outErrorDb(">> Loaded 0 disenchanting loot templates. DB table `disenchant_loot_template` is empty");
+ sLog.outString();
}
void LoadLootTemplates_Fishing()
{
+ sLog.outString("Loading fishing loot templates...");
+
+ uint32 oldMSTime = getMSTime();
+
LootIdSet ids_set;
- LootTemplates_Fishing.LoadAndCollectLootIds(ids_set);
+ uint32 count = LootTemplates_Fishing.LoadAndCollectLootIds(ids_set);
// remove real entries and check existence loot
for (uint32 i = 1; i < sAreaStore.GetNumRows(); ++i)
@@ -1469,12 +1492,23 @@ void LoadLootTemplates_Fishing()
// output error for any still listed (not referenced from appropriate table) ids
LootTemplates_Fishing.ReportUnusedIds(ids_set);
+
+ if(count)
+ sLog.outString(">> Loaded %u fishing loot templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
+ else
+ sLog.outErrorDb(">> Loaded 0 fishing loot templates. DB table `fishing_loot_template` is empty");
+
+ sLog.outString();
}
void LoadLootTemplates_Gameobject()
{
+ sLog.outString("Loading gameobject loot templates...");
+
+ uint32 oldMSTime = getMSTime();
+
LootIdSet ids_set, ids_setUsed;
- LootTemplates_Gameobject.LoadAndCollectLootIds(ids_set);
+ uint32 count = LootTemplates_Gameobject.LoadAndCollectLootIds(ids_set);
// remove real entries and check existence loot
for (uint32 i = 1; i < sGOStorage.MaxEntry; ++i)
@@ -1495,12 +1529,23 @@ void LoadLootTemplates_Gameobject()
// output error for any still listed (not referenced from appropriate table) ids
LootTemplates_Gameobject.ReportUnusedIds(ids_set);
+
+ if(count)
+ sLog.outString(">> Loaded %u gameobject loot templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
+ else
+ sLog.outErrorDb(">> Loaded 0 gameobject loot templates. DB table `gameobject_loot_template` is empty");
+
+ sLog.outString();
}
void LoadLootTemplates_Item()
{
+ sLog.outString("Loading item loot templates...");
+
+ uint32 oldMSTime = getMSTime();
+
LootIdSet ids_set;
- LootTemplates_Item.LoadAndCollectLootIds(ids_set);
+ uint32 count = LootTemplates_Item.LoadAndCollectLootIds(ids_set);
// remove real entries and check existence loot
for (uint32 i = 1; i < sItemStorage.MaxEntry; ++i)
@@ -1510,12 +1555,23 @@ void LoadLootTemplates_Item()
// output error for any still listed (not referenced from appropriate table) ids
LootTemplates_Item.ReportUnusedIds(ids_set);
+
+ if(count)
+ sLog.outString(">> Loaded %u prospecting loot templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
+ else
+ sLog.outErrorDb(">> Loaded 0 prospecting loot templates. DB table `item_loot_template` is empty");
+
+ sLog.outString();
}
void LoadLootTemplates_Milling()
{
+ sLog.outString("Loading milling loot templates...");
+
+ uint32 oldMSTime = getMSTime();
+
LootIdSet ids_set;
- LootTemplates_Milling.LoadAndCollectLootIds(ids_set);
+ uint32 count = LootTemplates_Milling.LoadAndCollectLootIds(ids_set);
// remove real entries and check existence loot
for (uint32 i = 1; i < sItemStorage.MaxEntry; ++i)
@@ -1533,12 +1589,23 @@ void LoadLootTemplates_Milling()
// output error for any still listed (not referenced from appropriate table) ids
LootTemplates_Milling.ReportUnusedIds(ids_set);
+
+ if(count)
+ sLog.outString(">> Loaded %u milling loot templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
+ else
+ sLog.outErrorDb(">> Loaded 0 milling loot templates. DB table `milling_loot_template` is empty");
+
+ sLog.outString();
}
void LoadLootTemplates_Pickpocketing()
{
+ sLog.outString("Loading pickpocketing loot templates...");
+
+ uint32 oldMSTime = getMSTime();
+
LootIdSet ids_set, ids_setUsed;
- LootTemplates_Pickpocketing.LoadAndCollectLootIds(ids_set);
+ uint32 count = LootTemplates_Pickpocketing.LoadAndCollectLootIds(ids_set);
// remove real entries and check existence loot
for (uint32 i = 1; i < sCreatureStorage.MaxEntry; ++i)
@@ -1559,12 +1626,23 @@ void LoadLootTemplates_Pickpocketing()
// output error for any still listed (not referenced from appropriate table) ids
LootTemplates_Pickpocketing.ReportUnusedIds(ids_set);
+
+ if(count)
+ sLog.outString(">> Loaded %u pickpocketing loot templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
+ else
+ sLog.outErrorDb(">> Loaded 0 pickpocketing loot templates. DB table `pickpocketing_loot_template` is empty");
+
+ sLog.outString();
}
void LoadLootTemplates_Prospecting()
{
+ sLog.outString("Loading prospecting loot templates...");
+
+ uint32 oldMSTime = getMSTime();
+
LootIdSet ids_set;
- LootTemplates_Prospecting.LoadAndCollectLootIds(ids_set);
+ uint32 count = LootTemplates_Prospecting.LoadAndCollectLootIds(ids_set);
// remove real entries and check existence loot
for (uint32 i = 1; i < sItemStorage.MaxEntry; ++i)
@@ -1582,12 +1660,23 @@ void LoadLootTemplates_Prospecting()
// output error for any still listed (not referenced from appropriate table) ids
LootTemplates_Prospecting.ReportUnusedIds(ids_set);
+
+ if(count)
+ sLog.outString(">> Loaded %u prospecting loot templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
+ else
+ sLog.outErrorDb(">> Loaded 0 prospecting loot templates. DB table `prospecting_loot_template` is empty");
+
+ sLog.outString();
}
void LoadLootTemplates_Mail()
{
+ sLog.outString("Loading mail loot templates...");
+
+ uint32 oldMSTime = getMSTime();
+
LootIdSet ids_set;
- LootTemplates_Mail.LoadAndCollectLootIds(ids_set);
+ uint32 count = LootTemplates_Mail.LoadAndCollectLootIds(ids_set);
// remove real entries and check existence loot
for (uint32 i = 1; i < sMailTemplateStore.GetNumRows(); ++i)
@@ -1597,12 +1686,23 @@ void LoadLootTemplates_Mail()
// output error for any still listed (not referenced from appropriate table) ids
LootTemplates_Mail.ReportUnusedIds(ids_set);
+
+ if(count)
+ sLog.outString(">> Loaded %u mail loot templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
+ else
+ sLog.outErrorDb(">> Loaded 0 mail loot templates. DB table `mail_loot_template` is empty");
+
+ sLog.outString();
}
void LoadLootTemplates_Skinning()
{
+ sLog.outString("Loading skinning loot templates...");
+
+ uint32 oldMSTime = getMSTime();
+
LootIdSet ids_set, ids_setUsed;
- LootTemplates_Skinning.LoadAndCollectLootIds(ids_set);
+ uint32 count = LootTemplates_Skinning.LoadAndCollectLootIds(ids_set);
// remove real entries and check existence loot
for (uint32 i = 1; i < sCreatureStorage.MaxEntry; ++i)
@@ -1623,12 +1723,23 @@ void LoadLootTemplates_Skinning()
// output error for any still listed (not referenced from appropriate table) ids
LootTemplates_Skinning.ReportUnusedIds(ids_set);
+
+ if(count)
+ sLog.outString(">> Loaded %u skinning loot templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
+ else
+ sLog.outErrorDb(">> Loaded 0 skinning loot templates. DB table `skinning_loot_template` is empty");
+
+ sLog.outString();
}
void LoadLootTemplates_Spell()
{
+ sLog.outString("Loading spell loot templates...");
+
+ uint32 oldMSTime = getMSTime();
+
LootIdSet ids_set;
- LootTemplates_Spell.LoadAndCollectLootIds(ids_set);
+ uint32 count = LootTemplates_Spell.LoadAndCollectLootIds(ids_set);
// remove real entries and check existence loot
for (uint32 spell_id = 1; spell_id < sSpellStore.GetNumRows(); ++spell_id)
@@ -1656,10 +1767,20 @@ void LoadLootTemplates_Spell()
// output error for any still listed (not referenced from appropriate table) ids
LootTemplates_Spell.ReportUnusedIds(ids_set);
+
+ if(count)
+ sLog.outString(">> Loaded %u spell loot templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
+ else
+ sLog.outErrorDb(">> Loaded 0 spell loot templates. DB table `spell_loot_template` is empty");
+ sLog.outString();
}
void LoadLootTemplates_Reference()
{
+ sLog.outString("Loading reference loot templates...");
+
+ uint32 oldMSTime = getMSTime();
+
LootIdSet ids_set;
LootTemplates_Reference.LoadAndCollectLootIds(ids_set);
@@ -1678,4 +1799,7 @@ void LoadLootTemplates_Reference()
// output error for any still listed ids (not referenced from any loot table)
LootTemplates_Reference.ReportUnusedIds(ids_set);
+
+ sLog.outString(">> Loaded refence loot templates in %u ms", GetMSTimeDiffToNow(oldMSTime));
+ sLog.outString();
}