From 8b2184a53c558bfdb7caaa5300ef0345a0398008 Mon Sep 17 00:00:00 2001 From: Moony Date: Sat, 26 Feb 2022 21:04:01 -0600 Subject: [PATCH] Two more events (#6906) * vent clog! * forgot you * Breaker flip event, to annoy engineering. * small fix. --- .../ReactionEffects/AreaReactionEffect.cs | 1 + .../ReactionEffects/FoamAreaReactionEffect.cs | 29 +++++++ .../Power/EntitySystems/ApcSystem.cs | 18 +++-- .../StationEvents/Events/BreakerFlip.cs | 40 ++++++++++ .../StationEvents/Events/VentClog.cs | 78 +++++++++++++++++++ .../station-events/events/breaker-flip.ftl | 1 + .../en-US/station-events/events/vent-clog.ftl | 1 + 7 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 Content.Server/StationEvents/Events/BreakerFlip.cs create mode 100644 Content.Server/StationEvents/Events/VentClog.cs create mode 100644 Resources/Locale/en-US/station-events/events/breaker-flip.ftl create mode 100644 Resources/Locale/en-US/station-events/events/vent-clog.ftl diff --git a/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs b/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs index 2c15a28d6a..262af0c1b4 100644 --- a/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs +++ b/Content.Server/Chemistry/ReactionEffects/AreaReactionEffect.cs @@ -3,6 +3,7 @@ using Content.Server.Chemistry.Components; using Content.Server.Chemistry.EntitySystems; using Content.Server.Coordinates.Helpers; using Content.Shared.Audio; +using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Reagent; using Content.Shared.Database; using Content.Shared.Sound; diff --git a/Content.Server/Chemistry/ReactionEffects/FoamAreaReactionEffect.cs b/Content.Server/Chemistry/ReactionEffects/FoamAreaReactionEffect.cs index 75087c94b8..24e9688c17 100644 --- a/Content.Server/Chemistry/ReactionEffects/FoamAreaReactionEffect.cs +++ b/Content.Server/Chemistry/ReactionEffects/FoamAreaReactionEffect.cs @@ -1,7 +1,14 @@ using Content.Server.Chemistry.Components; +using Content.Server.Coordinates.Helpers; +using Content.Shared.Audio; +using Content.Shared.Chemistry.Components; +using Content.Shared.Sound; using JetBrains.Annotations; +using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.IoC; +using Robust.Shared.Map; +using Robust.Shared.Player; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Server.Chemistry.ReactionEffects @@ -14,5 +21,27 @@ namespace Content.Server.Chemistry.ReactionEffects { return IoCManager.Resolve().GetComponentOrNull(entity); } + + public static void SpawnFoam(string entityPrototype, EntityCoordinates coords, Solution? contents, int amount, float duration, float spreadDelay, + float removeDelay, SoundSpecifier sound, IEntityManager? entityManager = null) + { + entityManager ??= IoCManager.Resolve(); + var ent = entityManager.SpawnEntity(entityPrototype, coords.SnapToGrid()); + + var areaEffectComponent = entityManager.GetComponentOrNull(ent); + + if (areaEffectComponent == null) + { + Logger.Error("Couldn't get AreaEffectComponent from " + entityPrototype); + IoCManager.Resolve().QueueDeleteEntity(ent); + return; + } + + if (contents != null) + areaEffectComponent.TryAddSolution(contents); + areaEffectComponent.Start(amount, duration, spreadDelay, removeDelay); + + SoundSystem.Play(Filter.Pvs(ent), sound.GetSound(), ent, AudioHelpers.WithVariation(0.125f)); + } } } diff --git a/Content.Server/Power/EntitySystems/ApcSystem.cs b/Content.Server/Power/EntitySystems/ApcSystem.cs index 3a529648a9..c7a1b64e60 100644 --- a/Content.Server/Power/EntitySystems/ApcSystem.cs +++ b/Content.Server/Power/EntitySystems/ApcSystem.cs @@ -57,11 +57,7 @@ namespace Content.Server.Power.EntitySystems if (access == null || _accessReader.IsAllowed(access, args.Session.AttachedEntity.Value)) { - component.MainBreakerEnabled = !component.MainBreakerEnabled; - Comp(uid).CanDischarge = component.MainBreakerEnabled; - - UpdateUIState(uid, component); - SoundSystem.Play(Filter.Pvs(uid), component.OnReceiveMessageSound.GetSound(), uid, AudioParams.Default.WithVolume(-2f)); + ApcToggleBreaker(uid, component); } else { @@ -70,6 +66,18 @@ namespace Content.Server.Power.EntitySystems } } + public void ApcToggleBreaker(EntityUid uid, ApcComponent? apc = null, PowerNetworkBatteryComponent? battery = null) + { + if (!Resolve(uid, ref apc, ref battery)) + return; + + apc.MainBreakerEnabled = !apc.MainBreakerEnabled; + battery.CanDischarge = apc.MainBreakerEnabled; + + UpdateUIState(uid, apc); + SoundSystem.Play(Filter.Pvs(uid), apc.OnReceiveMessageSound.GetSound(), uid, AudioParams.Default.WithVolume(-2f)); + } + private void OnEmagged(EntityUid uid, ApcComponent comp, GotEmaggedEvent args) { if(!comp.Emagged) diff --git a/Content.Server/StationEvents/Events/BreakerFlip.cs b/Content.Server/StationEvents/Events/BreakerFlip.cs new file mode 100644 index 0000000000..f115682fde --- /dev/null +++ b/Content.Server/StationEvents/Events/BreakerFlip.cs @@ -0,0 +1,40 @@ +using System.Linq; +using Content.Server.Power.Components; +using Content.Server.Power.EntitySystems; +using JetBrains.Annotations; +using Robust.Shared.Random; + +namespace Content.Server.StationEvents.Events; + +[UsedImplicitly] +public sealed class BreakerFlip : StationEvent +{ + [Dependency] private readonly IEntityManager _entityManager = default!; + [Dependency] private readonly IRobustRandom _random = default!; + + public override string Name => "BreakerFlip"; + public override string? StartAnnouncement => + Loc.GetString("station-event-breaker-flip-announcement", ("data", Loc.GetString(Loc.GetString($"random-sentience-event-data-{_random.Next(1, 6)}")))); + public override float Weight => WeightNormal; + protected override float EndAfter => 1.0f; + public override int? MaxOccurrences => 5; + public override int MinimumPlayers => 15; + + public override void Startup() + { + base.Startup(); + + var apcSys = EntitySystem.Get(); + var allApcs = _entityManager.EntityQuery().ToList(); + var toDisable = Math.Min(_random.Next(3, 7), allApcs.Count); + if (toDisable == 0) + return; + + _random.Shuffle(allApcs); + + for (var i = 0; i < toDisable; i++) + { + apcSys.ApcToggleBreaker(allApcs[i].Owner, allApcs[i]); + } + } +} diff --git a/Content.Server/StationEvents/Events/VentClog.cs b/Content.Server/StationEvents/Events/VentClog.cs new file mode 100644 index 0000000000..0bc12239e7 --- /dev/null +++ b/Content.Server/StationEvents/Events/VentClog.cs @@ -0,0 +1,78 @@ +using System.Linq; +using Content.Server.Atmos.Piping.Unary.Components; +using Content.Server.Chemistry.ReactionEffects; +using Content.Shared.Chemistry.Components; +using Content.Shared.Chemistry.Reagent; +using Content.Shared.Sound; +using JetBrains.Annotations; +using Robust.Shared.Map; +using Robust.Shared.Prototypes; +using Robust.Shared.Random; +using Robust.Shared.Utility; + +namespace Content.Server.StationEvents.Events; + +[UsedImplicitly] +public sealed class VentClog : StationEvent +{ + [Dependency] private readonly IRobustRandom _random = default!; + [Dependency] private readonly IEntityManager _entityManager = default!; + [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + + public override string Name => "VentClog"; + + public override string? StartAnnouncement => + Loc.GetString("station-event-vent-clog-start-announcement"); + + public override string? StartAudio => "/Audio/Announcements/bloblarm.ogg"; + + public override int EarliestStart => 15; + + public override int MinimumPlayers => 15; + + public override float Weight => WeightLow; + + public override int? MaxOccurrences => 2; + + // Give players time to reach cover. + protected override float StartAfter => 50f; + + protected override float EndAfter => 1.0f; + + public readonly IReadOnlyList SafeishVentChemicals = new[] + { + "Water", "Iron", "Oxygen", "Tritium", "Plasma", "SulfuricAcid", "Blood", "SpaceDrugs", "SpaceCleaner", "Flour", + "Nutriment", "Sugar", "SpaceLube", "Ethanol", "Mercury", "Ephedrine", "WeldingFuel" + }; + + public override void Startup() + { + base.Startup(); + + // TODO: "safe random" for chems. Right now this includes admin chemicals. + var allReagents = _prototypeManager.EnumeratePrototypes() + .Where(x => !x.Abstract) + .Select(x => x.ID).ToList(); + + // This is gross, but not much can be done until event refactor, which needs Dynamic. + var sound = new SoundPathSpecifier("/Audio/Effects/extinguish.ogg"); + + foreach (var (_, transform) in _entityManager.EntityQuery()) + { + var solution = new Solution(); + + if (_random.Prob(0.05f)) + { + solution.AddReagent(_random.Pick(allReagents), 100); + } + else + { + solution.AddReagent(_random.Pick(SafeishVentChemicals), 100); + } + + FoamAreaReactionEffect.SpawnFoam("Foam", transform.Coordinates, solution, _random.Next(2, 6), 20, 1, + 1, sound, _entityManager); + } + } + +} diff --git a/Resources/Locale/en-US/station-events/events/breaker-flip.ftl b/Resources/Locale/en-US/station-events/events/breaker-flip.ftl new file mode 100644 index 0000000000..b3ed9c8fce --- /dev/null +++ b/Resources/Locale/en-US/station-events/events/breaker-flip.ftl @@ -0,0 +1 @@ +station-event-breaker-flip-announcement = Based on { $data }, we have opted to disable specific APCs to avoid damage to equipment. Please contact the engineering department to re-enable them. diff --git a/Resources/Locale/en-US/station-events/events/vent-clog.ftl b/Resources/Locale/en-US/station-events/events/vent-clog.ftl new file mode 100644 index 0000000000..f87f9e241b --- /dev/null +++ b/Resources/Locale/en-US/station-events/events/vent-clog.ftl @@ -0,0 +1 @@ +station-event-vent-clog-start-announcement = The scrubbers network is experiencing a backpressure surge. Some ejection of contents may occur.