* Allow the use of referenced trainer / vendor data.
* This will reduce the size of the trainer / vendor tables a LOT. * Current tables will continue to work as/is until the refs can be made. * Huge thanks to XTElite1 * Credits for patch to Cycrow --HG-- branch : trunk
This commit is contained in:
+136
-46
@@ -8148,81 +8148,47 @@ void ObjectMgr::LoadMailLevelRewards()
|
||||
sLog.outString( ">> Loaded %u level dependent mail rewards,", count );
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadTrainerSpell()
|
||||
bool ObjectMgr::AddSpellToTrainer(int32 entry, int32 spell, Field *fields, std::set<uint32> *skip_trainers, std::set<uint32> *talentIds)
|
||||
{
|
||||
// For reload case
|
||||
for (CacheTrainerSpellMap::iterator itr = m_mCacheTrainerSpellMap.begin(); itr != m_mCacheTrainerSpellMap.end(); ++itr)
|
||||
itr->second.Clear();
|
||||
m_mCacheTrainerSpellMap.clear();
|
||||
|
||||
std::set<uint32> skip_trainers;
|
||||
|
||||
QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer");
|
||||
|
||||
if( !result )
|
||||
{
|
||||
barGoLink bar( 1 );
|
||||
|
||||
bar.step();
|
||||
|
||||
sLog.outString();
|
||||
sLog.outErrorDb(">> Loaded `npc_trainer`, table is empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
barGoLink bar( result->GetRowCount() );
|
||||
|
||||
std::set<uint32> talentIds;
|
||||
|
||||
uint32 count = 0;
|
||||
do
|
||||
{
|
||||
bar.step();
|
||||
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 entry = fields[0].GetUInt32();
|
||||
uint32 spell = fields[1].GetUInt32();
|
||||
|
||||
CreatureInfo const* cInfo = GetCreatureTemplate(entry);
|
||||
|
||||
if(!cInfo)
|
||||
if(!cInfo && entry > 0)
|
||||
{
|
||||
sLog.outErrorDb("Table `npc_trainer` have entry for not existed creature template (Entry: %u), ignore", entry);
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!(cInfo->npcflag & UNIT_NPC_FLAG_TRAINER))
|
||||
{
|
||||
if (skip_trainers.find(entry) == skip_trainers.end())
|
||||
if (skip_trainers->find(entry) == skip_trainers->end())
|
||||
{
|
||||
sLog.outErrorDb("Table `npc_trainer` have data for not creature template (Entry: %u) without trainer flag, ignore", entry);
|
||||
skip_trainers.insert(entry);
|
||||
skip_trainers->insert(entry);
|
||||
}
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
SpellEntry const *spellinfo = sSpellStore.LookupEntry(spell);
|
||||
if(!spellinfo)
|
||||
{
|
||||
sLog.outErrorDb("Table `npc_trainer` for Trainer (Entry: %u ) has non existing spell %u, ignore", entry,spell);
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!SpellMgr::IsSpellValid(spellinfo))
|
||||
{
|
||||
sLog.outErrorDb("Table `npc_trainer` for Trainer (Entry: %u) has broken learning spell %u, ignore", entry, spell);
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(GetTalentSpellCost(spell))
|
||||
{
|
||||
if(talentIds.count(spell)==0)
|
||||
if(talentIds->count(spell)==0)
|
||||
{
|
||||
sLog.outErrorDb("Table `npc_trainer` has talent as learning spell %u, ignore", spell);
|
||||
talentIds.insert(spell);
|
||||
talentIds->insert(spell);
|
||||
}
|
||||
continue;
|
||||
return false;
|
||||
}
|
||||
|
||||
TrainerSpellData& data = m_mCacheTrainerSpellMap[entry];
|
||||
@@ -8267,6 +8233,77 @@ void ObjectMgr::LoadTrainerSpell()
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int ObjectMgr::LoadReferenceTrainer(int32 trainer, int32 spell, std::set<uint32> *skip_trainers, std::set<uint32> *talentIds)
|
||||
{
|
||||
QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer WHERE entry='%d'", spell);
|
||||
if ( !result )
|
||||
{
|
||||
barGoLink bar( 1 );
|
||||
|
||||
bar.step();
|
||||
return 0;
|
||||
}
|
||||
|
||||
barGoLink bar( result->GetRowCount() );
|
||||
|
||||
uint32 count = 0;
|
||||
do
|
||||
{
|
||||
bar.step();
|
||||
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
int32 spell = fields[1].GetInt32();
|
||||
if ( spell < 0 )
|
||||
count += this->LoadReferenceTrainer(trainer, -spell, skip_trainers, talentIds);
|
||||
else if ( this->AddSpellToTrainer(trainer, spell, fields, skip_trainers, talentIds) )
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadTrainerSpell()
|
||||
{
|
||||
// For reload case
|
||||
for (CacheTrainerSpellMap::iterator itr = m_mCacheTrainerSpellMap.begin(); itr != m_mCacheTrainerSpellMap.end(); ++itr)
|
||||
itr->second.Clear();
|
||||
m_mCacheTrainerSpellMap.clear();
|
||||
|
||||
std::set<uint32> skip_trainers;
|
||||
|
||||
QueryResult_AutoPtr result = WorldDatabase.Query("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer");
|
||||
|
||||
if( !result )
|
||||
{
|
||||
barGoLink bar( 1 );
|
||||
|
||||
bar.step();
|
||||
|
||||
sLog.outString();
|
||||
sLog.outErrorDb(">> Loaded `npc_trainer`, table is empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
barGoLink bar( result->GetRowCount() );
|
||||
|
||||
std::set<uint32> talentIds;
|
||||
|
||||
uint32 count = 0;
|
||||
do
|
||||
{
|
||||
bar.step();
|
||||
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 entry = fields[0].GetUInt32();
|
||||
int32 spell = fields[1].GetInt32();
|
||||
if ( spell < 0 )
|
||||
count += this->LoadReferenceTrainer(entry, -spell, &skip_trainers, &talentIds);
|
||||
else if ( this->AddSpellToTrainer(entry, spell, fields, &skip_trainers, &talentIds) )
|
||||
++count;
|
||||
|
||||
} while (result->NextRow());
|
||||
@@ -8275,6 +8312,52 @@ void ObjectMgr::LoadTrainerSpell()
|
||||
sLog.outString( ">> Loaded %d Trainers", count );
|
||||
}
|
||||
|
||||
int ObjectMgr::LoadReferenceVendor(int32 vendor, int32 item, std::set<uint32> *skip_vendors)
|
||||
{
|
||||
// find all items from the reference vendor
|
||||
QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT entry, item, maxcount, incrtime, ExtendedCost FROM npc_vendor WHERE entry='%d'", item);
|
||||
if( !result )
|
||||
{
|
||||
barGoLink bar( 1 );
|
||||
|
||||
bar.step();
|
||||
return 0;
|
||||
}
|
||||
|
||||
barGoLink bar( result->GetRowCount() );
|
||||
|
||||
uint32 count = 0;
|
||||
do
|
||||
{
|
||||
bar.step();
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 entry = fields[0].GetUInt32();
|
||||
int32 item_id = fields[1].GetInt32();
|
||||
|
||||
// if item is a negative, its a reference
|
||||
if ( item_id < 0 )
|
||||
count += LoadReferenceVendor(vendor, -item_id, skip_vendors);
|
||||
else
|
||||
{
|
||||
int32 maxcount = fields[2].GetInt32();
|
||||
uint32 incrtime = fields[3].GetUInt32();
|
||||
uint32 ExtendedCost = fields[4].GetUInt32();
|
||||
|
||||
if(!IsVendorItemValid(vendor,item_id,maxcount,incrtime,ExtendedCost,NULL,skip_vendors))
|
||||
continue;
|
||||
|
||||
VendorItemData& vList = m_mCacheVendorItemMap[vendor];
|
||||
|
||||
vList.AddItem(item_id,maxcount,incrtime,ExtendedCost);
|
||||
++count;
|
||||
}
|
||||
|
||||
} while (result->NextRow());
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadVendors()
|
||||
{
|
||||
// For reload case
|
||||
@@ -8305,7 +8388,13 @@ void ObjectMgr::LoadVendors()
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
uint32 entry = fields[0].GetUInt32();
|
||||
uint32 item_id = fields[1].GetUInt32();
|
||||
int32 item_id = fields[1].GetInt32();
|
||||
|
||||
// if item is a negative, its a reference
|
||||
if ( item_id < 0 )
|
||||
count += LoadReferenceVendor(entry, -item_id, &skip_vendors);
|
||||
else
|
||||
{
|
||||
int32 maxcount = fields[2].GetInt32();
|
||||
uint32 incrtime = fields[3].GetUInt32();
|
||||
uint32 ExtendedCost = fields[4].GetUInt32();
|
||||
@@ -8317,6 +8406,7 @@ void ObjectMgr::LoadVendors()
|
||||
|
||||
vList.AddItem(item_id,maxcount,incrtime,ExtendedCost);
|
||||
++count;
|
||||
}
|
||||
|
||||
} while (result->NextRow());
|
||||
|
||||
|
||||
@@ -429,6 +429,7 @@ class ObjectMgr
|
||||
Player* GetPlayer(uint64 guid) const { return ObjectAccessor::FindPlayer(guid); }
|
||||
|
||||
static GameObjectInfo const *GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry<GameObjectInfo>(id); }
|
||||
int LoadReferenceVendor(int32 vendor, int32 item_id, std::set<uint32> *skip_vendors);
|
||||
|
||||
void LoadGameobjectInfo();
|
||||
void AddGameobjectInfo(GameObjectInfo *goinfo);
|
||||
@@ -691,6 +692,8 @@ class ObjectMgr
|
||||
|
||||
void LoadVendors();
|
||||
void LoadTrainerSpell();
|
||||
bool AddSpellToTrainer(int32 entry, int32 spell, Field *fields, std::set<uint32> *skip_trainers, std::set<uint32> *talentIds);
|
||||
int LoadReferenceTrainer(int32 trainer, int32 spell, std::set<uint32> *skip_trainers, std::set<uint32> *talentIds);
|
||||
void LoadGMTickets();
|
||||
|
||||
std::string GeneratePetName(uint32 entry);
|
||||
|
||||
Reference in New Issue
Block a user