Core/ObjectMgr: Refactor sCreatureInfoAddonStorage
This commit is contained in:
@@ -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`;
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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 ()
|
||||
|
||||
Reference in New Issue
Block a user