2021-02-01 10:19:43 -06:00
|
|
|
using System.Threading.Tasks;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Stack;
|
|
|
|
|
using Content.Server.Tools.Components;
|
|
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.Tool;
|
2020-06-28 09:23:26 -06:00
|
|
|
using Robust.Shared.GameObjects;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2020-06-28 09:23:26 -06:00
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-07-04 18:11:52 +02:00
|
|
|
namespace Content.Server.Power.Components
|
2020-06-28 09:23:26 -06:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2021-07-04 18:11:52 +02:00
|
|
|
/// Allows the attached entity to be destroyed by a cutting tool, dropping a piece of cable.
|
2020-06-28 09:23:26 -06:00
|
|
|
/// </summary>
|
|
|
|
|
[RegisterComponent]
|
2021-07-04 18:11:52 +02:00
|
|
|
public class CableComponent : Component, IInteractUsing
|
2020-06-28 09:23:26 -06:00
|
|
|
{
|
2021-07-04 18:11:52 +02:00
|
|
|
public override string Name => "Cable";
|
2020-06-28 09:23:26 -06:00
|
|
|
|
|
|
|
|
[ViewVariables]
|
2021-07-04 18:11:52 +02:00
|
|
|
[DataField("cableDroppedOnCutPrototype")]
|
|
|
|
|
private string? _cableDroppedOnCutPrototype = "CableHVStack1";
|
2020-06-28 09:23:26 -06:00
|
|
|
|
|
|
|
|
/// <summary>
|
2021-07-04 18:11:52 +02:00
|
|
|
/// Checked by <see cref="CablePlacerComponent"/> to determine if there is
|
|
|
|
|
/// already a cable of a type on a tile.
|
2020-06-28 09:23:26 -06:00
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables]
|
2021-07-04 18:11:52 +02:00
|
|
|
public CableType CableType => _cableType;
|
|
|
|
|
[DataField("cableType")]
|
|
|
|
|
private CableType _cableType = CableType.HighVoltage;
|
2020-06-28 09:23:26 -06:00
|
|
|
|
2021-02-04 17:44:49 +01:00
|
|
|
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
2020-06-28 09:23:26 -06:00
|
|
|
{
|
2021-07-04 18:11:52 +02:00
|
|
|
if (_cableDroppedOnCutPrototype == null)
|
2021-02-01 10:19:43 -06:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!eventArgs.Using.TryGetComponent<ToolComponent>(out var tool)) return false;
|
2020-08-18 14:39:08 +02:00
|
|
|
if (!await tool.UseTool(eventArgs.User, Owner, 0.25f, ToolQuality.Cutting)) return false;
|
2020-06-28 09:23:26 -06:00
|
|
|
|
|
|
|
|
Owner.Delete();
|
2021-07-04 18:11:52 +02:00
|
|
|
var droppedEnt = Owner.EntityManager.SpawnEntity(_cableDroppedOnCutPrototype, eventArgs.ClickLocation);
|
2020-06-28 09:23:26 -06:00
|
|
|
|
2021-05-30 08:53:02 +02:00
|
|
|
// TODO: Literally just use a prototype that has a single thing in the stack, it's not that complicated...
|
2021-06-12 11:24:34 +02:00
|
|
|
if (droppedEnt.TryGetComponent<StackComponent>(out var stack))
|
|
|
|
|
EntitySystem.Get<StackSystem>().SetCount(droppedEnt.Uid, stack, 1);
|
2020-06-28 09:23:26 -06:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-04 18:11:52 +02:00
|
|
|
public enum CableType
|
2020-06-28 09:23:26 -06:00
|
|
|
{
|
|
|
|
|
HighVoltage,
|
|
|
|
|
MediumVoltage,
|
|
|
|
|
Apc,
|
|
|
|
|
}
|
|
|
|
|
}
|