From 02c1bc6557d03c9dfc3dbe9912fa82b3963319e6 Mon Sep 17 00:00:00 2001 From: zergtmn Date: Sat, 5 Mar 2011 01:50:09 +0500 Subject: [PATCH] [11217] Drop effect indexes from *_addon.auras field --- sql/mangos.sql | 2 +- .../11217_01_mangos_creature_addon.sql | 56 +++++++++++++++++++ src/game/Creature.cpp | 33 +++++------ src/game/Creature.h | 3 +- src/game/ObjectMgr.cpp | 32 +++-------- src/shared/revision_nr.h | 2 +- src/shared/revision_sql.h | 2 +- 7 files changed, 83 insertions(+), 47 deletions(-) create mode 100644 sql/updates/11217_01_mangos_creature_addon.sql diff --git a/sql/mangos.sql b/sql/mangos.sql index 500a95829..9fabe0570 100644 --- a/sql/mangos.sql +++ b/sql/mangos.sql @@ -24,7 +24,7 @@ CREATE TABLE `db_version` ( `version` varchar(120) default NULL, `creature_ai_version` varchar(120) default NULL, `cache_id` int(10) default '0', - `required_11214_02_mangos_command` bit(1) default NULL + `required_11217_01_mangos_creature_addon` bit(1) default NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Used DB version notes'; -- diff --git a/sql/updates/11217_01_mangos_creature_addon.sql b/sql/updates/11217_01_mangos_creature_addon.sql new file mode 100644 index 000000000..cf00588cb --- /dev/null +++ b/sql/updates/11217_01_mangos_creature_addon.sql @@ -0,0 +1,56 @@ +ALTER TABLE db_version CHANGE COLUMN required_11214_02_mangos_command required_11217_01_mangos_creature_addon bit; + +CREATE TABLE `temp_auras` ( + `spell` mediumint(8) unsigned NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +DELIMITER %% + +CREATE FUNCTION `ConvertAuras`(`auras` varchar(1024)) +RETURNS varchar(1024) CHARSET utf8 +BEGIN + DECLARE tmp VARCHAR(1024); + DECLARE curr VARCHAR(10); + DECLARE k INT; + DECLARE pos INT; + DECLARE startp INT; + + SET @k = 0; + SET @tmp = ''; + SET @startp = 1; + SET @pos = LOCATE(' ', auras); + + DELETE FROM temp_auras; + + WHILE @pos > 0 DO + IF @k = 0 THEN + SET @curr = SUBSTR(auras, @startp, @pos - @startp); + + IF NOT EXISTS(SELECT spell FROM temp_auras WHERE spell = @curr) THEN + SET @tmp = CONCAT(@tmp, @curr, ' '); + INSERT INTO temp_auras VALUES(@curr); + END IF; + END IF; + + SET @k = 1-@k; + SET @startp = @pos+1; + SET @pos = LOCATE(' ', auras, @startp); + END WHILE; + + SET @tmp = RTRIM(@tmp); + RETURN @tmp; +END%% + +DELIMITER ; + +UPDATE `creature_template_addon` SET `auras` = REPLACE(`auras`, ' ', ' '); +UPDATE `creature_template_addon` SET `auras` = TRIM(`auras`); +UPDATE `creature_template_addon` SET `auras` = NULL WHERE `auras` = ''; +UPDATE `creature_template_addon` SET `auras` = ConvertAuras(`auras`) WHERE `auras` IS NOT NULL; +UPDATE `creature_addon` SET `auras` = REPLACE(`auras`, ' ', ' '); +UPDATE `creature_addon` SET `auras` = TRIM(`auras`); +UPDATE `creature_addon` SET `auras` = NULL WHERE `auras` = ''; +UPDATE `creature_addon` SET `auras` = ConvertAuras(`auras`) WHERE `auras` IS NOT NULL; + +DROP FUNCTION `ConvertAuras`; +DROP TABLE `temp_auras`; diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 138bfda42..7f7419137 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -1908,36 +1908,31 @@ bool Creature::LoadCreatureAddon(bool reload) } // skip already applied aura - if(HasAura(cAura->spell_id,cAura->effect_idx)) + if (HasAura(cAura->spell_id)) { if(!reload) - sLog.outErrorDb("Creature (GUIDLow: %u Entry: %u ) has duplicate aura (spell %u effect %u) in `auras` field.",GetGUIDLow(),GetEntry(),cAura->spell_id,cAura->effect_idx); + sLog.outErrorDb("Creature (GUIDLow: %u Entry: %u) has duplicate spell %u in `auras` field.", GetGUIDLow(), GetEntry(), cAura->spell_id); continue; } - SpellAuraHolder *holder = GetSpellAuraHolder(cAura->spell_id, GetGUID()); + SpellAuraHolder *holder = CreateSpellAuraHolder(AdditionalSpellInfo, this, this); - bool addedToExisting = true; - if (!holder) + for(uint32 eff = 0; eff < MAX_EFFECT_INDEX; ++eff) { - holder = CreateSpellAuraHolder(AdditionalSpellInfo, this, this); - addedToExisting = false; - } - Aura* AdditionalAura = CreateAura(AdditionalSpellInfo, cAura->effect_idx, NULL, holder, this, this, 0); - holder->AddAura(AdditionalAura, cAura->effect_idx); + if (IsSpellAppliesAura(AdditionalSpellInfo, 1 << eff)) + { + Aura* AdditionalAura = CreateAura(AdditionalSpellInfo, SpellEffectIndex(eff), NULL, holder, this, this); + holder->AddAura(AdditionalAura, SpellEffectIndex(eff)); - if (addedToExisting) - { - AddAuraToModList(AdditionalAura); - holder->SetInUse(true); - AdditionalAura->ApplyModifier(true,true); - holder->SetInUse(false); + DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Spell: %u - Aura %u added to creature (GUIDLow: %u Entry: %u)", cAura->spell_id, AdditionalSpellInfo->EffectApplyAuraName[eff], GetGUIDLow(), GetEntry()); + } } - else + + if (!holder->IsEmptyHolder()) AddSpellAuraHolder(holder); - - DEBUG_FILTER_LOG(LOG_FILTER_SPELL_CAST, "Spell: %u - Aura %u added to creature (GUIDLow: %u Entry: %u )", cAura->spell_id, AdditionalSpellInfo->EffectApplyAuraName[EFFECT_INDEX_0],GetGUIDLow(),GetEntry()); + else + delete holder; } } return true; diff --git a/src/game/Creature.h b/src/game/Creature.h index de24aa183..34e404e42 100644 --- a/src/game/Creature.h +++ b/src/game/Creature.h @@ -198,7 +198,6 @@ struct CreatureData struct CreatureDataAddonAura { uint32 spell_id; - SpellEffectIndex effect_idx; }; // from `creature_addon` and `creature_template_addon`tables @@ -211,7 +210,7 @@ struct CreatureDataAddon uint8 pvp_state; // UnitPVPStateFlags uint32 emote; uint32 splineFlags; - CreatureDataAddonAura const* auras; // loaded as char* "spell1 eff1 spell2 eff2 ... " + CreatureDataAddonAura const* auras; // loaded as char* "spell1 spell2 ... " }; struct CreatureModelInfo diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index 33138a2b4..2cb66d746 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -753,7 +753,7 @@ void ObjectMgr::LoadCreatureTemplates() void ObjectMgr::ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr) { - // Now add the auras, format "spellid effectindex spellid effectindex..." + // Now add the auras, format "spell1 spell2 ..." char *p,*s; std::vector val; s=p=(char*)reinterpret_cast(addon->auras); @@ -773,14 +773,6 @@ void ObjectMgr::ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* // free char* loaded memory delete[] (char*)reinterpret_cast(addon->auras); - - // wrong list - if (val.size()%2) - { - addon->auras = NULL; - sLog.outErrorDb("Creature (%s: %u) has wrong `auras` data in `%s`.",guidEntryStr,addon->guidOrEntry,table); - return; - } } // empty list @@ -791,19 +783,14 @@ void ObjectMgr::ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* } // replace by new structures array - const_cast(addon->auras) = new CreatureDataAddonAura[val.size()/2+1]; + const_cast(addon->auras) = new CreatureDataAddonAura[val.size()+1]; - uint32 i=0; - for(uint32 j = 0; j < val.size()/2; ++j) + uint32 i = 0; + for(uint32 j = 0; j < val.size(); ++j) { CreatureDataAddonAura& cAura = const_cast(addon->auras[i]); - cAura.spell_id = uint32(val[2*j+0]); - cAura.effect_idx = SpellEffectIndex(val[2*j+1]); - if (cAura.effect_idx >= MAX_EFFECT_INDEX) - { - sLog.outErrorDb("Creature (%s: %u) has wrong effect %u for spell %u in `auras` field in `%s`.",guidEntryStr,addon->guidOrEntry,cAura.effect_idx,cAura.spell_id,table); - continue; - } + cAura.spell_id = uint32(val[j]); + SpellEntry const *AdditionalSpellInfo = sSpellStore.LookupEntry(cAura.spell_id); if (!AdditionalSpellInfo) { @@ -811,9 +798,9 @@ void ObjectMgr::ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* continue; } - if (!AdditionalSpellInfo->Effect[cAura.effect_idx] || !AdditionalSpellInfo->EffectApplyAuraName[cAura.effect_idx]) + if (!IsSpellAppliesAura(AdditionalSpellInfo)) { - sLog.outErrorDb("Creature (%s: %u) has not aura effect %u of spell %u defined in `auras` field in `%s`.",guidEntryStr,addon->guidOrEntry,cAura.effect_idx,cAura.spell_id,table); + sLog.outErrorDb("Creature (%s: %u) has spell %u defined in `auras` field in `%s` but spell doesn't apply any auras.", guidEntryStr, addon->guidOrEntry, cAura.spell_id, table); continue; } @@ -822,8 +809,7 @@ void ObjectMgr::ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* // fill terminator element (after last added) CreatureDataAddonAura& endAura = const_cast(addon->auras[i]); - endAura.spell_id = 0; - endAura.effect_idx = EFFECT_INDEX_0; + endAura.spell_id = 0; } void ObjectMgr::LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment) diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index c257772f9..ec84b52c8 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 "11216" + #define REVISION_NR "11217" #endif // __REVISION_NR_H__ diff --git a/src/shared/revision_sql.h b/src/shared/revision_sql.h index 31a7c6696..0ebaf91e7 100644 --- a/src/shared/revision_sql.h +++ b/src/shared/revision_sql.h @@ -1,6 +1,6 @@ #ifndef __REVISION_SQL_H__ #define __REVISION_SQL_H__ #define REVISION_DB_CHARACTERS "required_11117_02_characters_world" - #define REVISION_DB_MANGOS "required_11214_02_mangos_command" + #define REVISION_DB_MANGOS "required_11217_01_mangos_creature_addon" #define REVISION_DB_REALMD "required_10008_01_realmd_realmd_db_version" #endif // __REVISION_SQL_H__