From 20a51ad7c3b217d5a2a8019ab95c74b49771c8c1 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Sun, 14 Aug 2022 02:00:39 -0400 Subject: [PATCH] prevent placing tiles under walls (#10547) --- Content.Server/Tiles/FloorTileSystem.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Content.Server/Tiles/FloorTileSystem.cs b/Content.Server/Tiles/FloorTileSystem.cs index 670d77d5cb..2ce8786c1e 100644 --- a/Content.Server/Tiles/FloorTileSystem.cs +++ b/Content.Server/Tiles/FloorTileSystem.cs @@ -2,8 +2,10 @@ using Content.Server.Stack; using Content.Shared.Audio; using Content.Shared.Interaction; using Content.Shared.Maps; +using Content.Shared.Physics; using Robust.Shared.Audio; using Robust.Shared.Map; +using Robust.Shared.Physics; using Robust.Shared.Player; using Robust.Shared.Random; @@ -15,6 +17,8 @@ namespace Content.Server.Tiles [Dependency] private readonly IMapManager _mapManager = default!; [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly StackSystem _stackSystem = default!; + [Dependency] private readonly SharedAudioSystem _audio = default!; + [Dependency] private readonly EntityLookupSystem _lookup = default!; public override void Initialize() { @@ -35,10 +39,20 @@ namespace Content.Server.Tiles // this looks a bit sussy but it might be because it needs to be able to place off of grids and expand them var location = args.ClickLocation.AlignWithClosestGridTile(); + var physics = GetEntityQuery(); + foreach (var ent in location.GetEntitiesInTile(lookupSystem: _lookup)) + { + // check that we the tile we're trying to access isn't blocked by a wall or something + if (physics.TryGetComponent(ent, out var phys) && + phys.BodyType == BodyType.Static && + phys.Hard && + (phys.CollisionLayer & (int) CollisionGroup.Impassable) != 0) + return; + } var locationMap = location.ToMap(EntityManager); if (locationMap.MapId == MapId.Nullspace) return; - _mapManager.TryGetGrid(location.GetGridId(EntityManager), out var mapGrid); + _mapManager.TryGetGrid(location.EntityId, out var mapGrid); foreach (var currentTile in component.OutputTiles) { @@ -82,7 +96,7 @@ namespace Content.Server.Tiles { var variant = _random.Pick(((ContentTileDefinition) _tileDefinitionManager[tileId]).PlacementVariants); mapGrid.SetTile(location.Offset(new Vector2(offset, offset)), new Tile(tileId, 0, variant)); - SoundSystem.Play(placeSound.GetSound(), Filter.Pvs(location), location, AudioHelpers.WithVariation(0.125f, _random)); + _audio.Play(placeSound, Filter.Pvs(location), location, AudioHelpers.WithVariation(0.125f, _random)); } } }