[Performance] Look object stack

This commit is contained in:
Yunfan Li
2024-06-24 00:21:59 +08:00
parent 82114fdfff
commit 3abce62bba

View File

@@ -249,16 +249,17 @@ bool LootObject::IsLootPossible(Player* bot)
bool LootObjectStack::Add(ObjectGuid guid)
{
if (availableLoot.size() >= MAX_LOOT_OBJECT_COUNT) {
availableLoot.shrink(time(nullptr) - 30);
}
if (availableLoot.size() >= MAX_LOOT_OBJECT_COUNT) {
availableLoot.clear();
}
if (!availableLoot.insert(guid).second)
return false;
if (availableLoot.size() < MAX_LOOT_OBJECT_COUNT)
return true;
std::vector<LootObject> ordered = OrderByDistance();
for (size_t i = MAX_LOOT_OBJECT_COUNT; i < ordered.size(); i++)
Remove(ordered[i].guid);
return true;
}