Core/ObjectMgr: Simplify trainer spell loading. Should decrease loading time on decently sized machines
--HG-- branch : trunk
This commit is contained in:
@@ -385,12 +385,12 @@ typedef UNORDERED_MAP<uint32 /*spellid*/, TrainerSpell> TrainerSpellMap;
|
|||||||
struct TrainerSpellData
|
struct TrainerSpellData
|
||||||
{
|
{
|
||||||
TrainerSpellData() : trainerType(0) {}
|
TrainerSpellData() : trainerType(0) {}
|
||||||
|
~TrainerSpellData() { spellList.clear(); }
|
||||||
|
|
||||||
TrainerSpellMap spellList;
|
TrainerSpellMap spellList;
|
||||||
uint32 trainerType; // trainer type based at trainer spells, can be different from creature_template value.
|
uint32 trainerType; // trainer type based at trainer spells, can be different from creature_template value.
|
||||||
// req. for correct show non-prof. trainers like weaponmaster, allowed values 0 and 2.
|
// req. for correct show non-prof. trainers like weaponmaster, allowed values 0 and 2.
|
||||||
TrainerSpell const* Find(uint32 spell_id) const;
|
TrainerSpell const* Find(uint32 spell_id) const;
|
||||||
void Clear() { spellList.clear(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<uint32,time_t> CreatureSpellCooldowns;
|
typedef std::map<uint32,time_t> CreatureSpellCooldowns;
|
||||||
|
|||||||
@@ -299,8 +299,7 @@ ObjectMgr::~ObjectMgr()
|
|||||||
for (CacheVendorItemMap::iterator itr = m_mCacheVendorItemMap.begin(); itr != m_mCacheVendorItemMap.end(); ++itr)
|
for (CacheVendorItemMap::iterator itr = m_mCacheVendorItemMap.begin(); itr != m_mCacheVendorItemMap.end(); ++itr)
|
||||||
itr->second.Clear();
|
itr->second.Clear();
|
||||||
|
|
||||||
for (CacheTrainerSpellMap::iterator itr = m_mCacheTrainerSpellMap.begin(); itr != m_mCacheTrainerSpellMap.end(); ++itr)
|
m_mCacheTrainerSpellMap.clear();
|
||||||
itr->second.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Group * ObjectMgr::GetGroupByGUID(uint32 guid) const
|
Group * ObjectMgr::GetGroupByGUID(uint32 guid) const
|
||||||
@@ -8567,59 +8566,51 @@ void ObjectMgr::LoadMailLevelRewards()
|
|||||||
sLog.outString();
|
sLog.outString();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ObjectMgr::AddSpellToTrainer(uint32 entry, uint32 spell, Field *fields, std::set<uint32> *skip_trainers, std::set<uint32> *talentIds)
|
void ObjectMgr::AddSpellToTrainer( uint32 entry, uint32 spell, uint32 spellCost, uint32 reqSkill, uint32 reqSkillValue, uint32 reqLevel)
|
||||||
{
|
{
|
||||||
if (entry >= TRINITY_TRAINER_START_REF)
|
if (entry >= TRINITY_TRAINER_START_REF)
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
CreatureInfo const* cInfo = GetCreatureTemplate(entry);
|
CreatureInfo const* cInfo = GetCreatureTemplate(entry);
|
||||||
if (!cInfo)
|
if (!cInfo)
|
||||||
{
|
{
|
||||||
sLog.outErrorDb("Table `npc_trainer` have entry for not existed creature template (Entry: %u), ignore", entry);
|
sLog.outErrorDb("Table `npc_trainer` contains an entry for a non-existing creature template (Entry: %u), ignoring", entry);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(cInfo->npcflag & UNIT_NPC_FLAG_TRAINER))
|
if (!(cInfo->npcflag & UNIT_NPC_FLAG_TRAINER))
|
||||||
{
|
{
|
||||||
if (skip_trainers->find(entry) == skip_trainers->end())
|
sLog.outErrorDb("Table `npc_trainer` contains an entry for a creature template (Entry: %u) without trainer flag, ignoring", entry);
|
||||||
{
|
return;
|
||||||
sLog.outErrorDb("Table `npc_trainer` have data for not creature template (Entry: %u) without trainer flag, ignore", entry);
|
|
||||||
skip_trainers->insert(entry);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SpellEntry const *spellinfo = sSpellStore.LookupEntry(spell);
|
SpellEntry const *spellinfo = sSpellStore.LookupEntry(spell);
|
||||||
if (!spellinfo)
|
if (!spellinfo)
|
||||||
{
|
{
|
||||||
sLog.outErrorDb("Table `npc_trainer` for Trainer (Entry: %u) has non existing spell %u, ignore", entry,spell);
|
sLog.outErrorDb("Table `npc_trainer` contains an entry (Entry: %u) for a non-existing spell (Spell: %u), ignoring", entry, spell);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SpellMgr::IsSpellValid(spellinfo))
|
if (!SpellMgr::IsSpellValid(spellinfo))
|
||||||
{
|
{
|
||||||
sLog.outErrorDb("Table `npc_trainer` for Trainer (Entry: %u) has broken learning spell %u, ignore", entry, spell);
|
sLog.outErrorDb("Table `npc_trainer` contains an entry (Entry: %u) for a broken spell (Spell: %u), ignoring", entry, spell);
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetTalentSpellCost(spell))
|
if (GetTalentSpellCost(spell))
|
||||||
{
|
{
|
||||||
if (talentIds->count(spell) == 0)
|
sLog.outErrorDb("Table `npc_trainer` contains an entry (Entry: %u) for a non-existing spell (Spell: %u) which is a talent, ignoring", entry, spell);
|
||||||
{
|
return;
|
||||||
sLog.outErrorDb("Table `npc_trainer` has talent as learning spell %u, ignore", spell);
|
|
||||||
talentIds->insert(spell);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TrainerSpellData& data = m_mCacheTrainerSpellMap[entry];
|
TrainerSpellData& data = m_mCacheTrainerSpellMap[entry];
|
||||||
|
|
||||||
TrainerSpell& trainerSpell = data.spellList[spell];
|
TrainerSpell& trainerSpell = data.spellList[spell];
|
||||||
trainerSpell.spell = spell;
|
trainerSpell.spell = spell;
|
||||||
trainerSpell.spellCost = fields[2].GetUInt32();
|
trainerSpell.spellCost = spellCost;
|
||||||
trainerSpell.reqSkill = fields[3].GetUInt32();
|
trainerSpell.reqSkill = reqSkill;
|
||||||
trainerSpell.reqSkillValue = fields[4].GetUInt32();
|
trainerSpell.reqSkillValue = reqSkillValue;
|
||||||
trainerSpell.reqLevel = fields[5].GetUInt32();
|
trainerSpell.reqLevel = reqLevel;
|
||||||
|
|
||||||
if (!trainerSpell.reqLevel)
|
if (!trainerSpell.reqLevel)
|
||||||
trainerSpell.reqLevel = spellinfo->spellLevel;
|
trainerSpell.reqLevel = spellinfo->spellLevel;
|
||||||
@@ -8641,40 +8632,12 @@ bool ObjectMgr::AddSpellToTrainer(uint32 entry, uint32 spell, Field *fields, std
|
|||||||
}
|
}
|
||||||
|
|
||||||
trainerSpell.learnedSpell[i] = spellinfo->EffectTriggerSpell[i];
|
trainerSpell.learnedSpell[i] = spellinfo->EffectTriggerSpell[i];
|
||||||
}
|
|
||||||
|
|
||||||
for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i)
|
if (trainerSpell.learnedSpell[i] && SpellMgr::IsProfessionSpell(trainerSpell.learnedSpell[i]))
|
||||||
{
|
|
||||||
if (!trainerSpell.learnedSpell[i])
|
|
||||||
continue;
|
|
||||||
if (SpellMgr::IsProfessionSpell(trainerSpell.learnedSpell[i]))
|
|
||||||
{
|
|
||||||
data.trainerType = 2;
|
data.trainerType = 2;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
int ObjectMgr::LoadReferenceTrainer(uint32 trainer, int32 spell, std::set<uint32> *skip_trainers, std::set<uint32> *talentIds)
|
|
||||||
{
|
|
||||||
QueryResult result = WorldDatabase.PQuery("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer WHERE entry='%d'", spell);
|
|
||||||
if (!result)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
uint32 count = 0;
|
return;
|
||||||
do
|
|
||||||
{
|
|
||||||
|
|
||||||
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, uint32(spell), fields, skip_trainers, talentIds))
|
|
||||||
++count;
|
|
||||||
} while (result->NextRow());
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectMgr::LoadTrainerSpell()
|
void ObjectMgr::LoadTrainerSpell()
|
||||||
@@ -8682,13 +8645,13 @@ void ObjectMgr::LoadTrainerSpell()
|
|||||||
uint32 oldMSTime = getMSTime();
|
uint32 oldMSTime = getMSTime();
|
||||||
|
|
||||||
// For reload case
|
// For reload case
|
||||||
for (CacheTrainerSpellMap::iterator itr = m_mCacheTrainerSpellMap.begin(); itr != m_mCacheTrainerSpellMap.end(); ++itr)
|
|
||||||
itr->second.Clear();
|
|
||||||
m_mCacheTrainerSpellMap.clear();
|
m_mCacheTrainerSpellMap.clear();
|
||||||
|
|
||||||
std::set<uint32> skip_trainers;
|
std::set<uint32> skip_trainers;
|
||||||
|
|
||||||
QueryResult result = WorldDatabase.Query("SELECT entry, spell,spellcost,reqskill,reqskillvalue,reqlevel FROM npc_trainer");
|
QueryResult result = WorldDatabase.Query("SELECT b.entry, a.spell, a.spellcost, a.reqskill, a.reqskillvalue, a.reqlevel FROM npc_trainer AS a "
|
||||||
|
"INNER JOIN npc_trainer AS b ON a.entry = -(b.spell) "
|
||||||
|
"UNION SELECT * FROM npc_trainer WHERE spell > 0");
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
@@ -8701,7 +8664,6 @@ void ObjectMgr::LoadTrainerSpell()
|
|||||||
|
|
||||||
barGoLink bar(result->GetRowCount());
|
barGoLink bar(result->GetRowCount());
|
||||||
uint32 count = 0;
|
uint32 count = 0;
|
||||||
std::set<uint32> talentIds;
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -8709,12 +8671,16 @@ void ObjectMgr::LoadTrainerSpell()
|
|||||||
|
|
||||||
Field* fields = result->Fetch();
|
Field* fields = result->Fetch();
|
||||||
|
|
||||||
uint32 entry = fields[0].GetUInt32();
|
uint32 entry = fields[0].GetUInt32();
|
||||||
int32 spell = fields[1].GetInt32();
|
uint32 spell = fields[1].GetUInt32();
|
||||||
if (spell < 0)
|
uint32 spellCost = fields[2].GetUInt32();
|
||||||
count += this->LoadReferenceTrainer(entry, -spell, &skip_trainers, &talentIds);
|
uint32 reqSkill = fields[3].GetUInt32();
|
||||||
else if (this->AddSpellToTrainer(entry, uint32(spell), fields, &skip_trainers, &talentIds))
|
uint32 reqSkillValue = fields[4].GetUInt32();
|
||||||
++count;
|
uint32 reqLevel = fields[5].GetUInt32();
|
||||||
|
|
||||||
|
AddSpellToTrainer(entry, spell, spellCost, reqSkill, reqSkillValue, reqLevel);
|
||||||
|
|
||||||
|
count++;
|
||||||
|
|
||||||
}
|
}
|
||||||
while (result->NextRow());
|
while (result->NextRow());
|
||||||
|
|||||||
@@ -926,8 +926,7 @@ class ObjectMgr
|
|||||||
|
|
||||||
void LoadVendors();
|
void LoadVendors();
|
||||||
void LoadTrainerSpell();
|
void LoadTrainerSpell();
|
||||||
bool AddSpellToTrainer(uint32 entry, uint32 spell, Field *fields, std::set<uint32> *skip_trainers, std::set<uint32> *talentIds);
|
void AddSpellToTrainer(uint32 entry, uint32 spell, uint32 spellCost, uint32 reqSkill, uint32 reqSkillValue, uint32 reqLevel);
|
||||||
int LoadReferenceTrainer(uint32 trainer, int32 spell, std::set<uint32> *skip_trainers, std::set<uint32> *talentIds);
|
|
||||||
|
|
||||||
std::string GeneratePetName(uint32 entry);
|
std::string GeneratePetName(uint32 entry);
|
||||||
uint32 GetBaseXP(uint8 level);
|
uint32 GetBaseXP(uint8 level);
|
||||||
|
|||||||
Reference in New Issue
Block a user