aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleak <leakzx@googlemail.com>2011-04-28 22:50:06 +0200
committerleak <leakzx@googlemail.com>2011-04-28 22:50:06 +0200
commit3ab83417f5d6e18cf055195aa35beefdc4f98b9b (patch)
treebfbdb1f744f4938f9d3222088c5389bcb250e221
parentc8413a7f27cdb0de2f93d2437decdbc1628cb69e (diff)
Core/ObjectMgr: Refactor sCreatureInfoAddonStorage
-rw-r--r--sql/updates/world/2011_04_28_03_world_creature_template_addon.sql51
-rwxr-xr-xsrc/server/game/Entities/Creature/Creature.cpp2
-rwxr-xr-xsrc/server/game/Globals/ObjectMgr.cpp80
-rwxr-xr-xsrc/server/game/Globals/ObjectMgr.h10
-rwxr-xr-xsrc/server/game/World/World.cpp3
-rwxr-xr-xsrc/server/shared/Database/SQLStorage.cpp2
6 files changed, 138 insertions, 10 deletions
diff --git a/sql/updates/world/2011_04_28_03_world_creature_template_addon.sql b/sql/updates/world/2011_04_28_03_world_creature_template_addon.sql
new file mode 100644
index 00000000000..ee5cb61ccdc
--- /dev/null
+++ b/sql/updates/world/2011_04_28_03_world_creature_template_addon.sql
@@ -0,0 +1,51 @@
+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
+DETERMINISTIC
+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;
+
+DROP FUNCTION `ConvertAuras`;
+DROP TABLE `temp_auras`; \ No newline at end of file
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 ()