speed up InitEquipment

This commit is contained in:
Yunfan Li
2023-08-10 13:44:46 +08:00
parent 8fc864aa04
commit 3b85e3e4b9
4 changed files with 384 additions and 271 deletions

View File

@@ -154,6 +154,7 @@ void RandomItemMgr::Init()
{
BuildItemInfoCache();
// BuildEquipCache();
BuildEquipCacheNew();
BuildAmmoCache();
BuildPotionCache();
BuildFoodCache();
@@ -441,6 +442,11 @@ bool RandomItemMgr::CheckItemStats(uint8 clazz, uint8 sp, uint8 ap, uint8 tank)
return sp || ap || tank;
}
std::vector<uint32> RandomItemMgr::GetCachedEquipments(uint32 requiredLevel, uint32 inventoryType)
{
return equipCacheNew[requiredLevel][inventoryType];
}
bool RandomItemMgr::ShouldEquipArmorForSpec(uint8 playerclass, uint8 spec, ItemTemplate const* proto)
{
if (proto->InventoryType == INVTYPE_TABARD)
@@ -2139,6 +2145,23 @@ void RandomItemMgr::BuildEquipCache()
}
}
void RandomItemMgr::BuildEquipCacheNew()
{
LOG_INFO("playerbots", "Loading equipments cache...");
ItemTemplateContainer const* itemTemplates = sObjectMgr->GetItemTemplateStore();
for (auto const& itr : *itemTemplates)
{
ItemTemplate const* proto = &itr.second;
if (!proto)
continue;
uint32 itemId = proto->ItemId;
if (IsTestItem(itemId)) {
continue;
}
equipCacheNew[proto->RequiredLevel][proto->InventoryType].push_back(itemId);
}
}
RandomItemList RandomItemMgr::Query(uint32 level, uint8 clazz, uint8 slot, uint32 quality)
{
// return equipCache[key];