fish-station/Content.Shared/_Sunrise/Biocode/BiocodeSystem.cs
banumbas 2dfac23510
Бола синдиката и СБ (#3300)
Co-authored-by: worstplayerever <worstplayerever912@gmail.com>
Co-authored-by: Vigers Ray <60344369+VigersRay@users.noreply.github.com>
2025-12-25 20:02:09 +03:00

41 lines
1.2 KiB
C#

using Content.Shared.NPC.Components;
using Content.Shared.Popups;
namespace Content.Shared._Sunrise.Biocode;
public sealed class BiocodeSystem : EntitySystem
{
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<BiocodeComponent, AttemptThrowBiocodeEvent>(OnAttemptThrowBiocode);
}
public bool CanUse(EntityUid user, HashSet<string> factions)
{
var canUse = false;
if (!TryComp<NpcFactionMemberComponent>(user, out var npcFactionMemberComponent))
return canUse;
foreach (var faction in npcFactionMemberComponent.Factions)
{
if (factions.Contains(faction))
canUse = true;
}
return canUse;
}
private void OnAttemptThrowBiocode(EntityUid uid, BiocodeComponent component, ref AttemptThrowBiocodeEvent args)
{
if (args.User == null || CanUse(args.User.Value, component.Factions))
return;
if (!string.IsNullOrEmpty(component.AlertText))
_popup.PopupEntity(component.AlertText, args.User.Value, args.User.Value);
args.Cancelled = true;
}
}