ModifyLungGas.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Content.Server.Body.Components;
  2. using Content.Shared.Atmos;
  3. using Content.Shared.EntityEffects;
  4. using Robust.Shared.Prototypes;
  5. namespace Content.Server.EntityEffects.Effects;
  6. public sealed partial class ModifyLungGas : EntityEffect
  7. {
  8. [DataField("ratios", required: true)]
  9. private Dictionary<Gas, float> _ratios = default!;
  10. // JUSTIFICATION: This is internal magic that players never directly interact with.
  11. protected override string? ReagentEffectGuidebookText(IPrototypeManager prototype, IEntitySystemManager entSys)
  12. => null;
  13. public override void Effect(EntityEffectBaseArgs args)
  14. {
  15. LungComponent? lung;
  16. float amount = 1f;
  17. if (args is EntityEffectReagentArgs reagentArgs)
  18. {
  19. if (!args.EntityManager.TryGetComponent<LungComponent>(reagentArgs.OrganEntity, out var organLung))
  20. return;
  21. lung = organLung;
  22. amount = reagentArgs.Quantity.Float();
  23. }
  24. else
  25. {
  26. if (!args.EntityManager.TryGetComponent<LungComponent>(args.TargetEntity, out var organLung)) //Likely needs to be modified to ensure it works correctly
  27. return;
  28. lung = organLung;
  29. }
  30. if (lung != null)
  31. {
  32. foreach (var (gas, ratio) in _ratios)
  33. {
  34. var quantity = ratio * amount / Atmospherics.BreathMolesToReagentMultiplier;
  35. if (quantity < 0)
  36. quantity = Math.Max(quantity, -lung.Air[(int) gas]);
  37. lung.Air.AdjustMoles(gas, quantity);
  38. }
  39. }
  40. }
  41. }