[8250] Cleanup code and data for spell_threat Author: nos4r2zod

* Load table data to std::map instead SQLStorage and add check loaded spell existance.
    * Drop from table not existed spells.

--HG--
branch : trunk
This commit is contained in:
megamage
2009-07-30 11:37:08 +08:00
parent 7121d98480
commit af2d5e3fd4
7 changed files with 61 additions and 32 deletions
-7
View File
@@ -1463,13 +1463,6 @@ struct SpellFocusObjectEntry
// 16 string flags, unused
};
// stored in SQL table
struct SpellThreatEntry
{
uint32 spellId;
int32 threat;
};
struct SpellRadiusEntry
{
uint32 ID;
+5 -4
View File
@@ -4200,13 +4200,14 @@ void Spell::HandleThreatSpells(uint32 spellId)
if(!m_targets.getUnitTarget()->CanHaveThreatList())
return;
SpellThreatEntry const *threatSpell = sSpellThreatStore.LookupEntry<SpellThreatEntry>(spellId);
if(!threatSpell)
uint16 threat = spellmgr.GetSpellThreat(spellId);
if(!threat)
return;
m_targets.getUnitTarget()->AddThreat(m_caster, float(threatSpell->threat));
m_targets.getUnitTarget()->AddThreat(m_caster, float(threat));
DEBUG_LOG("Spell %u, rank %u, added an additional %i threat", spellId, spellmgr.GetSpellRank(spellId), threatSpell->threat);
DEBUG_LOG("Spell %u, rank %u, added an additional %i threat", spellId, spellmgr.GetSpellRank(spellId), threat);
}
void Spell::HandleEffects(Unit *pUnitTarget,Item *pItemTarget,GameObject *pGOTarget,uint32 i)
+41 -3
View File
@@ -1505,12 +1505,50 @@ void SpellMgr::LoadSpellElixirs()
void SpellMgr::LoadSpellThreats()
{
sSpellThreatStore.Free(); // for reload
mSpellThreatMap.clear(); // need for reload case
sSpellThreatStore.Load();
uint32 count = 0;
// 0 1
QueryResult *result = WorldDatabase.Query("SELECT entry, Threat FROM spell_threat");
if( !result )
{
barGoLink bar( 1 );
bar.step();
sLog.outString();
sLog.outString( ">> Loaded %u aggro generating spells", count );
return;
}
barGoLink bar( result->GetRowCount() );
do
{
Field *fields = result->Fetch();
bar.step();
uint32 entry = fields[0].GetUInt32();
uint16 Threat = fields[1].GetUInt16();
if (!sSpellStore.LookupEntry(entry))
{
sLog.outErrorDb("Spell %u listed in `spell_threat` does not exist", entry);
continue;
}
mSpellThreatMap[entry] = Threat;
++count;
} while( result->NextRow() );
delete result;
sLog.outString( ">> Loaded %u aggro generating spells", sSpellThreatStore.RecordCount );
sLog.outString();
sLog.outString( ">> Loaded %u aggro generating spells", count );
}
bool SpellMgr::IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const
+11 -2
View File
@@ -40,8 +40,6 @@ class Player;
class Spell;
struct SpellModifier;
extern SQLStorage sSpellThreatStore;
// only used in code
enum SpellCategories
{
@@ -527,6 +525,7 @@ typedef UNORDERED_MAP<uint32, SpellBonusEntry> SpellBonusMap;
typedef std::map<uint32, uint8> SpellElixirMap;
typedef std::map<uint32, float> SpellProcItemEnchantMap;
typedef std::map<uint32, uint16> SpellThreatMap;
// Spell script target related declarations (accessed using SpellMgr functions)
enum SpellScriptTargetType
@@ -764,6 +763,15 @@ class SpellMgr
return SPELL_NORMAL;
}
uint16 GetSpellThreat(uint32 spellid) const
{
SpellThreatMap::const_iterator itr = mSpellThreatMap.find(spellid);
if(itr==mSpellThreatMap.end())
return 0;
return itr->second;
}
// Spell proc events
SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const
{
@@ -1081,6 +1089,7 @@ class SpellMgr
SpellLearnSpellMap mSpellLearnSpells;
SpellTargetPositionMap mSpellTargetPositions;
SpellElixirMap mSpellElixirs;
SpellThreatMap mSpellThreatMap;
SpellProcEventMap mSpellProcEventMap;
SpellProcItemEnchantMap mSpellProcItemEnchantMap;
SpellBonusMap mSpellBonusMap;