From 47bea619f79ab3c4829d490af6566822b97f49c7 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 2 Mar 2022 18:00:52 -0500 Subject: [PATCH] Scripts/Comamnds: Improve ".debug objectcount" command Port From (https://github.com/TrinityCore/TrinityCore/commit/ffd85f9139119ec56a8a6f3add4ef4c0f047b838) --- Source/Game/Chat/Commands/DebugCommands.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Source/Game/Chat/Commands/DebugCommands.cs b/Source/Game/Chat/Commands/DebugCommands.cs index 37e864a14..8d746465e 100644 --- a/Source/Game/Chat/Commands/DebugCommands.cs +++ b/Source/Game/Chat/Commands/DebugCommands.cs @@ -757,13 +757,31 @@ namespace Game.Chat return true; } - + [Command("objectcount", RBACPermissions.CommandDebug, true)] static bool HandleDebugObjectCountCommand(CommandHandler handler, uint? mapId) { void HandleDebugObjectCountMap(Map map) { handler.SendSysMessage($"Map Id: {map.GetId()} Name: '{map.GetMapName()}' Instance Id: {map.GetInstanceId()} Creatures: {map.GetObjectsStore().OfType().Count()} GameObjects: {map.GetObjectsStore().OfType().Count()}"); + + Dictionary creatureIds = new(); + foreach (var p in map.GetObjectsStore()) + { + if (p.Value.IsCreature()) + { + if (!creatureIds.ContainsKey(p.Value.GetEntry())) + creatureIds[p.Value.GetEntry()] = 0; + + creatureIds[p.Value.GetEntry()]++; + } + } + + var orderedCreatures = creatureIds.OrderBy(p => p.Value).Where(p => p.Value > 5); + + handler.SendSysMessage("Top Creatures count:"); + foreach (var p in orderedCreatures) + handler.SendSysMessage($"Entry: {p.Key} Count: {p.Value}"); } if (mapId.HasValue)