ECS cable (#6141)
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Electrocution;
|
||||
using Content.Server.Stack;
|
||||
using Content.Server.Tools;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Shared.Tools;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.Power.Components
|
||||
{
|
||||
@@ -16,46 +12,25 @@ namespace Content.Server.Power.Components
|
||||
/// Allows the attached entity to be destroyed by a cutting tool, dropping a piece of cable.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class CableComponent : Component, IInteractUsing
|
||||
[Friend(typeof(CableSystem))]
|
||||
[ComponentProtoName("Cable")]
|
||||
public class CableComponent : Component
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
||||
|
||||
public override string Name => "Cable";
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("cableDroppedOnCutPrototype")]
|
||||
private string? _cableDroppedOnCutPrototype = "CableHVStack1";
|
||||
[DataField("cableDroppedOnCutPrototype", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public readonly string CableDroppedOnCutPrototype = "CableHVStack1";
|
||||
|
||||
[DataField("cuttingQuality", customTypeSerializer:typeof(PrototypeIdSerializer<ToolQualityPrototype>))]
|
||||
private string _cuttingQuality = "Cutting";
|
||||
public string CuttingQuality = "Cutting";
|
||||
|
||||
/// <summary>
|
||||
/// Checked by <see cref="CablePlacerComponent"/> to determine if there is
|
||||
/// already a cable of a type on a tile.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public CableType CableType => _cableType;
|
||||
[DataField("cableType")]
|
||||
private CableType _cableType = CableType.HighVoltage;
|
||||
public CableType CableType = CableType.HighVoltage;
|
||||
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (_cableDroppedOnCutPrototype == null)
|
||||
return false;
|
||||
|
||||
if (!await EntitySystem.Get<ToolSystem>().UseTool(eventArgs.Using, eventArgs.User, Owner, 0f, 0.25f, _cuttingQuality)) return false;
|
||||
|
||||
if (EntitySystem.Get<ElectrocutionSystem>().TryDoElectrifiedAct(Owner, eventArgs.User)) return false;
|
||||
|
||||
_entMan.DeleteEntity(Owner);
|
||||
var droppedEnt = _entMan.SpawnEntity(_cableDroppedOnCutPrototype, eventArgs.ClickLocation);
|
||||
|
||||
// TODO: Literally just use a prototype that has a single thing in the stack, it's not that complicated...
|
||||
if (_entMan.TryGetComponent<StackComponent?>(droppedEnt, out var stack))
|
||||
EntitySystem.Get<StackSystem>().SetCount(droppedEnt, 1, stack);
|
||||
|
||||
return true;
|
||||
}
|
||||
[DataField("cuttingDelay")]
|
||||
public float CuttingDelay = 0.25f;
|
||||
}
|
||||
|
||||
public enum CableType
|
||||
|
||||
Reference in New Issue
Block a user