From 4783886aee1c66e67f1356be8ba2dba3e8a60981 Mon Sep 17 00:00:00 2001 From: Kirus59 <145689588+Kirus59@users.noreply.github.com> Date: Fri, 11 Oct 2024 19:32:01 +0300 Subject: [PATCH] Role-ban check for antag roles (#2050) --- .../Lobby/UI/HumanoidProfileEditor.xaml.cs | 9 ++++++++- .../PlayTimeTracking/JobRequirementsManager.cs | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs index ac2c6130c574..6f1281571e08 100644 --- a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs +++ b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs @@ -664,7 +664,14 @@ public void RefreshAntags() selector.Select(Profile?.AntagPreferences.Contains(antag.ID) == true ? 0 : 1); var requirements = _entManager.System().GetAntagRequirement(antag); - if (!_requirements.CheckRoleRequirements(requirements, (HumanoidCharacterProfile?)_preferencesManager.Preferences?.SelectedCharacter, out var reason)) + // SS220 Add role-ban check begin + if (_requirements.IsRoleBaned(antag.ID, out var banReason)) + { + selector.LockRequirements(banReason); + Profile = Profile?.WithAntagPreference(antag.ID, false); + SetDirty(); + } // SS220 Add role-ban check end + else if (!_requirements.CheckRoleRequirements(requirements, (HumanoidCharacterProfile?)_preferencesManager.Preferences?.SelectedCharacter, out var reason)) // SS220 change 'if' -> 'else if' { selector.LockRequirements(reason); Profile = Profile?.WithAntagPreference(antag.ID, false); diff --git a/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs b/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs index b2ece555ad2a..7a59774f4a9d 100644 --- a/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs +++ b/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs @@ -190,4 +190,18 @@ public IReadOnlyDictionary GetPlayTimes(ICommonSession session return _roles; } + + // SS220 Add role-ban check begin + public bool IsRoleBaned(string role, [NotNullWhen(true)] out FormattedMessage? reason) + { + if (_roleBans.Contains($"Job:{role}")) + { + reason = FormattedMessage.FromUnformatted(Loc.GetString("role-ban")); + return true; + } + + reason = null; + return false; + } + // SS220 Add role-ban check end }