Files
tbd-station-14/Content.Server/Wires/ComponentWireAction.cs
goet 855547a2d4 Ensure wires can always be cut (#32447)
ensure wires are always cut
2024-11-23 12:41:37 +01:00

42 lines
1.6 KiB
C#

using Content.Shared.Wires;
namespace Content.Server.Wires;
/// <summary>
/// convenience class for wires that depend on the existence of some component to function. Slightly reduces boilerplate.
/// </summary>
public abstract partial class ComponentWireAction<TComponent> : BaseWireAction where TComponent : Component
{
public abstract StatusLightState? GetLightState(Wire wire, TComponent component);
public override StatusLightState? GetLightState(Wire wire)
{
return EntityManager.TryGetComponent(wire.Owner, out TComponent? component)
? GetLightState(wire, component)
: StatusLightState.Off;
}
public abstract bool Cut(EntityUid user, Wire wire, TComponent component);
public abstract bool Mend(EntityUid user, Wire wire, TComponent component);
public abstract void Pulse(EntityUid user, Wire wire, TComponent component);
public override bool Cut(EntityUid user, Wire wire)
{
base.Cut(user, wire);
// if the entity doesn't exist, we need to return true otherwise the wire sprite is never updated
return EntityManager.TryGetComponent(wire.Owner, out TComponent? component) ? Cut(user, wire, component) : true;
}
public override bool Mend(EntityUid user, Wire wire)
{
base.Mend(user, wire);
return EntityManager.TryGetComponent(wire.Owner, out TComponent? component) ? Mend(user, wire, component) : true;
}
public override void Pulse(EntityUid user, Wire wire)
{
base.Pulse(user, wire);
if (EntityManager.TryGetComponent(wire.Owner, out TComponent? component))
Pulse(user, wire, component);
}
}