MassHallucinationsRule.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Content.Server.GameTicking.Rules.Components;
  2. using Content.Server.StationEvents.Components;
  3. using Content.Server.Traits.Assorted;
  4. using Content.Shared.GameTicking.Components;
  5. using Content.Shared.Humanoid;
  6. using Content.Shared.Mind.Components;
  7. using Content.Shared.Traits.Assorted;
  8. namespace Content.Server.StationEvents.Events;
  9. public sealed class MassHallucinationsRule : StationEventSystem<MassHallucinationsRuleComponent>
  10. {
  11. [Dependency] private readonly ParacusiaSystem _paracusia = default!;
  12. protected override void Started(EntityUid uid, MassHallucinationsRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
  13. {
  14. base.Started(uid, component, gameRule, args);
  15. var query = EntityQueryEnumerator<MindContainerComponent, HumanoidAppearanceComponent>();
  16. while (query.MoveNext(out var ent, out _, out _))
  17. {
  18. if (!EnsureComp<ParacusiaComponent>(ent, out var paracusia))
  19. {
  20. _paracusia.SetSounds(ent, component.Sounds, paracusia);
  21. _paracusia.SetTime(ent, component.MinTimeBetweenIncidents, component.MaxTimeBetweenIncidents, paracusia);
  22. _paracusia.SetDistance(ent, component.MaxSoundDistance);
  23. component.AffectedEntities.Add(ent);
  24. }
  25. }
  26. }
  27. protected override void Ended(EntityUid uid, MassHallucinationsRuleComponent component, GameRuleComponent gameRule, GameRuleEndedEvent args)
  28. {
  29. base.Ended(uid, component, gameRule, args);
  30. foreach (var ent in component.AffectedEntities)
  31. {
  32. RemComp<ParacusiaComponent>(ent);
  33. }
  34. component.AffectedEntities.Clear();
  35. }
  36. }