mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Scripts/Comamnds: Improve ".debug objectcount" command (#25208)
* Scripts/Comamnds: Improve ".debug objectcount" command
Include the top 5 most common creatures in the map
* Use C++ features to copy data
* Fix build warnings
* Update src/server/scripts/Commands/cs_debug.cpp
Co-authored-by: Shauren <shauren.trinity@gmail.com>
* Update src/server/scripts/Commands/cs_debug.cpp
Co-authored-by: Shauren <shauren.trinity@gmail.com>
* Update src/server/scripts/Commands/cs_debug.cpp
Co-authored-by: Shauren <shauren.trinity@gmail.com>
* Move CreatureCountWorker out of function and use template for unhandled cases
* Code cleanup
Co-authored-by: Shauren <shauren.trinity@gmail.com>
(cherry picked from commit bd5e832a64)
This commit is contained in:
@@ -1867,12 +1867,57 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
class CreatureCountWorker
|
||||
{
|
||||
public:
|
||||
CreatureCountWorker() { }
|
||||
|
||||
void Visit(std::unordered_map<ObjectGuid, Creature*>& creatureMap)
|
||||
{
|
||||
for (auto const& p : creatureMap)
|
||||
{
|
||||
uint32& count = creatureIds[p.second->GetEntry()];
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Visit(std::unordered_map<ObjectGuid, T*>&) { }
|
||||
|
||||
std::vector<std::pair<uint32, uint32>> GetTopCreatureCount(uint32 count)
|
||||
{
|
||||
auto comp = [](std::pair<uint32, uint32> const& a, std::pair<uint32, uint32> const& b)
|
||||
{
|
||||
return a.second > b.second;
|
||||
};
|
||||
std::set<std::pair<uint32, uint32>, decltype(comp)> set(creatureIds.begin(), creatureIds.end(), comp);
|
||||
|
||||
count = std::min(count, uint32(set.size()));
|
||||
std::vector<std::pair<uint32, uint32>> result(count);
|
||||
std::copy_n(set.begin(), count, result.begin());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<uint32, uint32> creatureIds;
|
||||
};
|
||||
|
||||
static void HandleDebugObjectCountMap(ChatHandler* handler, Map* map)
|
||||
{
|
||||
handler->PSendSysMessage("Map Id: %u Name: '%s' Instance Id: %u Creatures: " UI64FMTD " GameObjects: " UI64FMTD,
|
||||
map->GetId(), map->GetMapName(), map->GetInstanceId(),
|
||||
uint64(map->GetObjectsStore().Size<Creature>()),
|
||||
uint64(map->GetObjectsStore().Size<GameObject>()));
|
||||
|
||||
CreatureCountWorker worker;
|
||||
TypeContainerVisitor<CreatureCountWorker, MapStoredObjectTypesContainer> visitor(worker);
|
||||
visitor.Visit(map->GetObjectsStore());
|
||||
|
||||
handler->PSendSysMessage("Top Creatures count:");
|
||||
|
||||
for (auto&& p : worker.GetTopCreatureCount(5))
|
||||
handler->PSendSysMessage("Entry: %u Count: %u", p.first, p.second);
|
||||
}
|
||||
|
||||
static bool HandleDebugDummyCommand(ChatHandler* handler, CommandArgs* /*args*/)
|
||||
|
||||
Reference in New Issue
Block a user