using Content.Server._Shitmed.DelayedDeath;
using Content.Shared._Shitmed.Body.Organ;
using Content.Shared.Body.Systems;
using Content.Shared.Mind;
using Content.Server.Popups;
using Content.Shared.Speech;
using Content.Shared.Standing;
using Content.Shared.Stunnable;
namespace Content.Server._Shitmed.Body.Systems;
///
/// This system handles behavior on entities when they lose their head or their brains are removed.
/// MindComponent fuckery should still be mainly handled on BrainSystem as usual.
///
public sealed class DebrainedSystem : EntitySystem
{
[Dependency] private readonly SharedBodySystem _bodySystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly StandingStateSystem _standingSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent(OnComponentInit);
SubscribeLocalEvent(OnComponentRemove);
SubscribeLocalEvent(OnSpeakAttempt);
SubscribeLocalEvent(OnStandAttempt);
}
private void OnComponentInit(EntityUid uid, DebrainedComponent _, ComponentInit args)
{
if (TerminatingOrDeleted(uid))
return;
EnsureComp(uid);
EnsureComp(uid);
_standingSystem.Down(uid);
}
private void OnComponentRemove(EntityUid uid, DebrainedComponent _, ComponentRemove args)
{
if (TerminatingOrDeleted(uid))
return;
RemComp(uid);
RemComp(uid);
if (_bodySystem.TryGetBodyOrganEntityComps(uid, out var _))
RemComp(uid);
}
private void OnSpeakAttempt(EntityUid uid, DebrainedComponent _, SpeakAttemptEvent args)
{
_popupSystem.PopupEntity(Loc.GetString("speech-muted"), uid, uid);
args.Cancel();
}
private void OnStandAttempt(EntityUid uid, DebrainedComponent _, StandAttemptEvent args)
{
args.Cancel();
}
}