Files
tbd-station-14/Content.Server/GameObjects/Components/Power/WireComponent.cs
chairbender b35333d366 Click Drag Functionality + Refactor Interaction Interfaces (#1125)
Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
Co-authored-by: ComicIronic <comicironic@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
2020-07-06 23:27:03 +02:00

60 lines
2.0 KiB
C#

using Content.Server.GameObjects.Components.Interactable;
using Content.Server.GameObjects.Components.Stack;
using Content.Server.GameObjects.EntitySystems;
using Content.Server.Interfaces.GameObjects.Components.Interaction;
using Content.Shared.GameObjects.Components.Interactable;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Power
{
/// <summary>
/// Allows the attached entity to be destroyed by a cutting tool, dropping a piece of wire.
/// </summary>
[RegisterComponent]
public class WireComponent : Component, IInteractUsing
{
public override string Name => "Wire";
[ViewVariables]
private string _wireDroppedOnCutPrototype;
/// <summary>
/// Checked by <see cref="WirePlacerComponent"/> to determine if there is
/// already a wire of a type on a tile.
/// </summary>
[ViewVariables]
public WireType WireType => _wireType;
private WireType _wireType;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _wireDroppedOnCutPrototype, "wireDroppedOnCutPrototype", "HVWireStack1");
serializer.DataField(ref _wireType, "wireType", WireType.HighVoltage);
}
public bool InteractUsing(InteractUsingEventArgs eventArgs)
{
if (!eventArgs.Using.TryGetComponent(out ToolComponent tool)) return false;
if (!tool.UseTool(eventArgs.User, Owner, ToolQuality.Cutting)) return false;
Owner.Delete();
var droppedEnt = Owner.EntityManager.SpawnEntity(_wireDroppedOnCutPrototype, eventArgs.ClickLocation);
if (droppedEnt.TryGetComponent<StackComponent>(out var stackComp))
stackComp.Count = 1;
return true;
}
}
public enum WireType
{
HighVoltage,
MediumVoltage,
Apc,
}
}