Files
tbd-station-14/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs
DrSmugleaf 48b61f6bcc Replace every usage of GridCoordinates with EntityCoordinates (#2021)
* Update RobustToolbox

* Transition direct type usages

* More updates

* Fix invalid use of to map

* Update RobustToolbox

* Fix dropping items

* Rename name usages of "GridCoordinates" to "EntityCoordinates"

* Revert "Update RobustToolbox"

This reverts commit 9f334a17c5908ded0043a63158bb671e4aa3f346.

* Revert "Update RobustToolbox"

This reverts commit 3a9c8cfa3606fa501aa84407796d2ad920853a09.

# Conflicts:
#	RobustToolbox

* Fix cursed IMapGrid method usage.

* GridTileLookupTest now uses EntityCoordinates

Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
Co-authored-by: Víctor Aguilera Puerto <zddm@outlook.es>
2020-09-06 16:11:53 +02:00

60 lines
2.3 KiB
C#

using Content.Server.GameObjects.Components.Stack;
using Content.Server.Utility;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Utility;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Power
{
[RegisterComponent]
internal class WirePlacerComponent : Component, IAfterInteract
{
[Dependency] private readonly IServerEntityManager _entityManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
/// <inheritdoc />
public override string Name => "WirePlacer";
[ViewVariables]
private string _wirePrototypeID;
[ViewVariables]
private WireType _blockingWireType;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _wirePrototypeID, "wirePrototypeID", "HVWire");
serializer.DataField(ref _blockingWireType, "blockingWireType", WireType.HighVoltage);
}
/// <inheritdoc />
public void AfterInteract(AfterInteractEventArgs eventArgs)
{
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true)) return;
if(!_mapManager.TryGetGrid(eventArgs.ClickLocation.GetGridId(_entityManager), out var grid))
return;
var snapPos = grid.SnapGridCellFor(eventArgs.ClickLocation, SnapGridOffset.Center);
var snapCell = grid.GetSnapGridCell(snapPos, SnapGridOffset.Center);
if(grid.GetTileRef(snapPos).Tile.IsEmpty)
return;
foreach (var snapComp in snapCell)
{
if (snapComp.Owner.TryGetComponent<WireComponent>(out var wire) && wire.WireType == _blockingWireType)
{
return;
}
}
if (Owner.TryGetComponent(out StackComponent stack) && !stack.Use(1))
return;
_entityManager.SpawnEntity(_wirePrototypeID, grid.GridTileToLocal(snapPos));
}
}
}