GasArtifactSystem.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Content.Server.Atmos;
  2. using Content.Server.Atmos.EntitySystems;
  3. using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
  4. using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
  5. using Content.Shared.Atmos;
  6. namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;
  7. public sealed class GasArtifactSystem : EntitySystem
  8. {
  9. [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
  10. public override void Initialize()
  11. {
  12. base.Initialize();
  13. SubscribeLocalEvent<GasArtifactComponent, ArtifactNodeEnteredEvent>(OnNodeEntered);
  14. SubscribeLocalEvent<GasArtifactComponent, ArtifactActivatedEvent>(OnActivate);
  15. }
  16. private void OnNodeEntered(EntityUid uid, GasArtifactComponent component, ArtifactNodeEnteredEvent args)
  17. {
  18. if (component.SpawnGas == null && component.PossibleGases.Count != 0)
  19. {
  20. var gas = component.PossibleGases[args.RandomSeed % component.PossibleGases.Count];
  21. component.SpawnGas = gas;
  22. }
  23. if (component.SpawnTemperature == null)
  24. {
  25. var temp = args.RandomSeed % component.MaxRandomTemperature - component.MinRandomTemperature +
  26. component.MinRandomTemperature;
  27. component.SpawnTemperature = temp;
  28. }
  29. }
  30. private void OnActivate(EntityUid uid, GasArtifactComponent component, ArtifactActivatedEvent args)
  31. {
  32. if (component.SpawnGas == null || component.SpawnTemperature == null)
  33. return;
  34. var environment = _atmosphereSystem.GetContainingMixture(uid, false, true);
  35. if (environment == null)
  36. return;
  37. if (environment.Pressure >= component.MaxExternalPressure)
  38. return;
  39. var merger = new GasMixture(1) { Temperature = component.SpawnTemperature.Value };
  40. merger.SetMoles(component.SpawnGas.Value, component.SpawnAmount);
  41. _atmosphereSystem.Merge(environment, merger);
  42. }
  43. }