diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/scripts/Commands/cs_debug.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/server/scripts/Commands/cs_debug.cpp b/src/server/scripts/Commands/cs_debug.cpp index 86400739bc7..7f1dc590e4c 100644 --- a/src/server/scripts/Commands/cs_debug.cpp +++ b/src/server/scripts/Commands/cs_debug.cpp @@ -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*/) |