1
0

DamageRandomPopupSystem.cs 889 B

123456789101112131415161718192021222324252627
  1. using Content.Server.Damage.Components;
  2. using Content.Server.Popups;
  3. using Content.Shared.Damage;
  4. using Robust.Shared.Player;
  5. using Robust.Shared.Random;
  6. namespace Content.Server.Damage.Systems;
  7. /// <summary>
  8. /// Outputs a random pop-up from the strings list when an object receives damage
  9. /// </summary>
  10. public sealed class DamageRandomPopupSystem : EntitySystem
  11. {
  12. [Dependency] private readonly PopupSystem _popupSystem = default!;
  13. [Dependency] private readonly IRobustRandom _random = default!;
  14. public override void Initialize()
  15. {
  16. base.Initialize();
  17. SubscribeLocalEvent<DamageRandomPopupComponent, DamageChangedEvent>(OnDamageChange);
  18. }
  19. private void OnDamageChange(EntityUid uid, DamageRandomPopupComponent component, DamageChangedEvent args)
  20. {
  21. _popupSystem.PopupEntity(Loc.GetString(_random.Pick(component.Popups)), uid);
  22. }
  23. }