Files
tbd-station-14/Content.Server/StationEvents/Events/VentClogRule.cs
Moony e92a8fedab Refactor stations to properly use entity prototypes. (stationsv3) (#16570)
* Update StationSpawningSystem.cs

Web-edit to allow feeding in an existing entity.

* Update StationSpawningSystem.cs

value type moment

* Update StationSpawningSystem.cs

* Oh goddamnit this is a refactor now.

* awawawa

* aaaaaaaaaaa

* ee

* forgot records.

* no records? no records.

* What's in a name?

* Sloth forcing me to do the refactor properly smh.

* e

* optional evac in test.

* tests pls work

* awa

---------

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
2023-05-19 15:45:09 -05:00

63 lines
2.5 KiB
C#

using Content.Server.Atmos.Piping.Unary.Components;
using Content.Server.Station.Components;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.Random;
using System.Linq;
using Content.Server.Chemistry.Components;
using Content.Server.Fluids.EntitySystems;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.StationEvents.Components;
namespace Content.Server.StationEvents.Events;
[UsedImplicitly]
public sealed class VentClogRule : StationEventSystem<VentClogRuleComponent>
{
[Dependency] private readonly SmokeSystem _smoke = default!;
protected override void Started(EntityUid uid, VentClogRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);
if (!TryGetRandomStation(out var chosenStation))
return;
// TODO: "safe random" for chems. Right now this includes admin chemicals.
var allReagents = PrototypeManager.EnumeratePrototypes<ReagentPrototype>()
.Where(x => !x.Abstract)
.Select(x => x.ID).ToList();
// TODO: This is gross, but not much can be done until event refactor, which needs Dynamic.
var mod = (float) Math.Sqrt(GetSeverityModifier());
foreach (var (_, transform) in EntityManager.EntityQuery<GasVentPumpComponent, TransformComponent>())
{
if (CompOrNull<StationMemberComponent>(transform.GridUid)?.Station != chosenStation)
{
continue;
}
var solution = new Solution();
if (!RobustRandom.Prob(Math.Min(0.33f * mod, 1.0f)))
continue;
var pickAny = RobustRandom.Prob(Math.Min(0.05f * mod, 1.0f));
var reagent = RobustRandom.Pick(pickAny ? allReagents : component.SafeishVentChemicals);
var weak = component.WeakReagents.Contains(reagent);
var quantity = (weak ? component.WeakReagentQuantity : component.ReagentQuantity) * mod;
solution.AddReagent(reagent, quantity);
var foamEnt = Spawn("Foam", transform.Coordinates);
var smoke = EnsureComp<SmokeComponent>(foamEnt);
smoke.SpreadAmount = weak ? component.WeakSpread : component.Spread;
_smoke.Start(foamEnt, smoke, solution, component.Time);
Audio.PlayPvs(component.Sound, transform.Coordinates);
}
}
}