VentClogRule.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using Content.Server.Atmos.Piping.Unary.Components;
  2. using Content.Server.Fluids.EntitySystems;
  3. using Content.Server.StationEvents.Components;
  4. using Content.Shared.Chemistry.Components;
  5. using Content.Shared.Chemistry.Reagent;
  6. using Content.Shared.GameTicking.Components;
  7. using Content.Shared.Station.Components;
  8. using JetBrains.Annotations;
  9. using Robust.Shared.Random;
  10. using System.Linq;
  11. namespace Content.Server.StationEvents.Events;
  12. [UsedImplicitly]
  13. public sealed class VentClogRule : StationEventSystem<VentClogRuleComponent>
  14. {
  15. [Dependency] private readonly SmokeSystem _smoke = default!;
  16. protected override void Started(EntityUid uid, VentClogRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
  17. {
  18. base.Started(uid, component, gameRule, args);
  19. if (!TryGetRandomStation(out var chosenStation))
  20. return;
  21. // TODO: "safe random" for chems. Right now this includes admin chemicals.
  22. var allReagents = PrototypeManager.EnumeratePrototypes<ReagentPrototype>()
  23. .Where(x => !x.Abstract)
  24. .Select(x => x.ID).ToList();
  25. foreach (var (_, transform) in EntityManager.EntityQuery<GasVentPumpComponent, TransformComponent>())
  26. {
  27. if (CompOrNull<StationMemberComponent>(transform.GridUid)?.Station != chosenStation)
  28. {
  29. continue;
  30. }
  31. var solution = new Solution();
  32. if (!RobustRandom.Prob(0.33f))
  33. continue;
  34. var pickAny = RobustRandom.Prob(0.05f);
  35. var reagent = RobustRandom.Pick(pickAny ? allReagents : component.SafeishVentChemicals);
  36. var weak = component.WeakReagents.Contains(reagent);
  37. var quantity = weak ? component.WeakReagentQuantity : component.ReagentQuantity;
  38. solution.AddReagent(reagent, quantity);
  39. var foamEnt = Spawn("Foam", transform.Coordinates);
  40. var spreadAmount = weak ? component.WeakSpread : component.Spread;
  41. _smoke.StartSmoke(foamEnt, solution, component.Time, spreadAmount);
  42. Audio.PlayPvs(component.Sound, transform.Coordinates);
  43. }
  44. }
  45. }