Files
crystall-punk-14/Content.Server/GameObjects/Components/Power/WirePlacerComponent.cs

69 lines
2.3 KiB
C#
Raw Normal View History

2020-01-23 17:52:44 -08:00
using Content.Server.GameObjects.Components.Stack;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Utility;
using Robust.Server.GameObjects;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components.Transform;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.IoC;
using Robust.Shared.Map;
namespace Content.Server.GameObjects.Components.Power
{
[RegisterComponent]
2020-05-23 17:23:25 +02:00
internal class WirePlacerComponent : Component, IAfterInteract
{
2019-10-10 15:48:11 +02:00
#pragma warning disable 649
[Dependency] private readonly IServerEntityManager _entityManager;
[Dependency] private readonly IMapManager _mapManager;
2019-10-10 15:48:11 +02:00
#pragma warning restore 649
/// <inheritdoc />
public override string Name => "WirePlacer";
/// <inheritdoc />
2020-05-23 17:23:25 +02:00
public void AfterInteract(AfterInteractEventArgs eventArgs)
{
if (!InteractionChecks.InRangeUnobstructed(eventArgs)) return;
if(!_mapManager.TryGetGrid(eventArgs.ClickLocation.GridID, out var grid))
return;
2020-01-25 01:39:14 -08:00
var snapPos = grid.SnapGridCellFor(eventArgs.ClickLocation, SnapGridOffset.Center);
var snapCell = grid.GetSnapGridCell(snapPos, SnapGridOffset.Center);
if(grid.GetTileRef(snapPos).Tile.IsEmpty)
return;
var found = false;
foreach (var snapComp in snapCell)
{
if (!snapComp.Owner.HasComponent<PowerTransferComponent>())
continue;
found = true;
break;
}
if (found)
return;
2019-10-10 15:48:11 +02:00
2020-01-23 17:52:44 -08:00
bool hasItemSpriteComp = Owner.TryGetComponent(out SpriteComponent itemSpriteComp);
if (Owner.TryGetComponent(out StackComponent stack) && !stack.Use(1))
return;
GridCoordinates coordinates = grid.GridTileToLocal(snapPos);
var newWire = _entityManager.SpawnEntity("Wire", coordinates);
2020-01-23 17:52:44 -08:00
if (newWire.TryGetComponent(out SpriteComponent wireSpriteComp) && hasItemSpriteComp)
{
wireSpriteComp.Color = itemSpriteComp.Color;
}
//TODO: There is no way to set this wire as above or below the floor
}
}
}