remove item cache info

This commit is contained in:
Yunfan Li
2023-12-17 17:48:48 +08:00
parent b96244b28f
commit d4ad08f986

View File

@@ -996,240 +996,240 @@ void RandomItemMgr::BuildItemInfoCache()
continue; continue;
// Init Item cache // Init Item cache
ItemInfoEntry cacheInfo; // ItemInfoEntry cacheInfo;
for (uint8 clazz = CLASS_WARRIOR; clazz < MAX_CLASSES; ++clazz) // for (uint8 clazz = CLASS_WARRIOR; clazz < MAX_CLASSES; ++clazz)
{ // {
// skip nonexistent classes // // skip nonexistent classes
if (!((1 << (clazz - 1)) & CLASSMASK_ALL_PLAYABLE) || !sChrClassesStore.LookupEntry(clazz)) // if (!((1 << (clazz - 1)) & CLASSMASK_ALL_PLAYABLE) || !sChrClassesStore.LookupEntry(clazz))
continue; // continue;
// skip wrong classes // // skip wrong classes
if ((proto->AllowableClass & (1 << (clazz - 1))) == 0) // if ((proto->AllowableClass & (1 << (clazz - 1))) == 0)
continue; // continue;
for (uint32 spec = 1; spec < 5; ++spec) // for (uint32 spec = 1; spec < 5; ++spec)
{ // {
if (!m_weightScales[clazz][spec].info.id) // if (!m_weightScales[clazz][spec].info.id)
continue; // continue;
// check possible armor for spec // // check possible armor for spec
if (m_weightScales) // if (m_weightScales)
if (proto->Class == ITEM_CLASS_ARMOR && ( // if (proto->Class == ITEM_CLASS_ARMOR && (
slot == EQUIPMENT_SLOT_HEAD || // slot == EQUIPMENT_SLOT_HEAD ||
slot == EQUIPMENT_SLOT_SHOULDERS || // slot == EQUIPMENT_SLOT_SHOULDERS ||
slot == EQUIPMENT_SLOT_CHEST || // slot == EQUIPMENT_SLOT_CHEST ||
slot == EQUIPMENT_SLOT_WAIST || // slot == EQUIPMENT_SLOT_WAIST ||
slot == EQUIPMENT_SLOT_LEGS || // slot == EQUIPMENT_SLOT_LEGS ||
slot == EQUIPMENT_SLOT_FEET || // slot == EQUIPMENT_SLOT_FEET ||
slot == EQUIPMENT_SLOT_WRISTS || // slot == EQUIPMENT_SLOT_WRISTS ||
slot == EQUIPMENT_SLOT_HANDS) && // slot == EQUIPMENT_SLOT_HANDS) &&
!ShouldEquipArmorForSpec(clazz, spec, proto)) // !ShouldEquipArmorForSpec(clazz, spec, proto))
continue; // continue;
// check possible weapon for spec // // check possible weapon for spec
if ((proto->Class == ITEM_CLASS_WEAPON || (proto->SubClass == ITEM_SUBCLASS_ARMOR_SHIELD || (proto->SubClass == ITEM_SUBCLASS_ARMOR_MISC && proto->InventoryType == INVTYPE_HOLDABLE))) && // if ((proto->Class == ITEM_CLASS_WEAPON || (proto->SubClass == ITEM_SUBCLASS_ARMOR_SHIELD || (proto->SubClass == ITEM_SUBCLASS_ARMOR_MISC && proto->InventoryType == INVTYPE_HOLDABLE))) &&
!ShouldEquipWeaponForSpec(clazz, spec, proto)) // !ShouldEquipWeaponForSpec(clazz, spec, proto))
continue; // continue;
StatWeight statWeight; // StatWeight statWeight;
statWeight.id = m_weightScales[clazz][spec].info.id; // statWeight.id = m_weightScales[clazz][spec].info.id;
uint32 statW = CalculateStatWeight(clazz, spec, proto); // uint32 statW = CalculateStatWeight(clazz, spec, proto);
// set stat weight = 1 for items that can be equipped but have no proper stats // // set stat weight = 1 for items that can be equipped but have no proper stats
statWeight.weight = statW ? statW : 1; // statWeight.weight = statW ? statW : 1;
//statWeight.weight = statW; // //statWeight.weight = statW;
// save item statWeight into ItemCache // // save item statWeight into ItemCache
cacheInfo.weights[statWeight.id] = statWeight.weight; // cacheInfo.weights[statWeight.id] = statWeight.weight;
LOG_DEBUG("playerbots", "Item: {}, weight: {}, class: {}, spec: {}", proto->ItemId, statWeight.weight, clazz, m_weightScales[clazz][spec].info.name); // LOG_DEBUG("playerbots", "Item: {}, weight: {}, class: {}, spec: {}", proto->ItemId, statWeight.weight, clazz, m_weightScales[clazz][spec].info.name);
} // }
} // }
cacheInfo.team = TEAM_NEUTRAL; // cacheInfo.team = TEAM_NEUTRAL;
// check faction // // check faction
if (proto->Flags2 & ITEM_FLAG2_FACTION_HORDE) // if (proto->Flags2 & ITEM_FLAG2_FACTION_HORDE)
cacheInfo.team = TEAM_HORDE; // cacheInfo.team = TEAM_HORDE;
if (proto->Flags2 & ITEM_FLAG2_FACTION_ALLIANCE) // if (proto->Flags2 & ITEM_FLAG2_FACTION_ALLIANCE)
cacheInfo.team = TEAM_ALLIANCE; // cacheInfo.team = TEAM_ALLIANCE;
if (cacheInfo.team == TEAM_NEUTRAL && proto->AllowableRace > 1 && proto->AllowableRace < 8388607) // if (cacheInfo.team == TEAM_NEUTRAL && proto->AllowableRace > 1 && proto->AllowableRace < 8388607)
{ // {
if (FactionEntry const* faction = sFactionStore.LookupEntry(HORDE)) // if (FactionEntry const* faction = sFactionStore.LookupEntry(HORDE))
if ((proto->AllowableRace & faction->BaseRepRaceMask[0]) != 0) // if ((proto->AllowableRace & faction->BaseRepRaceMask[0]) != 0)
cacheInfo.team = TEAM_HORDE; // cacheInfo.team = TEAM_HORDE;
if (FactionEntry const* faction = sFactionStore.LookupEntry(ALLIANCE)) // if (FactionEntry const* faction = sFactionStore.LookupEntry(ALLIANCE))
if ((proto->AllowableRace & faction->BaseRepRaceMask[0]) != 0) // if ((proto->AllowableRace & faction->BaseRepRaceMask[0]) != 0)
cacheInfo.team = TEAM_ALLIANCE; // cacheInfo.team = TEAM_ALLIANCE;
} // }
if (cacheInfo.team < TEAM_NEUTRAL) // if (cacheInfo.team < TEAM_NEUTRAL)
LOG_DEBUG("playerbots", "Item: {}, team (item): {}", proto->ItemId, cacheInfo.team == TEAM_ALLIANCE ? "Alliance" : "Horde"); // LOG_DEBUG("playerbots", "Item: {}, team (item): {}", proto->ItemId, cacheInfo.team == TEAM_ALLIANCE ? "Alliance" : "Horde");
// check min level // // check min level
if (proto->RequiredLevel) // if (proto->RequiredLevel)
cacheInfo.minLevel = proto->RequiredLevel; // cacheInfo.minLevel = proto->RequiredLevel;
// check item source // // check item source
if (proto->Flags & ITEM_FLAG_NO_DISENCHANT) // if (proto->Flags & ITEM_FLAG_NO_DISENCHANT)
{ // {
cacheInfo.source = ITEM_SOURCE_PVP; // cacheInfo.source = ITEM_SOURCE_PVP;
LOG_DEBUG("playerbots", "Item: {}, source: PvP Reward", proto->ItemId); // LOG_DEBUG("playerbots", "Item: {}, source: PvP Reward", proto->ItemId);
} // }
// check quests // // check quests
if (cacheInfo.source == ITEM_SOURCE_NONE) // if (cacheInfo.source == ITEM_SOURCE_NONE)
{ // {
std::vector<uint32> questIds = GetQuestIdsForItem(proto->ItemId); // std::vector<uint32> questIds = GetQuestIdsForItem(proto->ItemId);
if (questIds.size()) // if (questIds.size())
{ // {
bool isAlly = false; // bool isAlly = false;
bool isHorde = false; // bool isHorde = false;
for (std::vector<uint32>::iterator i = questIds.begin(); i != questIds.end(); ++i) // for (std::vector<uint32>::iterator i = questIds.begin(); i != questIds.end(); ++i)
{ // {
Quest const* quest = sObjectMgr->GetQuestTemplate(*i); // Quest const* quest = sObjectMgr->GetQuestTemplate(*i);
if (quest) // if (quest)
{ // {
cacheInfo.source = ITEM_SOURCE_QUEST; // cacheInfo.source = ITEM_SOURCE_QUEST;
cacheInfo.sourceId = *i; // cacheInfo.sourceId = *i;
if (!cacheInfo.minLevel) // if (!cacheInfo.minLevel)
cacheInfo.minLevel = quest->GetMinLevel(); // cacheInfo.minLevel = quest->GetMinLevel();
// check quest team // // check quest team
if (cacheInfo.team == TEAM_NEUTRAL) // if (cacheInfo.team == TEAM_NEUTRAL)
{ // {
uint32 reqRace = quest->GetAllowableRaces(); // uint32 reqRace = quest->GetAllowableRaces();
if (reqRace) // if (reqRace)
{ // {
if ((reqRace & RACEMASK_ALLIANCE) != 0) // if ((reqRace & RACEMASK_ALLIANCE) != 0)
isAlly = true; // isAlly = true;
else if ((reqRace & RACEMASK_HORDE) != 0) // else if ((reqRace & RACEMASK_HORDE) != 0)
isHorde = true; // isHorde = true;
} // }
} // }
} // }
} // }
if (isAlly && isHorde) // if (isAlly && isHorde)
cacheInfo.team = TEAM_NEUTRAL; // cacheInfo.team = TEAM_NEUTRAL;
else if (isAlly) // else if (isAlly)
cacheInfo.team = TEAM_ALLIANCE; // cacheInfo.team = TEAM_ALLIANCE;
else if (isHorde) // else if (isHorde)
cacheInfo.team = TEAM_HORDE; // cacheInfo.team = TEAM_HORDE;
LOG_DEBUG("playerbots", "Item: {}, team (quest): {}", proto->ItemId, cacheInfo.team == TEAM_ALLIANCE ? "Alliance" : cacheInfo.team == TEAM_HORDE ? "Horde" : "Both"); // LOG_DEBUG("playerbots", "Item: {}, team (quest): {}", proto->ItemId, cacheInfo.team == TEAM_ALLIANCE ? "Alliance" : cacheInfo.team == TEAM_HORDE ? "Horde" : "Both");
LOG_DEBUG("playerbots", "Item: {}, source: quest {}, minlevel: {}", proto->ItemId, cacheInfo.sourceId, cacheInfo.minLevel); // LOG_DEBUG("playerbots", "Item: {}, source: quest {}, minlevel: {}", proto->ItemId, cacheInfo.sourceId, cacheInfo.minLevel);
} // }
} // }
if (cacheInfo.minLevel) // if (cacheInfo.minLevel)
LOG_DEBUG("playerbots", "Item: {}, minlevel: {}", proto->ItemId, cacheInfo.minLevel); // LOG_DEBUG("playerbots", "Item: {}, minlevel: {}", proto->ItemId, cacheInfo.minLevel);
// check vendors // // check vendors
if (cacheInfo.source == ITEM_SOURCE_NONE) // if (cacheInfo.source == ITEM_SOURCE_NONE)
{ // {
for (std::set<uint32>::iterator i = vendorItems.begin(); i != vendorItems.end(); ++i) // for (std::set<uint32>::iterator i = vendorItems.begin(); i != vendorItems.end(); ++i)
{ // {
if (proto->ItemId == *i) // if (proto->ItemId == *i)
{ // {
cacheInfo.source = ITEM_SOURCE_VENDOR; // cacheInfo.source = ITEM_SOURCE_VENDOR;
LOG_DEBUG("playerbots", "Item: {} source: vendor", proto->ItemId); // LOG_DEBUG("playerbots", "Item: {} source: vendor", proto->ItemId);
break; // break;
} // }
} // }
} // }
// check drops // // check drops
std::vector<int32> creatures; // std::vector<int32> creatures;
std::vector<int32> gameobjects; // std::vector<int32> gameobjects;
auto range = dropMap->equal_range(itr.first); // auto range = dropMap->equal_range(itr.first);
for (auto iter = range.first; iter != range.second; ++iter) // for (auto iter = range.first; iter != range.second; ++iter)
{ // {
if (iter->second > 0) // if (iter->second > 0)
creatures.push_back(iter->second); // creatures.push_back(iter->second);
else // else
gameobjects.push_back(abs(iter->second)); // gameobjects.push_back(abs(iter->second));
} // }
// check creature drop // // check creature drop
if (cacheInfo.source == ITEM_SOURCE_NONE) // if (cacheInfo.source == ITEM_SOURCE_NONE)
{ // {
if (creatures.size()) // if (creatures.size())
{ // {
if (creatures.size() == 1) // if (creatures.size() == 1)
{ // {
cacheInfo.source = ITEM_SOURCE_DROP; // cacheInfo.source = ITEM_SOURCE_DROP;
cacheInfo.sourceId = creatures.front(); // cacheInfo.sourceId = creatures.front();
LOG_DEBUG("playerbots", "Item: {}, source: creature drop, ID: {}", proto->ItemId, creatures.front()); // LOG_DEBUG("playerbots", "Item: {}, source: creature drop, ID: {}", proto->ItemId, creatures.front());
} // }
else // else
{ // {
cacheInfo.source = ITEM_SOURCE_DROP; // cacheInfo.source = ITEM_SOURCE_DROP;
LOG_DEBUG("playerbots", "Item: {}, source: creatures drop, number: {}", proto->ItemId, creatures.size()); // LOG_DEBUG("playerbots", "Item: {}, source: creatures drop, number: {}", proto->ItemId, creatures.size());
} // }
} // }
} // }
// check gameobject drop // // check gameobject drop
if (cacheInfo.source == ITEM_SOURCE_NONE || (cacheInfo.source == ITEM_SOURCE_DROP && !cacheInfo.sourceId)) // if (cacheInfo.source == ITEM_SOURCE_NONE || (cacheInfo.source == ITEM_SOURCE_DROP && !cacheInfo.sourceId))
{ // {
if (gameobjects.size()) // if (gameobjects.size())
{ // {
if (gameobjects.size() == 1) // if (gameobjects.size() == 1)
{ // {
cacheInfo.source = ITEM_SOURCE_DROP; // cacheInfo.source = ITEM_SOURCE_DROP;
cacheInfo.sourceId = gameobjects.front(); // cacheInfo.sourceId = gameobjects.front();
LOG_INFO("playerbots", "Item: {}, source: gameobject, ID: {}", proto->ItemId, gameobjects.front()); // LOG_INFO("playerbots", "Item: {}, source: gameobject, ID: {}", proto->ItemId, gameobjects.front());
} // }
else // else
{ // {
cacheInfo.source = ITEM_SOURCE_DROP; // cacheInfo.source = ITEM_SOURCE_DROP;
LOG_INFO("playerbots", "Item: {}, source: gameobjects, number: {}", proto->ItemId, gameobjects.size()); // LOG_INFO("playerbots", "Item: {}, source: gameobjects, number: {}", proto->ItemId, gameobjects.size());
} // }
} // }
} // }
// check faction // // check faction
if (proto->RequiredReputationFaction > 0 && proto->RequiredReputationFaction != 35 && proto->RequiredReputationRank < 15) // if (proto->RequiredReputationFaction > 0 && proto->RequiredReputationFaction != 35 && proto->RequiredReputationRank < 15)
{ // {
cacheInfo.repFaction = proto->RequiredReputationFaction; // cacheInfo.repFaction = proto->RequiredReputationFaction;
cacheInfo.repRank = proto->RequiredReputationRank; // cacheInfo.repRank = proto->RequiredReputationRank;
} // }
cacheInfo.quality = proto->Quality; // cacheInfo.quality = proto->Quality;
cacheInfo.itemId = proto->ItemId; // cacheInfo.itemId = proto->ItemId;
cacheInfo.slot = slot; // cacheInfo.slot = slot;
// save cache // // save cache
PlayerbotsDatabasePreparedStatement* stmt = PlayerbotsDatabase.GetPreparedStatement(PLAYERBOTS_DEL_EQUIP_CACHE_NEW); // PlayerbotsDatabasePreparedStatement* stmt = PlayerbotsDatabase.GetPreparedStatement(PLAYERBOTS_DEL_EQUIP_CACHE_NEW);
stmt->SetData(0, proto->ItemId); // stmt->SetData(0, proto->ItemId);
trans->Append(stmt); // trans->Append(stmt);
stmt = PlayerbotsDatabase.GetPreparedStatement(PLAYERBOTS_INS_EQUIP_CACHE_NEW); // stmt = PlayerbotsDatabase.GetPreparedStatement(PLAYERBOTS_INS_EQUIP_CACHE_NEW);
stmt->SetData(0, cacheInfo.itemId); // stmt->SetData(0, cacheInfo.itemId);
stmt->SetData(1, cacheInfo.quality); // stmt->SetData(1, cacheInfo.quality);
stmt->SetData(2, cacheInfo.slot); // stmt->SetData(2, cacheInfo.slot);
stmt->SetData(3, cacheInfo.source); // stmt->SetData(3, cacheInfo.source);
stmt->SetData(4, cacheInfo.sourceId); // stmt->SetData(4, cacheInfo.sourceId);
stmt->SetData(5, cacheInfo.team); // stmt->SetData(5, cacheInfo.team);
stmt->SetData(6, cacheInfo.repFaction); // stmt->SetData(6, cacheInfo.repFaction);
stmt->SetData(7, cacheInfo.repRank); // stmt->SetData(7, cacheInfo.repRank);
stmt->SetData(8, cacheInfo.minLevel); // stmt->SetData(8, cacheInfo.minLevel);
for (uint8 i = 1; i <= MAX_STAT_SCALES; ++i) // for (uint8 i = 1; i <= MAX_STAT_SCALES; ++i)
{ // {
if (cacheInfo.weights[i]) // if (cacheInfo.weights[i])
stmt->SetData(8 + i, cacheInfo.weights[i]); // stmt->SetData(8 + i, cacheInfo.weights[i]);
else // else
stmt->SetData(8 + i, 0); // stmt->SetData(8 + i, 0);
} // }
trans->Append(stmt); // trans->Append(stmt);
itemInfoCache[cacheInfo.itemId] = std::move(cacheInfo); // itemInfoCache[cacheInfo.itemId] = std::move(cacheInfo);
} }
PlayerbotsDatabase.CommitTransaction(trans); PlayerbotsDatabase.CommitTransaction(trans);