From fd2eb3cfee8d2526f70a19da11a96b71dbb29871 Mon Sep 17 00:00:00 2001 From: nos4r2zod Date: Sun, 26 Jul 2009 05:45:33 +0400 Subject: [PATCH] [8250] Cleanup code and data for `spell_threat` * Load table data to std::map instead SQLStorage and add check loaded spell existance. * Drop from table not existed spells. Signed-off-by: VladimirMangos --- sql/mangos.sql | 15 +------ sql/updates/8250_01_mangos_spell_threat.sql | 3 ++ sql/updates/Makefile.am | 2 + src/game/DBCStructure.h | 7 ---- src/game/Spell.cpp | 9 +++-- src/game/SpellMgr.cpp | 44 +++++++++++++++++++-- src/game/SpellMgr.h | 13 +++++- src/shared/Database/SQLStorage.cpp | 2 - src/shared/revision_nr.h | 2 +- 9 files changed, 64 insertions(+), 33 deletions(-) create mode 100644 sql/updates/8250_01_mangos_spell_threat.sql diff --git a/sql/mangos.sql b/sql/mangos.sql index ea9b2ab1e..67d7d1cbb 100644 --- a/sql/mangos.sql +++ b/sql/mangos.sql @@ -23,7 +23,7 @@ DROP TABLE IF EXISTS `db_version`; CREATE TABLE `db_version` ( `version` varchar(120) default NULL, `creature_ai_version` varchar(120) default NULL, - `required_8249_02_mangos_spell_chain` bit(1) default NULL + `required_8250_01_mangos_spell_threat` bit(1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes'; -- @@ -18099,7 +18099,6 @@ INSERT INTO `spell_threat` VALUES (284,39), (285,59), (770,108), -(778,108), (1608,78), (1672,180), (1715,61), @@ -18119,10 +18118,8 @@ INSERT INTO `spell_threat` VALUES (8380,180), (8972,118), (9745,148), -(9749,108), (9880,178), (9881,207), -(9907,108), (11556,43), (11564,98), (11565,118), @@ -18135,20 +18132,12 @@ INSERT INTO `spell_threat` VALUES (11600,275), (11601,315), (11775,395), -(14274,200), (14921,415), -(15629,300), -(15630,400), -(15631,500), -(15632,600), (16857,108), (17735,200), (17750,300), (17751,450), (17752,600), -(17390,108), -(17391,108), -(17392,108), (20569,100), (20736,100), (20925,20), @@ -18168,9 +18157,7 @@ INSERT INTO `spell_threat` VALUES (25286,175), (25288,355), (25289,60), -(26993,127), (26996,176), -(27011,127), (27179,54), (29704,230), (29707,196), diff --git a/sql/updates/8250_01_mangos_spell_threat.sql b/sql/updates/8250_01_mangos_spell_threat.sql new file mode 100644 index 000000000..6bc81761c --- /dev/null +++ b/sql/updates/8250_01_mangos_spell_threat.sql @@ -0,0 +1,3 @@ +ALTER TABLE db_version CHANGE COLUMN required_8249_02_mangos_spell_chain required_8250_01_mangos_spell_threat bit; + +DELETE FROM `spell_threat` WHERE `entry` IN (778,9749,9907,14274,15629,15630,15631,15632,17390,17391,17392,26993,27011); \ No newline at end of file diff --git a/sql/updates/Makefile.am b/sql/updates/Makefile.am index 5081f2f0b..c7898fb10 100644 --- a/sql/updates/Makefile.am +++ b/sql/updates/Makefile.am @@ -254,6 +254,7 @@ pkgdata_DATA = \ 8247_01_mangos_spell_bonus_data.sql \ 8249_01_mangos_spell_proc_item_enchant.sql \ 8249_02_mangos_spell_chain.sql \ + 8250_01_mangos_spell_threat.sql \ README ## Additional files to include when running 'make dist' @@ -488,4 +489,5 @@ EXTRA_DIST = \ 8247_01_mangos_spell_bonus_data.sql \ 8249_01_mangos_spell_proc_item_enchant.sql \ 8249_02_mangos_spell_chain.sql \ + 8250_01_mangos_spell_threat.sql \ README diff --git a/src/game/DBCStructure.h b/src/game/DBCStructure.h index 6b2407911..9ffdb539d 100644 --- a/src/game/DBCStructure.h +++ b/src/game/DBCStructure.h @@ -1426,13 +1426,6 @@ struct SpellFocusObjectEntry // 16 string flags, unused }; -// stored in SQL table -struct SpellThreatEntry -{ - uint32 spellId; - int32 threat; -}; - struct SpellRadiusEntry { uint32 ID; diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index 952662bd2..b8c0f803b 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -3566,13 +3566,14 @@ void Spell::HandleThreatSpells(uint32 spellId) if(!m_targets.getUnitTarget()->CanHaveThreatList()) return; - SpellThreatEntry const *threatSpell = sSpellThreatStore.LookupEntry(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, float DamageMultiplier) diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp index 3ef401901..b9a97109e 100644 --- a/src/game/SpellMgr.cpp +++ b/src/game/SpellMgr.cpp @@ -989,12 +989,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 diff --git a/src/game/SpellMgr.h b/src/game/SpellMgr.h index bd76dcd9d..2d865159b 100644 --- a/src/game/SpellMgr.h +++ b/src/game/SpellMgr.h @@ -36,8 +36,6 @@ class Player; class Spell; struct SpellModifier; -extern SQLStorage sSpellThreatStore; - // only used in code enum SpellCategories { @@ -450,6 +448,7 @@ typedef UNORDERED_MAP SpellBonusMap; typedef std::map SpellElixirMap; typedef std::map SpellProcItemEnchantMap; +typedef std::map SpellThreatMap; // Spell script target related declarations (accessed using SpellMgr functions) enum SpellTargetType @@ -663,6 +662,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 { @@ -927,6 +935,7 @@ class SpellMgr SpellLearnSpellMap mSpellLearnSpells; SpellTargetPositionMap mSpellTargetPositions; SpellElixirMap mSpellElixirs; + SpellThreatMap mSpellThreatMap; SpellProcEventMap mSpellProcEventMap; SpellProcItemEnchantMap mSpellProcItemEnchantMap; SpellBonusMap mSpellBonusMap; diff --git a/src/shared/Database/SQLStorage.cpp b/src/shared/Database/SQLStorage.cpp index 288b66539..e4f5f99ca 100644 --- a/src/shared/Database/SQLStorage.cpp +++ b/src/shared/Database/SQLStorage.cpp @@ -36,7 +36,6 @@ const char GameObjectInfodstfmt[]="iiissssiifiiiiiiiiiiiiiiiiiiiiiiiiiiiii"; const char ItemPrototypesrcfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiisiiii"; const char ItemPrototypedstfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiiiiiii"; const char PageTextfmt[]="isi"; -const char SpellThreatfmt[]="ii"; const char InstanceTemplatesrcfmt[]="iiiiiiiffffs"; const char InstanceTemplatedstfmt[]="iiiiiiiffffi"; @@ -48,7 +47,6 @@ SQLStorage sEquipmentStorage(EquipmentInfofmt,"entry","creature_equip_template") SQLStorage sGOStorage(GameObjectInfosrcfmt, GameObjectInfodstfmt, "entry","gameobject_template"); SQLStorage sItemStorage(ItemPrototypesrcfmt, ItemPrototypedstfmt, "entry","item_template"); SQLStorage sPageTextStore(PageTextfmt,"entry","page_text"); -SQLStorage sSpellThreatStore(SpellThreatfmt,"entry","spell_threat"); SQLStorage sInstanceTemplate(InstanceTemplatesrcfmt, InstanceTemplatedstfmt, "map","instance_template"); void SQLStorage::Free () diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index ba58a49ca..9f04ff169 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "8249" + #define REVISION_NR "8250" #endif // __REVISION_NR_H__