Core/Commands: Enable .debug loadcells on console and allow to load a specific tile

Port From (https://github.com/TrinityCore/TrinityCore/commit/e7fc68d74b4fe146b37d14f1b73dbbed421b9214)
This commit is contained in:
hondacrx
2022-06-09 18:01:31 -04:00
parent 32e72d59f9
commit 651cdf59c1
+32 -10
View File
@@ -572,23 +572,45 @@ namespace Game.Chat
return true; return true;
} }
[Command("loadcells", RBACPermissions.CommandDebug)] [Command("loadcells", RBACPermissions.CommandDebug, true)]
static bool HandleDebugLoadCellsCommand(CommandHandler handler, uint mapId = 0xFFFFFFFF) static bool HandleDebugLoadCellsCommand(CommandHandler handler, uint? mapId, uint? tileX, uint? tileY)
{
Map map = null;
if (mapId.HasValue)
map = Global.MapMgr.FindBaseNonInstanceMap(mapId.Value);
else
{ {
Player player = handler.GetPlayer(); Player player = handler.GetPlayer();
if (!player) if (player != null)
return false; {
// Fallback to player's map if no map has been specified
Map map = null; map = player.GetMap();
if (mapId != 0xFFFFFFFF) }
map = Global.MapMgr.FindBaseNonInstanceMap(mapId); }
if (!map) if (!map)
map = player.GetMap(); return false;
// Load 1 single tile if specified, otherwise load the whole map
if (tileX.HasValue && tileY.HasValue)
{
handler.SendSysMessage($"Loading cell (mapId: {map.GetId()} tile: {tileX}, {tileY}). Current GameObjects {map.GetObjectsStore().Count(p => p.Value is GameObject)}, Creatures {map.GetObjectsStore().Count(p => p.Value is Creature)}");
// Some unit convertions to go from TileXY to GridXY to WorldXY
float x = (((float)(64 - 1 - tileX.Value) - 0.5f - MapConst.CenterGridId) * MapConst.SizeofGrids) + (MapConst.CenterGridOffset * 2);
float y = (((float)(64 - 1 - tileY.Value) - 0.5f - MapConst.CenterGridId) * MapConst.SizeofGrids) + (MapConst.CenterGridOffset * 2);
map.LoadGrid(x, y);
handler.SendSysMessage($"Cell loaded (mapId: {map.GetId()} tile: {tileX}, {tileY}) After load - GameObject {map.GetObjectsStore().Count(p => p.Value is GameObject)}, Creatures {map.GetObjectsStore().Count(p => p.Value is Creature)}");
}
else
{
handler.SendSysMessage($"Loading all cells (mapId: {map.GetId()}). Current GameObjects {map.GetObjectsStore().Count(p => p.Value is GameObject)}, Creatures {map.GetObjectsStore().Count(p => p.Value is Creature)}");
map.LoadAllCells(); map.LoadAllCells();
handler.SendSysMessage("Cells loaded (mapId: {0})", map.GetId()); handler.SendSysMessage($"Cells loaded (mapId: {map.GetId()}) After load - GameObject {map.GetObjectsStore().Count(p => p.Value is GameObject)}, Creatures {map.GetObjectsStore().Count(p => p.Value is Creature)}");
}
return true; return true;
} }