restrict by tag system (#1586)

This commit is contained in:
iertis 2025-07-08 14:14:11 +05:00 committed by GitHub
parent 0d72c1bd9e
commit afdf832c07
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 84 additions and 0 deletions

View file

@ -0,0 +1,6 @@
using Content.Shared._Sunrise.Restrict;
namespace Content.Client._Sunrise.Restrict;
public sealed partial class RestrictSystem : SharedRestrictSystem
{
}

View file

@ -0,0 +1,6 @@
using Content.Shared._Sunrise.Restrict;
namespace Content.Server._Sunrise.Restrict;
public sealed partial class RestrictSystem : SharedRestrictSystem
{
}

View file

@ -0,0 +1,20 @@
using Content.Shared._Sunrise.Antags.Abductor;
using Content.Shared.Tag;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
namespace Content.Shared._Sunrise.Restrict;
[RegisterComponent, NetworkedComponent, Access(typeof(SharedAbductorSystem)), AutoGenerateComponentState]
// Taken from Starlight https://github.com/ss14Starlight/space-station-14
public sealed partial class RestrictByUserTagComponent : Component
{
[DataField, AutoNetworkedField]
public List<ProtoId<TagPrototype>> Contains = [];
[DataField, AutoNetworkedField]
public List<ProtoId<TagPrototype>> DoestContain = [];
[DataField, AutoNetworkedField]
public List<string> Messages = [];
}

View file

@ -0,0 +1,52 @@
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));
}
}
}