Files
tbd-station-14/Content.Server/VendingMachines/VendingMachineEjectItemWireAction.cs
metalgearsloth 2d873a2cf2 Add static "IsPowered" method (#8434)
* Add static "IsPowered" method

* Use IsPowered in more places

Co-authored-by: wrexbe <wrexbe@protonmail.com>
2022-05-26 17:36:12 -07:00

68 lines
1.7 KiB
C#

using Content.Server.Wires;
using Content.Shared.VendingMachines;
using Content.Shared.Wires;
namespace Content.Server.VendingMachines;
[DataDefinition]
public sealed class VendingMachineEjectItemWireAction : BaseWireAction
{
private VendingMachineSystem _vendingMachineSystem = default!;
private Color _color = Color.Red;
private string _text = "VEND";
public override object? StatusKey { get; } = EjectWireKey.StatusKey;
public override StatusLightData? GetStatusLightData(Wire wire)
{
var lightState = StatusLightState.Off;
if (IsPowered(wire.Owner)
&& EntityManager.TryGetComponent(wire.Owner, out VendingMachineComponent vending))
{
lightState = vending.CanShoot
? StatusLightState.BlinkingFast
: StatusLightState.On;
}
return new StatusLightData(
_color,
lightState,
_text);
}
public override void Initialize()
{
base.Initialize();
_vendingMachineSystem = EntitySystem.Get<VendingMachineSystem>();
}
public override bool Cut(EntityUid user, Wire wire)
{
if (EntityManager.TryGetComponent(wire.Owner, out VendingMachineComponent vending))
{
vending.CanShoot = true;
}
return true;
}
public override bool Mend(EntityUid user, Wire wire)
{
if (EntityManager.TryGetComponent(wire.Owner, out VendingMachineComponent vending))
{
vending.CanShoot = false;
}
return true;
}
public override bool Pulse(EntityUid user, Wire wire)
{
_vendingMachineSystem.EjectRandom(wire.Owner, true);
return true;
}
}