DeathgaspSystem.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Content.Server.Chat.Systems;
  2. using Content.Server.Speech.Muting;
  3. using Content.Shared.Mobs;
  4. using Content.Shared.Speech.Muting;
  5. using Robust.Shared.Prototypes;
  6. namespace Content.Server.Mobs;
  7. /// <see cref="DeathgaspComponent"/>
  8. public sealed class DeathgaspSystem: EntitySystem
  9. {
  10. [Dependency] private readonly ChatSystem _chat = default!;
  11. public override void Initialize()
  12. {
  13. base.Initialize();
  14. SubscribeLocalEvent<DeathgaspComponent, MobStateChangedEvent>(OnMobStateChanged);
  15. }
  16. private void OnMobStateChanged(EntityUid uid, DeathgaspComponent component, MobStateChangedEvent args)
  17. {
  18. // don't deathgasp if they arent going straight from crit to dead
  19. if (args.NewMobState != MobState.Dead || args.OldMobState != MobState.Critical)
  20. return;
  21. Deathgasp(uid, component);
  22. }
  23. /// <summary>
  24. /// Causes an entity to perform their deathgasp emote, if they have one.
  25. /// </summary>
  26. public bool Deathgasp(EntityUid uid, DeathgaspComponent? component = null)
  27. {
  28. if (!Resolve(uid, ref component, false))
  29. return false;
  30. if (HasComp<MutedComponent>(uid))
  31. return false;
  32. _chat.TryEmoteWithChat(uid, component.Prototype, ignoreActionBlocker: true);
  33. return true;
  34. }
  35. }