using Content.Server.Chat.Systems;
using Content.Shared.Mobs;
using Content.Shared.Speech.Muting;
using Content.Shared.StatusEffectNew;
namespace Content.Server.Mobs;
///
/// A system that handles death gasps, an emote a character makes when they die.
///
///
public sealed partial class DeathgaspSystem : EntitySystem
{
[Dependency] private ChatSystem _chat = default!;
[Dependency] private StatusEffectsSystem _statusEffects = default!;
[SubscribeLocalEvent]
private void OnMobStateChanged(Entity ent, ref MobStateChangedEvent args)
{
// don't deathgasp if they arent going straight from crit to dead
if (args.NewMobState != MobState.Dead || args.OldMobState != MobState.Critical)
return;
Deathgasp(ent, ent.Comp);
}
///
/// Causes an entity to perform their deathgasp emote, if they have one.
///
public bool Deathgasp(EntityUid uid, DeathgaspComponent? component = null)
{
if (!Resolve(uid, ref component, false))
return false;
if (_statusEffects.HasEffectComp(uid))
return false;
_chat.TryEmoteWithChat(uid, component.Prototype, ignoreActionBlocker: true);
return true;
}
}