public void Execute(IConsoleShell shell, string argStr, string[] args)
        {
            var    player = shell.Player as IPlayerSession;
            GridId gridId;

            switch (args.Length)
            {
            case 0:
                if (player?.AttachedEntity == null)
                {
                    shell.WriteLine("Only a player can run this command.");
                    return;
                }

                gridId = player.AttachedEntity.Transform.GridID;
                break;

            case 1:
                if (!int.TryParse(args[0], out var id))
                {
                    shell.WriteLine($"{args[0]} is not a valid integer.");
                    return;
                }

                gridId = new GridId(id);
                break;

            default:
                shell.WriteLine(Help);
                return;
            }

            var mapManager = IoCManager.Resolve <IMapManager>();

            if (!mapManager.TryGetGrid(gridId, out var grid))
            {
                shell.WriteLine($"No grid exists with id {gridId}");
                return;
            }

            var entityManager = IoCManager.Resolve <IEntityManager>();

            if (!entityManager.TryGetEntity(grid.GridEntityId, out var gridEntity))
            {
                shell.WriteLine($"Grid {gridId} doesn't have an associated grid entity.");
                return;
            }

            var tileDefinitionManager = IoCManager.Resolve <ITileDefinitionManager>();
            var prototypeManager      = IoCManager.Resolve <IPrototypeManager>();
            var underplating          = tileDefinitionManager["underplating"];
            var underplatingTile      = new Robust.Shared.Map.Tile(underplating.TileId);
            var changed = 0;

            foreach (var childUid in gridEntity.Transform.ChildEntityUids)
            {
                if (!entityManager.TryGetEntity(childUid, out var childEntity))
                {
                    continue;
                }

                var prototype = childEntity.Prototype;
                while (true)
                {
                    if (prototype?.Parent == null)
                    {
                        break;
                    }

                    prototype = prototypeManager.Index <EntityPrototype>(prototype.Parent);
                }

                if (prototype?.ID != "base_wall")
                {
                    continue;
                }

                if (!childEntity.Transform.Anchored)
                {
                    continue;
                }

                var tile    = grid.GetTileRef(childEntity.Transform.Coordinates);
                var tileDef = (ContentTileDefinition)tileDefinitionManager[tile.Tile.TypeId];

                if (tileDef.Name == "underplating")
                {
                    continue;
                }

                grid.SetTile(childEntity.Transform.Coordinates, underplatingTile);
                changed++;
            }

            shell.WriteLine($"Changed {changed} tiles.");
        }
Пример #2
0
        public GameStateMapData?GetStateData(GameTick fromTick)
        {
            var gridDatums = new Dictionary <GridId, GameStateMapData.GridDatum>();

            foreach (var grid in _grids.Values)
            {
                if (grid.LastModifiedTick < fromTick)
                {
                    continue;
                }

                var chunkData = new List <GameStateMapData.ChunkDatum>();
                foreach (var(index, chunk) in grid.GetMapChunks())
                {
                    if (chunk.LastModifiedTick < fromTick)
                    {
                        continue;
                    }

                    var tileBuffer = new Tile[grid.ChunkSize * (uint)grid.ChunkSize];

                    // Flatten the tile array.
                    // NetSerializer doesn't do multi-dimensional arrays.
                    // This is probably really expensive.
                    for (var x = 0; x < grid.ChunkSize; x++)
                    {
                        for (var y = 0; y < grid.ChunkSize; y++)
                        {
                            tileBuffer[x * grid.ChunkSize + y] = chunk.GetTile((ushort)x, (ushort)y);
                        }
                    }

                    chunkData.Add(new GameStateMapData.ChunkDatum(index, tileBuffer));
                }

                var gridDatum =
                    new GameStateMapData.GridDatum(chunkData.ToArray(), new MapCoordinates(grid.WorldPosition, grid.ParentMapId));

                gridDatums.Add(grid.Index, gridDatum);
            }

            var mapDeletionsData  = _mapDeletionHistory.Where(d => d.tick >= fromTick).Select(d => d.mapId).ToList();
            var gridDeletionsData = _gridDeletionHistory.Where(d => d.tick >= fromTick).Select(d => d.gridId).ToList();
            var mapCreations      = _mapCreationTick.Where(kv => kv.Value >= fromTick && kv.Key != MapId.Nullspace)
                                    .Select(kv => kv.Key).ToArray();
            var gridCreations = _grids.Values.Where(g => g.CreatedTick >= fromTick && g.ParentMapId != MapId.Nullspace).ToDictionary(g => g.Index,
                                                                                                                                     grid => new GameStateMapData.GridCreationDatum(grid.ChunkSize, grid.SnapSize));

            // no point sending empty collections
            if (gridDatums.Count == 0)
            {
                gridDatums = default;
            }
            if (gridDeletionsData.Count == 0)
            {
                gridDeletionsData = default;
            }
            if (mapDeletionsData.Count == 0)
            {
                mapDeletionsData = default;
            }
            if (mapCreations.Length == 0)
            {
                mapCreations = default;
            }
            if (gridCreations.Count == 0)
            {
                gridCreations = default;
            }

            // no point even creating an empty map state if no data
            if (gridDatums == null && gridDeletionsData == null && mapDeletionsData == null && mapCreations == null && gridCreations == null)
            {
                return(default);