prevent placing tiles under walls (#10547)
This commit is contained in:
@@ -2,8 +2,10 @@ using Content.Server.Stack;
|
|||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
using Content.Shared.Maps;
|
using Content.Shared.Maps;
|
||||||
|
using Content.Shared.Physics;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
@@ -15,6 +17,8 @@ namespace Content.Server.Tiles
|
|||||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
[Dependency] private readonly IRobustRandom _random = default!;
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
[Dependency] private readonly StackSystem _stackSystem = default!;
|
[Dependency] private readonly StackSystem _stackSystem = default!;
|
||||||
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
|
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
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
|
// 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 location = args.ClickLocation.AlignWithClosestGridTile();
|
||||||
|
var physics = GetEntityQuery<PhysicsComponent>();
|
||||||
|
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);
|
var locationMap = location.ToMap(EntityManager);
|
||||||
if (locationMap.MapId == MapId.Nullspace)
|
if (locationMap.MapId == MapId.Nullspace)
|
||||||
return;
|
return;
|
||||||
_mapManager.TryGetGrid(location.GetGridId(EntityManager), out var mapGrid);
|
_mapManager.TryGetGrid(location.EntityId, out var mapGrid);
|
||||||
|
|
||||||
foreach (var currentTile in component.OutputTiles)
|
foreach (var currentTile in component.OutputTiles)
|
||||||
{
|
{
|
||||||
@@ -82,7 +96,7 @@ namespace Content.Server.Tiles
|
|||||||
{
|
{
|
||||||
var variant = _random.Pick(((ContentTileDefinition) _tileDefinitionManager[tileId]).PlacementVariants);
|
var variant = _random.Pick(((ContentTileDefinition) _tileDefinitionManager[tileId]).PlacementVariants);
|
||||||
mapGrid.SetTile(location.Offset(new Vector2(offset, offset)), new Tile(tileId, 0, variant));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user