Make the station start with random broken wiring (#26695)

Random wire cutting on round start
This commit is contained in:
Tayrtahn
2024-04-04 02:28:09 -04:00
committed by GitHub
parent 705f029424
commit a1a12194a5
6 changed files with 125 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
using Content.Server.GameTicking.Rules.VariationPass.Components;
using Content.Server.Wires;
using Robust.Shared.Random;
namespace Content.Server.GameTicking.Rules.VariationPass;
/// <summary>
/// Handles cutting a random wire on random devices around the station.
/// This system identifies target devices and adds <see cref="CutWireOnMapInitComponent"/> to them.
/// The actual wire cutting is handled by <see cref="CutWireOnMapInitSystem"/>.
/// </summary>
public sealed class CutWireVariationPassSystem : VariationPassSystem<CutWireVariationPassComponent>
{
protected override void ApplyVariation(Entity<CutWireVariationPassComponent> ent, ref StationVariationPassEvent args)
{
var wiresCut = 0;
var query = AllEntityQuery<WiresComponent, TransformComponent>();
while (query.MoveNext(out var uid, out _, out var transform))
{
// Ignore if not part of the station
if (!IsMemberOfStation((uid, transform), ref args))
continue;
// Check against blacklist
if (ent.Comp.Blacklist.IsValid(uid))
continue;
if (Random.Prob(ent.Comp.WireCutChance))
{
EnsureComp<CutWireOnMapInitComponent>(uid);
wiresCut++;
// Limit max wires cut
if (wiresCut >= ent.Comp.MaxWiresCut)
break;
}
}
}
}