Files
tbd-station-14/Content.Server/Wires/CutWireOnMapInitSystem.cs
Tayrtahn a1a12194a5 Make the station start with random broken wiring (#26695)
Random wire cutting on round start
2024-04-04 17:28:09 +11:00

35 lines
1.0 KiB
C#

using Robust.Shared.Random;
namespace Content.Server.Wires;
/// <summary>
/// Handles cutting a random wire on devices that have <see cref="CutWireOnMapInitComponent"/>.
/// </summary>
public sealed partial class CutWireOnMapInitSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<CutWireOnMapInitComponent, MapInitEvent>(OnMapInit, after: [typeof(WiresSystem)]);
}
private void OnMapInit(Entity<CutWireOnMapInitComponent> entity, ref MapInitEvent args)
{
if (TryComp<WiresComponent>(entity, out var panel) && panel.WiresList.Count > 0)
{
// Pick a random wire
var targetWire = _random.Pick(panel.WiresList);
// Cut the wire
if (targetWire.Action == null || targetWire.Action.Cut(EntityUid.Invalid, targetWire))
targetWire.IsCut = true;
}
// Our work here is done
RemCompDeferred(entity, entity.Comp);
}
}