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
+33 -11
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)
{ {
Player player = handler.GetPlayer();
if (!player)
return false;
Map map = null; Map map = null;
if (mapId != 0xFFFFFFFF) if (mapId.HasValue)
map = Global.MapMgr.FindBaseNonInstanceMap(mapId); map = Global.MapMgr.FindBaseNonInstanceMap(mapId.Value);
else
{
Player player = handler.GetPlayer();
if (player != null)
{
// Fallback to player's map if no map has been specified
map = player.GetMap();
}
}
if (!map) if (!map)
map = player.GetMap(); return false;
map.LoadAllCells(); // 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)}");
handler.SendSysMessage("Cells loaded (mapId: {0})", map.GetId()); // 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();
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;
} }