diff --git a/Content.Shared/ADT/Roles/JobRequirement/SexRequirement.cs b/Content.Shared/ADT/Roles/JobRequirement/SexRequirement.cs new file mode 100644 index 00000000000..3f114fc7399 --- /dev/null +++ b/Content.Shared/ADT/Roles/JobRequirement/SexRequirement.cs @@ -0,0 +1,61 @@ +using System.Diagnostics.CodeAnalysis; +using System.Text; +using Content.Shared.Preferences; +using JetBrains.Annotations; +using Robust.Shared.Utility; +using Content.Shared.Humanoid; +using Robust.Shared.Prototypes; +using Robust.Shared.Serialization; + +namespace Content.Shared.Roles +{ + /// + /// Requires the character to be of a specified sex. + /// + [UsedImplicitly] + [Serializable, NetSerializable] + public sealed partial class SexRequirement : JobRequirement + { + [DataField(required: true)] + public HashSet AllowedSex = new(); + + /// + /// Проверка, соответствует ли персонаж требуемому полу + /// + /// Менеджер сущностей + /// Менеджер прототипов + /// Профиль персонажа + /// Время игры + /// Причина отказа, если не прошел проверку + /// Возвращает true, если проверка пройдена, иначе false + public override bool Check(IEntityManager entManager, + IPrototypeManager protoManager, + HumanoidCharacterProfile? profile, + IReadOnlyDictionary playTimes, + [NotNullWhen(false)] out FormattedMessage? reason) + { + reason = new FormattedMessage(); + + if (profile is null) + return true; + + var sb = new StringBuilder(); + sb.Append("[color=yellow]"); // Красим в жёлтый + + // Преобразование коллекции AllowedSex в строку для отображения + sb.Append(string.Join(", ", AllowedSex)); + + sb.Append("[/color]"); + + if (!Inverted) + { + reason = FormattedMessage.FromMarkupPermissive($"{Loc.GetString("role-timer-whitelisted-sex")}\n{sb}"); + + if (!AllowedSex.Contains(profile.Sex)) + return false; + } + + return true; + } + } +} diff --git a/Resources/Locale/ru-RU/ADT/Job/role-requirements.ftl b/Resources/Locale/ru-RU/ADT/Job/role-requirements.ftl new file mode 100644 index 00000000000..c512ab797ee --- /dev/null +++ b/Resources/Locale/ru-RU/ADT/Job/role-requirements.ftl @@ -0,0 +1 @@ +role-timer-whitelisted-sex = Ваш персонаж должен иметь следующий пол для этой роли: