From c8413a7f27cdb0de2f93d2437decdbc1628cb69e Mon Sep 17 00:00:00 2001 From: leak Date: Thu, 28 Apr 2011 22:46:40 +0200 Subject: Core/ObjectMgr: Refactor sCreatureDataAddonStorage --- src/server/game/Entities/Creature/Creature.cpp | 22 +++++++++++----------- src/server/game/Entities/Creature/Creature.h | 16 ++++++---------- 2 files changed, 17 insertions(+), 21 deletions(-) (limited to 'src/server/game/Entities') diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index a8ed317f7d5..f8e0c6224ce 100755 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -2025,11 +2025,11 @@ bool Creature::canCreatureAttack(Unit const *pVictim, bool force) const return pVictim->IsInDist(&m_homePosition, dist); } -CreatureDataAddon const* Creature::GetCreatureAddon() const +CreatureAddon const* Creature::GetCreatureAddon() const { if (m_DBTableGuid) { - if (CreatureDataAddon const* addon = ObjectMgr::GetCreatureAddon(m_DBTableGuid)) + if (CreatureAddon const* addon = sObjectMgr->GetCreatureAddon(m_DBTableGuid)) return addon; } @@ -2040,7 +2040,7 @@ CreatureDataAddon const* Creature::GetCreatureAddon() const //creature_addon table bool Creature::LoadCreaturesAddon(bool reload) { - CreatureDataAddon const *cainfo = GetCreatureAddon(); + CreatureAddon const *cainfo = GetCreatureAddon(); if (!cainfo) return false; @@ -2083,28 +2083,28 @@ bool Creature::LoadCreaturesAddon(bool reload) if (cainfo->path_id != 0) m_path_id = cainfo->path_id; - if (cainfo->auras) + if (!cainfo->auras.empty()) { - for (CreatureDataAddonAura const* cAura = cainfo->auras; cAura->spell_id; ++cAura) + for (std::vector::const_iterator itr = cainfo->auras.begin(); itr != cainfo->auras.end(); ++itr) { - SpellEntry const *AdditionalSpellInfo = sSpellStore.LookupEntry(cAura->spell_id); + SpellEntry const *AdditionalSpellInfo = sSpellStore.LookupEntry(*itr); if (!AdditionalSpellInfo) { - sLog->outErrorDb("Creature (GUID: %u Entry: %u) has wrong spell %u defined in `auras` field.",GetGUIDLow(),GetEntry(),cAura->spell_id); + sLog->outErrorDb("Creature (GUID: %u Entry: %u) has wrong spell %u defined in `auras` field.", GetGUIDLow(), GetEntry(), *itr); continue; } // skip already applied aura - if (HasAura(cAura->spell_id)) + if (HasAura(*itr)) { if (!reload) - sLog->outErrorDb("Creature (GUID: %u Entry: %u) has duplicate aura (spell %u) in `auras` field.",GetGUIDLow(),GetEntry(),cAura->spell_id); + sLog->outErrorDb("Creature (GUID: %u Entry: %u) has duplicate aura (spell %u) in `auras` field.", GetGUIDLow(), GetEntry(), *itr); continue; } - AddAura(AdditionalSpellInfo, cAura->effectMask, this); - sLog->outDebug(LOG_FILTER_UNITS, "Spell: %u with AuraEffectMask %u added to creature (GUID: %u Entry: %u)", cAura->spell_id, cAura->effectMask,GetGUIDLow(),GetEntry()); + AddAura(*itr, this); + sLog->outDebug(LOG_FILTER_UNITS, "Spell: %u added to creature (GUID: %u Entry: %u)", *itr, GetGUIDLow(), GetEntry()); } } return true; diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 9dc3b00791a..d3f26590f07 100755 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -263,14 +263,8 @@ struct CreatureData bool dbData; }; -struct CreatureDataAddonAura -{ - uint32 spell_id; - uint8 effectMask; -}; - -// from `creature_addon` table -struct CreatureDataAddon +// `creature_addon` table +struct CreatureAddon { uint32 guidOrEntry; uint32 path_id; @@ -278,9 +272,11 @@ struct CreatureDataAddon uint32 bytes1; uint32 bytes2; uint32 emote; - CreatureDataAddonAura const* auras; // loaded as char* "spell1 eff1 spell2 eff2 ... " + std::vector auras; }; +typedef UNORDERED_MAP CreatureAddonContainer; + struct CreatureModelInfo { float bounding_radius; @@ -533,7 +529,7 @@ class Creature : public Unit, public GridObject CreatureInfo const *GetCreatureInfo() const { return m_creatureInfo; } CreatureData const *GetCreatureData() const { return m_creatureData; } - CreatureDataAddon const* GetCreatureAddon() const; + CreatureAddon const* GetCreatureAddon() const; std::string GetAIName() const; std::string GetScriptName() const; -- cgit v1.2.3