diff --git a/Content.Client/_Sunrise/Restrict/RestrictSystem.cs b/Content.Client/_Sunrise/Restrict/RestrictSystem.cs new file mode 100644 index 0000000000..18680a5eea --- /dev/null +++ b/Content.Client/_Sunrise/Restrict/RestrictSystem.cs @@ -0,0 +1,6 @@ +using Content.Shared._Sunrise.Restrict; + +namespace Content.Client._Sunrise.Restrict; +public sealed partial class RestrictSystem : SharedRestrictSystem +{ +} diff --git a/Content.Server/_Sunrise/Restrict/RestrictSystem.cs b/Content.Server/_Sunrise/Restrict/RestrictSystem.cs new file mode 100644 index 0000000000..1128011691 --- /dev/null +++ b/Content.Server/_Sunrise/Restrict/RestrictSystem.cs @@ -0,0 +1,6 @@ +using Content.Shared._Sunrise.Restrict; + +namespace Content.Server._Sunrise.Restrict; +public sealed partial class RestrictSystem : SharedRestrictSystem +{ +} diff --git a/Content.Shared/_Sunrise/Restrict/RestrictByUserTagComponent.cs b/Content.Shared/_Sunrise/Restrict/RestrictByUserTagComponent.cs new file mode 100644 index 0000000000..f403b3e3da --- /dev/null +++ b/Content.Shared/_Sunrise/Restrict/RestrictByUserTagComponent.cs @@ -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> Contains = []; + + [DataField, AutoNetworkedField] + public List> DoestContain = []; + + [DataField, AutoNetworkedField] + public List Messages = []; +} diff --git a/Content.Shared/_Sunrise/Restrict/SharedRestrictSystem.cs b/Content.Shared/_Sunrise/Restrict/SharedRestrictSystem.cs new file mode 100644 index 0000000000..b7dca1abf5 --- /dev/null +++ b/Content.Shared/_Sunrise/Restrict/SharedRestrictSystem.cs @@ -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(OnAttemptMelee); + SubscribeLocalEvent(OnAttemptInteract); + SubscribeLocalEvent(OnShotAttempt); + } + + private void OnAttemptInteract(Entity 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 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 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)); + } + } +}