Core/ObjectMgr: Refactor sEquipmentStorage
This commit is contained in:
@@ -1416,9 +1416,9 @@ DROP TABLE IF EXISTS `creature_equip_template`;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `creature_equip_template` (
|
||||
`entry` mediumint(8) unsigned NOT NULL DEFAULT '0' COMMENT 'Unique entry',
|
||||
`equipentry1` mediumint(8) unsigned NOT NULL DEFAULT '0',
|
||||
`equipentry2` mediumint(8) unsigned NOT NULL DEFAULT '0',
|
||||
`equipentry3` mediumint(8) unsigned NOT NULL DEFAULT '0',
|
||||
`itemEntry1` mediumint(8) unsigned NOT NULL DEFAULT '0',
|
||||
`itemEntry2` mediumint(8) unsigned NOT NULL DEFAULT '0',
|
||||
`itemEntry3` mediumint(8) unsigned NOT NULL DEFAULT '0',
|
||||
PRIMARY KEY (`entry`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Creature System (Equipment)';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
ALTER TABLE `creature_equip_template`
|
||||
CHANGE `entry` `entry` SMALLINT(5) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
CHANGE `equipentry1` `itemEntry1` MEDIUMINT(8) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
CHANGE `equipentry2` `itemEntry2` MEDIUMINT(8) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
CHANGE `equipentry3` `itemEntry3` MEDIUMINT(8) UNSIGNED DEFAULT '0' NOT NULL,
|
||||
ADD COLUMN `newEntry` INT UNSIGNED AUTO_INCREMENT,
|
||||
ADD INDEX(newEntry),
|
||||
DROP PRIMARY KEY;
|
||||
|
||||
UPDATE `creature_template` ct, `creature_equip_template` cet
|
||||
SET ct.`equipment_id` = cet.`newEntry`
|
||||
WHERE ct.`equipment_id` = cet.`entry`;
|
||||
|
||||
UPDATE `game_event_model_equip` geme, `creature_equip_template` cet
|
||||
SET geme.`equipment_id` = cet.`newEntry`
|
||||
WHERE geme.`equipment_id` = cet.`entry`;
|
||||
|
||||
UPDATE `creature` c, `creature_equip_template` cet
|
||||
SET c.`equipment_id` = cet.`newEntry`
|
||||
WHERE c.`equipment_id` = cet.`entry`;
|
||||
|
||||
UPDATE `creature_equip_template` SET `entry` = `newEntry`;
|
||||
|
||||
ALTER TABLE `creature_equip_template`
|
||||
ADD PRIMARY KEY(`entry`),
|
||||
DROP COLUMN `newEntry`;
|
||||
@@ -1323,9 +1323,9 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
|
||||
return;
|
||||
}
|
||||
npc->SetCurrentEquipmentId(e.action.equip.entry);
|
||||
slot[0] = einfo->equipentry[0];
|
||||
slot[1] = einfo->equipentry[1];
|
||||
slot[2] = einfo->equipentry[2];
|
||||
slot[0] = einfo->ItemEntry[0];
|
||||
slot[1] = einfo->ItemEntry[1];
|
||||
slot[2] = einfo->ItemEntry[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1354,7 +1354,7 @@ void Creature::LoadEquipment(uint32 equip_entry, bool force)
|
||||
|
||||
m_equipmentId = equip_entry;
|
||||
for (uint8 i = 0; i < 3; ++i)
|
||||
SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + i, einfo->equipentry[i]);
|
||||
SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + i, einfo->ItemEntry[i]);
|
||||
}
|
||||
|
||||
bool Creature::hasQuest(uint32 quest_id) const
|
||||
|
||||
@@ -230,10 +230,12 @@ struct PointOfInterestLocale
|
||||
|
||||
struct EquipmentInfo
|
||||
{
|
||||
uint32 entry;
|
||||
uint32 equipentry[3];
|
||||
uint32 ItemEntry[3];
|
||||
};
|
||||
|
||||
// Benchmarked: Faster than std::map (insert/find)
|
||||
typedef UNORDERED_MAP<uint16, EquipmentInfo> EquipmentInfoContainer;
|
||||
|
||||
// from `creature` table
|
||||
struct CreatureData
|
||||
{
|
||||
|
||||
@@ -1023,53 +1023,77 @@ void ObjectMgr::LoadCreatureAddons()
|
||||
|
||||
EquipmentInfo const* ObjectMgr::GetEquipmentInfo(uint32 entry)
|
||||
{
|
||||
return sEquipmentStorage.LookupEntry<EquipmentInfo>(entry);
|
||||
EquipmentInfoContainer::const_iterator itr = EquipmentInfoStore.find(entry);
|
||||
if (itr != EquipmentInfoStore.end())
|
||||
return &(itr->second);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadEquipmentTemplates()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
sEquipmentStorage.Load();
|
||||
QueryResult result = WorldDatabase.Query("SELECT entry, itemEntry1, itemEntry2, itemEntry3 FROM creature_equip_template");
|
||||
|
||||
for (uint32 i = 0; i < sEquipmentStorage.MaxEntry; ++i)
|
||||
if (!result)
|
||||
{
|
||||
EquipmentInfo const* eqInfo = sEquipmentStorage.LookupEntry<EquipmentInfo>(i);
|
||||
sLog->outString(">> Loaded 0 creature equipment templates. DB table `creature_equip_template` is empty!");
|
||||
sLog->outString();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!eqInfo)
|
||||
continue;
|
||||
uint32 count = 0;
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
for (uint8 j = 0; j < 3; ++j)
|
||||
uint16 entry = fields[0].GetUInt16();
|
||||
|
||||
EquipmentInfo equipmentInfo;
|
||||
|
||||
equipmentInfo.ItemEntry[0] = fields[1].GetUInt32();
|
||||
equipmentInfo.ItemEntry[1] = fields[2].GetUInt32();
|
||||
equipmentInfo.ItemEntry[2] = fields[3].GetUInt32();
|
||||
|
||||
for (uint8 i = 0; i < 3; ++i)
|
||||
{
|
||||
if (!eqInfo->equipentry[j])
|
||||
continue;
|
||||
if (!equipmentInfo.ItemEntry[i])
|
||||
continue;
|
||||
|
||||
ItemEntry const *dbcitem = sItemStore.LookupEntry(eqInfo->equipentry[j]);
|
||||
ItemEntry const *dbcItem = sItemStore.LookupEntry(equipmentInfo.ItemEntry[i]);
|
||||
|
||||
if (!dbcitem)
|
||||
if (!dbcItem)
|
||||
{
|
||||
sLog->outErrorDb("Unknown item (entry=%u) in creature_equip_template.equipentry%u for entry = %u, forced to 0.", eqInfo->equipentry[j], j+1, i);
|
||||
const_cast<EquipmentInfo*>(eqInfo)->equipentry[j] = 0;
|
||||
sLog->outErrorDb("Unknown item (entry=%u) in creature_equip_template.itemEntry%u for entry = %u, forced to 0.",
|
||||
equipmentInfo.ItemEntry[i], i+1, entry);
|
||||
equipmentInfo.ItemEntry[i] = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dbcitem->InventoryType != INVTYPE_WEAPON &&
|
||||
dbcitem->InventoryType != INVTYPE_SHIELD &&
|
||||
dbcitem->InventoryType != INVTYPE_RANGED &&
|
||||
dbcitem->InventoryType != INVTYPE_2HWEAPON &&
|
||||
dbcitem->InventoryType != INVTYPE_WEAPONMAINHAND &&
|
||||
dbcitem->InventoryType != INVTYPE_WEAPONOFFHAND &&
|
||||
dbcitem->InventoryType != INVTYPE_HOLDABLE &&
|
||||
dbcitem->InventoryType != INVTYPE_THROWN &&
|
||||
dbcitem->InventoryType != INVTYPE_RANGEDRIGHT)
|
||||
if (dbcItem->InventoryType != INVTYPE_WEAPON &&
|
||||
dbcItem->InventoryType != INVTYPE_SHIELD &&
|
||||
dbcItem->InventoryType != INVTYPE_RANGED &&
|
||||
dbcItem->InventoryType != INVTYPE_2HWEAPON &&
|
||||
dbcItem->InventoryType != INVTYPE_WEAPONMAINHAND &&
|
||||
dbcItem->InventoryType != INVTYPE_WEAPONOFFHAND &&
|
||||
dbcItem->InventoryType != INVTYPE_HOLDABLE &&
|
||||
dbcItem->InventoryType != INVTYPE_THROWN &&
|
||||
dbcItem->InventoryType != INVTYPE_RANGEDRIGHT)
|
||||
{
|
||||
sLog->outErrorDb("Item (entry=%u) in creature_equip_template.equipentry%u for entry = %u is not equipable in a hand, forced to 0.", eqInfo->equipentry[j], j+1, i);
|
||||
const_cast<EquipmentInfo*>(eqInfo)->equipentry[j] = 0;
|
||||
sLog->outErrorDb("Item (entry=%u) in creature_equip_template.itemEntry%u for entry = %u is not equipable in a hand, forced to 0.",
|
||||
equipmentInfo.ItemEntry[i], i+1, entry);
|
||||
equipmentInfo.ItemEntry[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sLog->outString(">> Loaded %u equipment templates in %u ms", sEquipmentStorage.RecordCount, GetMSTimeDiffToNow(oldMSTime));
|
||||
EquipmentInfoStore[entry] = equipmentInfo;
|
||||
|
||||
++count;
|
||||
}
|
||||
while (result->NextRow());
|
||||
|
||||
sLog->outString(">> Loaded %u equipment templates in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
sLog->outString();
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@
|
||||
extern SQLStorage sCreatureStorage;
|
||||
extern SQLStorage sCreatureDataAddonStorage;
|
||||
extern SQLStorage sCreatureInfoAddonStorage;
|
||||
extern SQLStorage sEquipmentStorage;
|
||||
extern SQLStorage sGOStorage;
|
||||
extern SQLStorage sItemStorage;
|
||||
|
||||
@@ -1408,6 +1407,7 @@ class ObjectMgr
|
||||
MapObjectGuids mMapObjectGuids;
|
||||
CreatureDataMap mCreatureDataMap;
|
||||
CreatureModelContainer CreatureModelStore;
|
||||
EquipmentInfoContainer EquipmentInfoStore;
|
||||
LinkedRespawnMap mLinkedRespawnMap;
|
||||
CreatureLocaleMap mCreatureLocaleMap;
|
||||
GameObjectDataMap mGameObjectDataMap;
|
||||
|
||||
@@ -23,7 +23,6 @@ const char CreatureInfosrcfmt[]="iiiiiiiiiisssiiiiiiifffiffiifiiiiiiiiiiffiiiiii
|
||||
const char CreatureInfodstfmt[]="iiiiiiiiiisssibbiiiifffiffiifiiiiiiiiiiffiiiiiiiiiiiiiiiiiiiiiiiisiifffliiiiiiiliiiii";
|
||||
const char CreatureDataAddonInfofmt[]="iiiiiis";
|
||||
const char CreatureInfoAddonInfofmt[]="iiiiiis";
|
||||
const char EquipmentInfofmt[]="iiii";
|
||||
const char GameObjectInfosrcfmt[]="iiissssiifiiiiiiiiiiiiiiiiiiiiiiiiiiiiiissi";
|
||||
const char GameObjectInfodstfmt[]="iiissssiifiiiiiiiiiiiiiiiiiiiiiiiiiiiiiisii";
|
||||
const char ItemPrototypesrcfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiisiiiii";
|
||||
@@ -32,7 +31,6 @@ const char ItemPrototypedstfmt[]="iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
|
||||
SQLStorage sCreatureStorage(CreatureInfosrcfmt, CreatureInfodstfmt, "entry","creature_template");
|
||||
SQLStorage sCreatureDataAddonStorage(CreatureDataAddonInfofmt,"guid","creature_addon");
|
||||
SQLStorage sCreatureInfoAddonStorage(CreatureInfoAddonInfofmt,"entry","creature_template_addon");
|
||||
SQLStorage sEquipmentStorage(EquipmentInfofmt,"entry","creature_equip_template");
|
||||
SQLStorage sGOStorage(GameObjectInfosrcfmt, GameObjectInfodstfmt, "entry","gameobject_template");
|
||||
SQLStorage sItemStorage(ItemPrototypesrcfmt, ItemPrototypedstfmt, "entry","item_template");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user