fish-station/Content.Shared/_Sunrise/Restrict/SharedRestrictSystem.cs
2025-07-08 05:14:11 -04:00

52 lines
2.1 KiB
C#

using System.Linq;
using Content.Shared.Interaction.Events;
using Content.Shared.Popups;
using Content.Shared.Tag;
using Content.Shared.Weapons.Melee.Events;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Network;
using Robust.Shared.Random;
namespace Content.Shared._Sunrise.Restrict;
public abstract partial class SharedRestrictSystem : EntitySystem
{
[Dependency] private readonly TagSystem _tagSystem = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
public override void Initialize()
{
SubscribeLocalEvent<RestrictByUserTagComponent, AttemptMeleeEvent>(OnAttemptMelee);
SubscribeLocalEvent<RestrictByUserTagComponent, InteractionAttemptEvent>(OnAttemptInteract);
SubscribeLocalEvent<RestrictByUserTagComponent, AttemptShootEvent>(OnShotAttempt);
}
private void OnAttemptInteract(Entity<RestrictByUserTagComponent> ent, ref InteractionAttemptEvent args)
{
if (!_tagSystem.HasAllTags(args.Uid, ent.Comp.Contains) || _tagSystem.HasAnyTag(args.Uid, ent.Comp.DoestContain))
{
args.Cancelled = true;
if (ent.Comp.Messages.Count != 0)
_popup.PopupClient(Loc.GetString(_random.Pick(ent.Comp.Messages)), args.Uid);
}
}
private void OnShotAttempt(Entity<RestrictByUserTagComponent> ent, ref AttemptShootEvent args)
{
if (!_tagSystem.HasAllTags(args.User, ent.Comp.Contains) || _tagSystem.HasAnyTag(args.User, ent.Comp.DoestContain))
{
args.Cancelled = true;
if (ent.Comp.Messages.Count != 0)
args.Message = Loc.GetString(_random.Pick(ent.Comp.Messages));
}
}
private void OnAttemptMelee(Entity<RestrictByUserTagComponent> ent, ref AttemptMeleeEvent args)
{
if(!_tagSystem.HasAllTags(args.User, ent.Comp.Contains) || _tagSystem.HasAnyTag(args.User, ent.Comp.DoestContain))
{
args.Cancelled = true;
if(ent.Comp.Messages.Count != 0)
args.Message = Loc.GetString(_random.Pick(ent.Comp.Messages));
}
}
}