Fix being able to place cables on non-subfloor tiles

- Also performs an actionblocker check just in case.
This commit is contained in:
Vera Aguilera Puerto
2021-10-01 15:09:01 +02:00
parent 10254b5290
commit f21c921c56
2 changed files with 22 additions and 7 deletions

View File

@@ -1,7 +1,9 @@
using System.Threading.Tasks;
using Content.Server.Stack;
using Content.Shared.ActionBlocker;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Maps;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
@@ -29,26 +31,35 @@ namespace Content.Server.Power.Components
/// <inheritdoc />
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(eventArgs.User))
return false;
if (_cablePrototypeID == null)
return true;
return false;
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
return true;
return false;
if(!_mapManager.TryGetGrid(eventArgs.ClickLocation.GetGridId(Owner.EntityManager), out var grid))
return true;
return false;
var snapPos = grid.TileIndicesFor(eventArgs.ClickLocation);
if(grid.GetTileRef(snapPos).Tile.IsEmpty)
return true;
var tileDef = grid.GetTileRef(snapPos).Tile.GetContentTileDefinition();
if(!tileDef.IsSubFloor || tileDef.IsSpace)
return false;
foreach (var anchored in grid.GetAnchoredEntities(snapPos))
{
if (Owner.EntityManager.TryGetComponent<CableComponent>(anchored, out var wire) && wire.CableType == _blockingCableType)
{
return true;
return false;
}
}
if (Owner.TryGetComponent<StackComponent>(out var stack)
&& !EntitySystem.Get<StackSystem>().Use(Owner.Uid, 1, stack))
return true;
return false;
Owner.EntityManager.SpawnEntity(_cablePrototypeID, grid.GridTileToLocal(snapPos));
return true;