using Content.Shared.Emag.Systems;
using Content.Shared.Mind;
using Content.Shared.Popups;
using Content.Shared.Silicons.Laws.Components;
using Content.Shared.Stunnable;
using Content.Shared.Wires;
using Robust.Shared.Audio;
namespace Content.Shared.Silicons.Laws;
///
/// This handles getting and displaying the laws for silicons.
///
public abstract partial class SharedSiliconLawSystem : EntitySystem
{
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedStunSystem _stunSystem = default!;
[Dependency] private readonly EmagSystem _emag = default!;
[Dependency] private readonly SharedMindSystem _mind = default!;
///
public override void Initialize()
{
InitializeUpdater();
SubscribeLocalEvent(OnGotEmagged);
}
private void OnGotEmagged(EntityUid uid, EmagSiliconLawComponent component, ref GotEmaggedEvent args)
{
if (!_emag.CompareFlag(args.Type, EmagType.Interaction))
return;
if (_emag.CheckFlag(uid, EmagType.Interaction))
return;
// prevent self-emagging
if (uid == args.UserUid)
{
_popup.PopupClient(Loc.GetString("law-emag-cannot-emag-self"), uid, args.UserUid);
return;
}
if (component.RequireOpenPanel &&
TryComp(uid, out var panel) &&
!panel.Open)
{
_popup.PopupClient(Loc.GetString("law-emag-require-panel"), uid, args.UserUid);
return;
}
var ev = new SiliconEmaggedEvent(args.UserUid);
RaiseLocalEvent(uid, ref ev);
component.OwnerName = Name(args.UserUid);
if (_mind.TryGetMind(uid, out var mindId, out _))
EnsureSubvertedSiliconRole(mindId);
_stunSystem.TryParalyze(uid, component.StunTime, true);
args.Handled = true;
}
public virtual void NotifyLawsChanged(EntityUid uid, SoundSpecifier? cue = null)
{
}
protected virtual void EnsureSubvertedSiliconRole(EntityUid mindId)
{
}
protected virtual void RemoveSubvertedSiliconRole(EntityUid mindId)
{
}
}
[ByRefEvent]
public record struct SiliconEmaggedEvent(EntityUid user);