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

View File

@@ -0,0 +1,4 @@
author: Zumorica
changes:
- type: Fix # One of the following: Add, Remove, Tweak, Fix
message: Fix being able to place cables/wires on non-subfloor tiles.