Files
tbd-station-14/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs
Acruid ca4fd649fe Massive Namespace Cleanup (#3120)
* Engine namespace changes.

* Automated remove redundant using statements.

* Simplified Graphics namespace.

* Apparently the container system stores full type names in the map file.😞 This updates those names.

* API Changes to LocalizationManager.LoadCulture.

* Update submodule to v0.3.2
2021-02-11 01:13:03 -08:00

62 lines
2.3 KiB
C#

#nullable enable
using Content.Server.GameObjects.Components.Stack;
using Content.Shared.Interfaces.GameObjects.Components;
using Content.Shared.Utility;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using System.Threading.Tasks;
using Robust.Shared.Map;
namespace Content.Server.GameObjects.Components.Power
{
[RegisterComponent]
internal class WirePlacerComponent : Component, IAfterInteract
{
[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 />
async Task<bool> IAfterInteract.AfterInteract(AfterInteractEventArgs eventArgs)
{
if (_wirePrototypeID == null)
return true;
if (!eventArgs.InRangeUnobstructed(ignoreInsideBlocker: true, popup: true))
return true;
if(!_mapManager.TryGetGrid(eventArgs.ClickLocation.GetGridId(Owner.EntityManager), out var grid))
return true;
var snapPos = grid.SnapGridCellFor(eventArgs.ClickLocation, SnapGridOffset.Center);
var snapCell = grid.GetSnapGridCell(snapPos, SnapGridOffset.Center);
if(grid.GetTileRef(snapPos).Tile.IsEmpty)
return true;
foreach (var snapComp in snapCell)
{
if (snapComp.Owner.TryGetComponent<WireComponent>(out var wire) && wire.WireType == _blockingWireType)
{
return true;
}
}
if (Owner.TryGetComponent<StackComponent>(out var stack) && !stack.Use(1))
return true;
Owner.EntityManager.SpawnEntity(_wirePrototypeID, grid.GridTileToLocal(snapPos));
return true;
}
}
}