From: Tayrtahn Date: Thu, 4 Apr 2024 06:28:09 +0000 (-0400) Subject: Make the station start with random broken wiring (#26695) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=a1a12194a58591fade0468cc0889ae69ed4bd292;p=space-station-14.git Make the station start with random broken wiring (#26695) Random wire cutting on round start --- diff --git a/Content.Server/GameTicking/Rules/VariationPass/Components/CutWireVariationPassComponent.cs b/Content.Server/GameTicking/Rules/VariationPass/Components/CutWireVariationPassComponent.cs new file mode 100644 index 0000000000..dc9a582ec9 --- /dev/null +++ b/Content.Server/GameTicking/Rules/VariationPass/Components/CutWireVariationPassComponent.cs @@ -0,0 +1,29 @@ +using Content.Shared.Whitelist; + +namespace Content.Server.GameTicking.Rules.VariationPass.Components; + +/// +/// Handles cutting a random wire on random devices around the station. +/// +[RegisterComponent] +public sealed partial class CutWireVariationPassComponent : Component +{ + /// + /// Blacklist of hackable entities that should not be chosen to + /// have wires cut. + /// + [DataField] + public EntityWhitelist Blacklist = new(); + + /// + /// Chance for an individual wire to be cut. + /// + [DataField] + public float WireCutChance = 0.05f; + + /// + /// Maximum number of wires that can be cut stationwide. + /// + [DataField] + public int MaxWiresCut = 10; +} diff --git a/Content.Server/GameTicking/Rules/VariationPass/CutWireVariationPassSystem.cs b/Content.Server/GameTicking/Rules/VariationPass/CutWireVariationPassSystem.cs new file mode 100644 index 0000000000..fd94c74ac8 --- /dev/null +++ b/Content.Server/GameTicking/Rules/VariationPass/CutWireVariationPassSystem.cs @@ -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; + +/// +/// Handles cutting a random wire on random devices around the station. +/// This system identifies target devices and adds to them. +/// The actual wire cutting is handled by . +/// +public sealed class CutWireVariationPassSystem : VariationPassSystem +{ + protected override void ApplyVariation(Entity ent, ref StationVariationPassEvent args) + { + var wiresCut = 0; + var query = AllEntityQuery(); + 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(uid); + wiresCut++; + + // Limit max wires cut + if (wiresCut >= ent.Comp.MaxWiresCut) + break; + } + } + } +} diff --git a/Content.Server/Wires/CutWireOnMapInitComponent.cs b/Content.Server/Wires/CutWireOnMapInitComponent.cs new file mode 100644 index 0000000000..4a4345e053 --- /dev/null +++ b/Content.Server/Wires/CutWireOnMapInitComponent.cs @@ -0,0 +1,10 @@ +namespace Content.Server.Wires; + +/// +/// Picks a random wire on the entity's and cuts it. +/// Runs at MapInit and removes itself afterwards. +/// +[RegisterComponent] +public sealed partial class CutWireOnMapInitComponent : Component +{ +} diff --git a/Content.Server/Wires/CutWireOnMapInitSystem.cs b/Content.Server/Wires/CutWireOnMapInitSystem.cs new file mode 100644 index 0000000000..1de1d78630 --- /dev/null +++ b/Content.Server/Wires/CutWireOnMapInitSystem.cs @@ -0,0 +1,34 @@ +using Robust.Shared.Random; + +namespace Content.Server.Wires; + +/// +/// Handles cutting a random wire on devices that have . +/// +public sealed partial class CutWireOnMapInitSystem : EntitySystem +{ + [Dependency] private readonly IRobustRandom _random = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnMapInit, after: [typeof(WiresSystem)]); + } + + private void OnMapInit(Entity entity, ref MapInitEvent args) + { + if (TryComp(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); + } +} diff --git a/Resources/Prototypes/GameRules/roundstart.yml b/Resources/Prototypes/GameRules/roundstart.yml index 21ad1310de..29ede4fc90 100644 --- a/Resources/Prototypes/GameRules/roundstart.yml +++ b/Resources/Prototypes/GameRules/roundstart.yml @@ -142,6 +142,7 @@ - id: BasicTrashVariationPass - id: SolidWallRustingVariationPass - id: ReinforcedWallRustingVariationPass + - id: CutWireVariationPass - id: BasicPuddleMessVariationPass prob: 0.99 orGroup: puddleMess diff --git a/Resources/Prototypes/GameRules/variation.yml b/Resources/Prototypes/GameRules/variation.yml index 8721003c83..7424fc2854 100644 --- a/Resources/Prototypes/GameRules/variation.yml +++ b/Resources/Prototypes/GameRules/variation.yml @@ -119,3 +119,15 @@ tilesPerSpillAverage: 150 tilesPerSpillStdDev: 10 randomPuddleSolutionFill: RandomFillTrashPuddleBloodbath + +- type: entity + id: CutWireVariationPass + parent: BaseVariationPass + noSpawn: true + components: + - type: CutWireVariationPass + wireCutChance: 0.01 + maxWiresCut: 20 + blacklist: + components: + - ParticleAcceleratorControlBox