diff options
author | leak <leakzx@googlemail.com> | 2011-04-28 22:50:06 +0200 |
---|---|---|
committer | leak <leakzx@googlemail.com> | 2011-04-28 22:50:06 +0200 |
commit | 3ab83417f5d6e18cf055195aa35beefdc4f98b9b (patch) | |
tree | bfbdb1f744f4938f9d3222088c5389bcb250e221 /src | |
parent | c8413a7f27cdb0de2f93d2437decdbc1628cb69e (diff) |
Core/ObjectMgr: Refactor sCreatureInfoAddonStorage
Diffstat (limited to 'src')
-rwxr-xr-x | src/server/game/Entities/Creature/Creature.cpp | 2 | ||||
-rwxr-xr-x | src/server/game/Globals/ObjectMgr.cpp | 80 | ||||
-rwxr-xr-x | src/server/game/Globals/ObjectMgr.h | 10 | ||||
-rwxr-xr-x | src/server/game/World/World.cpp | 3 | ||||
-rwxr-xr-x | src/server/shared/Database/SQLStorage.cpp | 2 |
5 files changed, 87 insertions, 10 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index f8e0c6224ce..8bd7be73fcf 100755 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -2034,7 +2034,7 @@ CreatureAddon const* Creature::GetCreatureAddon() const } // dependent from difficulty mode entry - return ObjectMgr::GetCreatureTemplateAddon(GetCreatureInfo()->Entry); + return sObjectMgr->GetCreatureTemplateAddon(GetCreatureInfo()->Entry); } //creature_addon table diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 8e5b784dc09..8c08078cc4f 100755 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -561,6 +561,77 @@ void ObjectMgr::LoadCreatureTemplates() sLog->outString(); } +void ObjectMgr::LoadCreatureTemplateAddons() +{ + uint32 oldMSTime = getMSTime(); + + // 0 1 2 3 4 5 6 + QueryResult result = WorldDatabase.Query("SELECT entry, path_id, mount, bytes1, bytes2, emote, auras FROM creature_template_addon"); + + if (!result) + { + sLog->outString(">> Loaded 0 creature template addon definitions. DB table `creature_addon` is empty."); + sLog->outString(); + return; + } + + uint32 count = 0; + do + { + Field *fields = result->Fetch(); + + uint32 entry = fields[0].GetUInt32(); + + if (!sCreatureStorage.LookupEntry<CreatureInfo>(entry)) + { + sLog->outErrorDb("Creature template (Entry: %u) does not exist but has a record in `creature_template_addon`", entry); + continue; + } + + CreatureAddon creatureAddon; + + creatureAddon.path_id = fields[1].GetUInt32(); + creatureAddon.mount = fields[2].GetUInt32(); + creatureAddon.bytes1 = fields[3].GetUInt32(); + creatureAddon.bytes2 = fields[4].GetUInt32(); + creatureAddon.emote = fields[5].GetUInt32(); + + Tokens tokens(fields[6].GetString(), ' '); + uint8 i = 0; + creatureAddon.auras.resize(tokens.size()); + for (Tokens::iterator itr = tokens.begin(); itr != tokens.end(); ++itr) + { + SpellEntry const *AdditionalSpellInfo = sSpellStore.LookupEntry(uint32(atol(*itr))); + if (!AdditionalSpellInfo) + { + sLog->outErrorDb("Creature (GUID: %u) has wrong spell %u defined in `auras` field in `creature_addon`.", entry, uint32(atol(*itr))); + continue; + } + creatureAddon.auras[i++] = uint32(atol(*itr)); + } + + if (creatureAddon.mount) + { + if (!sCreatureDisplayInfoStore.LookupEntry(creatureAddon.mount)) + { + sLog->outErrorDb("Creature (GUID: %u) has invalid displayInfoId (%u) for mount defined in `creature_addon`", entry, creatureAddon.mount); + creatureAddon.mount = 0; + } + } + + if (!sEmotesStore.LookupEntry(creatureAddon.emote)) + sLog->outErrorDb("Creature (GUID: %u) has invalid emote (%u) defined in `creature_addon`.", entry, creatureAddon.emote); + + CreatureTemplateAddonStore[entry] = creatureAddon; + + ++count; + } + while (result->NextRow()); + + sLog->outString(">> Loaded %u creature template addons in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); + sLog->outString(); +} + void ObjectMgr::CheckCreatureTemplate(CreatureInfo const* cInfo) { if (!cInfo) @@ -940,6 +1011,15 @@ CreatureAddon const * ObjectMgr::GetCreatureAddon(uint32 lowguid) return NULL; } +CreatureAddon const * ObjectMgr::GetCreatureTemplateAddon(uint32 entry) +{ + CreatureAddonContainer::const_iterator itr = CreatureTemplateAddonStore.find(entry); + if (itr != CreatureTemplateAddonStore.end()) + return &(itr->second); + + return NULL; +} + EquipmentInfo const* ObjectMgr::GetEquipmentInfo(uint32 entry) { EquipmentInfoContainer::const_iterator itr = EquipmentInfoStore.find(entry); diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index e3d706f61dd..185a2f03b58 100755 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -45,7 +45,6 @@ #include <functional> extern SQLStorage sCreatureStorage; -extern SQLStorage sCreatureInfoAddonStorage; extern SQLStorage sGOStorage; class Group; @@ -679,12 +678,7 @@ class ObjectMgr static void ChooseCreatureFlags(const CreatureInfo *cinfo, uint32& npcflag, uint32& unit_flags, uint32& dynamicflags, const CreatureData *data = NULL); EquipmentInfo const *GetEquipmentInfo(uint32 entry); CreatureAddon const *GetCreatureAddon(uint32 lowguid); - - static CreatureAddon const *GetCreatureTemplateAddon(uint32 entry) - { - return sCreatureInfoAddonStorage.LookupEntry<CreatureAddon>(entry); - } - + CreatureAddon const *GetCreatureTemplateAddon(uint32 entry); ItemTemplate const* GetItemTemplate(uint32 entry); ItemTemplateContainer const* GetItemTemplateStore() { return &ItemTemplateStore; } @@ -923,6 +917,7 @@ class ObjectMgr void LoadCreatureClassLevelStats(); void LoadCreatureLocales(); void LoadCreatureTemplates(); + void LoadCreatureTemplateAddons(); void CheckCreatureTemplate(CreatureInfo const* cInfo); void LoadCreatures(); void LoadLinkedRespawn(); @@ -1404,6 +1399,7 @@ class ObjectMgr CreatureDataMap mCreatureDataMap; CreatureModelContainer CreatureModelStore; CreatureAddonContainer CreatureAddonStore; + CreatureAddonContainer CreatureTemplateAddonStore; EquipmentInfoContainer EquipmentInfoStore; LinkedRespawnMap mLinkedRespawnMap; CreatureLocaleMap mCreatureLocaleMap; diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 7ceaa5e0065..e0097b8627a 100755 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -1340,6 +1340,9 @@ void World::SetInitialWorldSettings() sLog->outString("Loading Creature templates..."); sObjectMgr->LoadCreatureTemplates(); + sLog->outString("Loading Creature template addons..."); + sObjectMgr->LoadCreatureTemplateAddons(); + sLog->outString("Loading Vehicle scaling information..."); sObjectMgr->LoadVehicleScaling(); diff --git a/src/server/shared/Database/SQLStorage.cpp b/src/server/shared/Database/SQLStorage.cpp index 439b1c5892c..019cfffea44 100755 --- a/src/server/shared/Database/SQLStorage.cpp +++ b/src/server/shared/Database/SQLStorage.cpp @@ -21,12 +21,10 @@ const char CreatureInfosrcfmt[]="iiiiiiiiiisssiiiiiiifffiffiifiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiiisiifffliiiiiiiliiisi"; const char CreatureInfodstfmt[]="iiiiiiiiiisssibbiiiifffiffiifiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiiisiifffliiiiiiiliiiii"; -const char CreatureInfoAddonInfofmt[]="iiiiiis"; const char GameObjectInfosrcfmt[]="iiissssiifiiiiiiiiiiiiiiiiiiiiiiiiiiiiiissi"; const char GameObjectInfodstfmt[]="iiissssiifiiiiiiiiiiiiiiiiiiiiiiiiiiiiiisii"; SQLStorage sCreatureStorage(CreatureInfosrcfmt, CreatureInfodstfmt, "entry","creature_template"); -SQLStorage sCreatureInfoAddonStorage(CreatureInfoAddonInfofmt,"entry","creature_template_addon"); SQLStorage sGOStorage(GameObjectInfosrcfmt, GameObjectInfodstfmt, "entry","gameobject_template"); void SQLStorage::Free () |