2021-02-01 10:19:43 -06:00
|
|
|
using System.Threading.Tasks;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Stack;
|
2021-10-07 13:01:27 +02:00
|
|
|
using Content.Server.Tools;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Server.Tools.Components;
|
|
|
|
|
using Content.Shared.Interaction;
|
2021-10-07 13:01:27 +02:00
|
|
|
using Content.Shared.Tools;
|
|
|
|
|
using Content.Shared.Tools.Components;
|
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;
|
2021-10-07 13:01:27 +02:00
|
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
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
|
|
|
|
2021-10-07 13:01:27 +02:00
|
|
|
[DataField("cuttingQuality", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
|
|
|
|
private string _cuttingQuality = "Cutting";
|
|
|
|
|
|
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;
|
|
|
|
|
|
2021-10-07 13:01:27 +02:00
|
|
|
if (!await EntitySystem.Get<ToolSystem>().UseTool(eventArgs.Using.Uid, eventArgs.User.Uid, Owner.Uid, 0f, 0.25f, _cuttingQuality)) 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))
|
2021-09-20 13:39:05 +02:00
|
|
|
EntitySystem.Get<StackSystem>().SetCount(droppedEnt.Uid, 1, stack);
|
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,
|
|
|
|
|
}
|
|
|
|
|
}
|