LightFlickerArtifactSystem.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Content.Server.Ghost;
  2. using Content.Server.Light.Components;
  3. using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
  4. using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
  5. using Robust.Shared.Random;
  6. namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;
  7. /// <summary>
  8. /// This handles...
  9. /// </summary>
  10. public sealed class LightFlickerArtifactSystem : EntitySystem
  11. {
  12. [Dependency] private readonly IRobustRandom _random = default!;
  13. [Dependency] private readonly EntityLookupSystem _lookup = default!;
  14. [Dependency] private readonly GhostSystem _ghost = default!;
  15. /// <inheritdoc/>
  16. public override void Initialize()
  17. {
  18. SubscribeLocalEvent<LightFlickerArtifactComponent, ArtifactActivatedEvent>(OnActivated);
  19. }
  20. private void OnActivated(EntityUid uid, LightFlickerArtifactComponent component, ArtifactActivatedEvent args)
  21. {
  22. var lights = GetEntityQuery<PoweredLightComponent>();
  23. foreach (var light in _lookup.GetEntitiesInRange(uid, component.Radius, LookupFlags.StaticSundries ))
  24. {
  25. if (!lights.HasComponent(light))
  26. continue;
  27. if (!_random.Prob(component.FlickerChance))
  28. continue;
  29. _ghost.DoGhostBooEvent(light);
  30. }
  31. }
  32. }