ShuffleParticlesAnomalySystem.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using Content.Server.Anomaly.Components;
  2. using Content.Shared.Anomaly.Components;
  3. using Robust.Shared.Physics.Events;
  4. using Robust.Shared.Random;
  5. namespace Content.Server.Anomaly.Effects;
  6. public sealed class ShuffleParticlesAnomalySystem : EntitySystem
  7. {
  8. [Dependency] private readonly AnomalySystem _anomaly = default!;
  9. [Dependency] private readonly IRobustRandom _random = default!;
  10. public override void Initialize()
  11. {
  12. SubscribeLocalEvent<ShuffleParticlesAnomalyComponent, AnomalyPulseEvent>(OnPulse);
  13. SubscribeLocalEvent<ShuffleParticlesAnomalyComponent, StartCollideEvent>(OnStartCollide);
  14. }
  15. private void OnStartCollide(Entity<ShuffleParticlesAnomalyComponent> ent, ref StartCollideEvent args)
  16. {
  17. if (!TryComp<AnomalyComponent>(ent, out var anomaly))
  18. return;
  19. if (!HasComp<AnomalousParticleComponent>(args.OtherEntity))
  20. return;
  21. if (ent.Comp.ShuffleOnParticleHit && _random.Prob(ent.Comp.Prob))
  22. _anomaly.ShuffleParticlesEffect((ent, anomaly));
  23. }
  24. private void OnPulse(Entity<ShuffleParticlesAnomalyComponent> ent, ref AnomalyPulseEvent args)
  25. {
  26. if (!TryComp<AnomalyComponent>(ent, out var anomaly))
  27. return;
  28. if (ent.Comp.ShuffleOnPulse && _random.Prob(ent.Comp.Prob))
  29. {
  30. _anomaly.ShuffleParticlesEffect((ent, anomaly));
  31. }
  32. }
  33. }