mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 22:37:03 +00:00
[7283] Use map for trainer spells for fast find data by spell id.
Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
parent
02b4b2f0b1
commit
22656b33e3
5 changed files with 38 additions and 42 deletions
|
|
@ -46,18 +46,11 @@
|
||||||
// apply implementation of the singletons
|
// apply implementation of the singletons
|
||||||
#include "Policies/SingletonImp.h"
|
#include "Policies/SingletonImp.h"
|
||||||
|
|
||||||
void TrainerSpellData::Clear()
|
|
||||||
{
|
|
||||||
for (TrainerSpellList::iterator itr = spellList.begin(); itr != spellList.end(); ++itr)
|
|
||||||
delete (*itr);
|
|
||||||
spellList.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const
|
TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const
|
||||||
{
|
{
|
||||||
for(TrainerSpellList::const_iterator itr = spellList.begin(); itr != spellList.end(); ++itr)
|
TrainerSpellMap::const_iterator itr = spellList.find(spell_id);
|
||||||
if((*itr)->spell == spell_id)
|
if (itr != spellList.end())
|
||||||
return *itr;
|
return &itr->second;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -358,6 +358,12 @@ typedef std::list<VendorItemCount> VendorItemCounts;
|
||||||
|
|
||||||
struct TrainerSpell
|
struct TrainerSpell
|
||||||
{
|
{
|
||||||
|
TrainerSpell() : spell(0), spellCost(0), reqSkill(0), reqSkillValue(0), reqLevel(0), learnedSpell(0) {}
|
||||||
|
|
||||||
|
TrainerSpell(uint32 _spell, uint32 _spellCost, uint32 _reqSkill, uint32 _reqSkillValue, uint32 _reqLevel, uint32 _learnedspell)
|
||||||
|
: spell(_spell), spellCost(_spellCost), reqSkill(_reqSkill), reqSkillValue(_reqSkillValue), reqLevel(_reqLevel), learnedSpell(_learnedspell)
|
||||||
|
{}
|
||||||
|
|
||||||
uint32 spell;
|
uint32 spell;
|
||||||
uint32 spellCost;
|
uint32 spellCost;
|
||||||
uint32 reqSkill;
|
uint32 reqSkill;
|
||||||
|
|
@ -369,18 +375,17 @@ struct TrainerSpell
|
||||||
bool IsCastable() const { return learnedSpell != spell; }
|
bool IsCastable() const { return learnedSpell != spell; }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<TrainerSpell*> TrainerSpellList;
|
typedef UNORDERED_MAP<uint32 /*spellid*/, TrainerSpell> TrainerSpellMap;
|
||||||
|
|
||||||
struct TrainerSpellData
|
struct TrainerSpellData
|
||||||
{
|
{
|
||||||
TrainerSpellData() : trainerType(0) {}
|
TrainerSpellData() : trainerType(0) {}
|
||||||
|
|
||||||
TrainerSpellList 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.
|
||||||
|
|
||||||
void Clear();
|
|
||||||
TrainerSpell const* Find(uint32 spell_id) const;
|
TrainerSpell const* Find(uint32 spell_id) const;
|
||||||
|
void Clear() { spellList.clear(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::list<GossipOption> GossipOptionList;
|
typedef std::list<GossipOption> GossipOptionList;
|
||||||
|
|
|
||||||
|
|
@ -160,9 +160,9 @@ void WorldSession::SendTrainerList( uint64 guid, const std::string& strTitle )
|
||||||
float fDiscountMod = _player->GetReputationPriceDiscount(unit);
|
float fDiscountMod = _player->GetReputationPriceDiscount(unit);
|
||||||
|
|
||||||
uint32 count = 0;
|
uint32 count = 0;
|
||||||
for(TrainerSpellList::const_iterator itr = trainer_spells->spellList.begin(); itr != trainer_spells->spellList.end(); ++itr)
|
for(TrainerSpellMap::const_iterator itr = trainer_spells->spellList.begin(); itr != trainer_spells->spellList.end(); ++itr)
|
||||||
{
|
{
|
||||||
TrainerSpell const* tSpell = *itr;
|
TrainerSpell const* tSpell = &itr->second;
|
||||||
|
|
||||||
if(!_player->IsSpellFitByClassAndRace(tSpell->learnedSpell))
|
if(!_player->IsSpellFitByClassAndRace(tSpell->learnedSpell))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -6870,36 +6870,34 @@ void ObjectMgr::LoadTrainerSpell()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
TrainerSpell* pTrainerSpell = new TrainerSpell();
|
|
||||||
pTrainerSpell->spell = spell;
|
|
||||||
pTrainerSpell->spellCost = fields[2].GetUInt32();
|
|
||||||
pTrainerSpell->reqSkill = fields[3].GetUInt32();
|
|
||||||
pTrainerSpell->reqSkillValue = fields[4].GetUInt32();
|
|
||||||
pTrainerSpell->reqLevel = fields[5].GetUInt32();
|
|
||||||
|
|
||||||
if(!pTrainerSpell->reqLevel)
|
|
||||||
pTrainerSpell->reqLevel = spellinfo->spellLevel;
|
|
||||||
|
|
||||||
// calculate learned spell for profession case when stored cast-spell
|
|
||||||
pTrainerSpell->learnedSpell = spell;
|
|
||||||
for(int i = 0; i <3; ++i)
|
|
||||||
{
|
|
||||||
if(spellinfo->Effect[i]!=SPELL_EFFECT_LEARN_SPELL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if(SpellMgr::IsProfessionOrRidingSpell(spellinfo->EffectTriggerSpell[i]))
|
|
||||||
{
|
|
||||||
pTrainerSpell->learnedSpell = spellinfo->EffectTriggerSpell[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TrainerSpellData& data = m_mCacheTrainerSpellMap[entry];
|
TrainerSpellData& data = m_mCacheTrainerSpellMap[entry];
|
||||||
|
|
||||||
if(SpellMgr::IsProfessionSpell(spell))
|
if(SpellMgr::IsProfessionSpell(spell))
|
||||||
data.trainerType = 2;
|
data.trainerType = 2;
|
||||||
|
|
||||||
data.spellList.push_back(pTrainerSpell);
|
TrainerSpell& trainerSpell = data.spellList[spell];
|
||||||
|
trainerSpell.spell = spell;
|
||||||
|
trainerSpell.spellCost = fields[2].GetUInt32();
|
||||||
|
trainerSpell.reqSkill = fields[3].GetUInt32();
|
||||||
|
trainerSpell.reqSkillValue = fields[4].GetUInt32();
|
||||||
|
trainerSpell.reqLevel = fields[5].GetUInt32();
|
||||||
|
|
||||||
|
if(!trainerSpell.reqLevel)
|
||||||
|
trainerSpell.reqLevel = spellinfo->spellLevel;
|
||||||
|
|
||||||
|
// calculate learned spell for profession case when stored cast-spell
|
||||||
|
trainerSpell.learnedSpell = spell;
|
||||||
|
for(int i = 0; i <3; ++i)
|
||||||
|
{
|
||||||
|
if(spellinfo->Effect[i] != SPELL_EFFECT_LEARN_SPELL)
|
||||||
|
continue;
|
||||||
|
if(SpellMgr::IsProfessionOrRidingSpell(spellinfo->EffectTriggerSpell[i]))
|
||||||
|
{
|
||||||
|
trainerSpell.learnedSpell = spellinfo->EffectTriggerSpell[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
++count;
|
++count;
|
||||||
|
|
||||||
} while (result->NextRow());
|
} while (result->NextRow());
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "7282"
|
#define REVISION_NR "7283"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue