#nullable enable
using System.Threading.Tasks;
using Content.Server.GameObjects.Components.Interactable;
using Content.Server.GameObjects.Components.Stack;
using Content.Shared.GameObjects.Components.Interactable;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Interfaces.GameObjects.Components;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Power
{
///
/// Allows the attached entity to be destroyed by a cutting tool, dropping a piece of wire.
///
[RegisterComponent]
public class WireComponent : Component, IInteractUsing
{
public override string Name => "Wire";
[ViewVariables]
[DataField("wireDroppedOnCutPrototype")]
private string? _wireDroppedOnCutPrototype = "HVWireStack1";
///
/// Checked by to determine if there is
/// already a wire of a type on a tile.
///
[ViewVariables]
public WireType WireType => _wireType;
[DataField("wireType")]
private WireType _wireType = WireType.HighVoltage;
async Task IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
{
if (_wireDroppedOnCutPrototype == null)
return false;
if (!eventArgs.Using.TryGetComponent(out var tool)) return false;
if (!await tool.UseTool(eventArgs.User, Owner, 0.25f, ToolQuality.Cutting)) return false;
Owner.Delete();
var droppedEnt = Owner.EntityManager.SpawnEntity(_wireDroppedOnCutPrototype, eventArgs.ClickLocation);
// TODO: Literally just use a prototype that has a single thing in the stack, it's not that complicated...
if (droppedEnt.HasComponent())
Owner.EntityManager.EventBus.RaiseLocalEvent(droppedEnt.Uid, new StackChangeCountEvent(1), false);
return true;
}
}
public enum WireType
{
HighVoltage,
MediumVoltage,
Apc,
}
}