Antag Rolebans (#35966)

Co-authored-by: beck-thompson <beck314159@hotmail.com>
Co-authored-by: Hannah Giovanna Dawson <karakkaraz@gmail.com>
This commit is contained in:
Errant
2025-09-17 23:59:07 +02:00
committed by GitHub
parent e1ba33814b
commit b692b6e33e
33 changed files with 898 additions and 283 deletions

View File

@@ -54,7 +54,7 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
SubscribeLocalEvent<MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<PlayerJoinedLobbyEvent>(OnPlayerJoinedLobby);
SubscribeLocalEvent<StationJobsGetCandidatesEvent>(OnStationJobsGetCandidates);
SubscribeLocalEvent<IsJobAllowedEvent>(OnIsJobAllowed);
SubscribeLocalEvent<IsRoleAllowedEvent>(OnIsRoleAllowed);
SubscribeLocalEvent<GetDisallowedJobsEvent>(OnGetDisallowedJobs);
_adminManager.OnPermsChanged += AdminPermsChanged;
}
@@ -86,6 +86,9 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
trackers.UnionWith(GetTimedRoles(player));
}
/// <summary>
/// Returns true if the player has an attached mob and it is alive (even if in critical).
/// </summary>
private bool IsPlayerAlive(ICommonSession session)
{
var attached = session.AttachedEntity;
@@ -176,9 +179,9 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
RemoveDisallowedJobs(ev.Player, ev.Jobs);
}
private void OnIsJobAllowed(ref IsJobAllowedEvent ev)
private void OnIsRoleAllowed(ref IsRoleAllowedEvent ev)
{
if (!IsAllowed(ev.Player, ev.JobId))
if (!IsAllowed(ev.Player, ev.Jobs) || !IsAllowed(ev.Player, ev.Antags))
ev.Cancelled = true;
}
@@ -187,10 +190,55 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
ev.Jobs.UnionWith(GetDisallowedJobs(ev.Player));
}
public bool IsAllowed(ICommonSession player, string role)
/// <summary>
/// Checks if the player meets role requirements.
/// </summary>
/// <param name="player">The player.</param>
/// <param name="jobs">A list of role prototype IDs</param>
/// <returns>Returns true if all requirements were met or there were no requirements.</returns>
public bool IsAllowed(ICommonSession player, List<ProtoId<JobPrototype>>? jobs)
{
if (!_prototypes.TryIndex<JobPrototype>(role, out var job) ||
!_cfg.GetCVar(CCVars.GameRoleTimers))
if (jobs is null)
return true;
foreach (var job in jobs)
{
if (!IsAllowed(player, job))
return false;
}
return true;
}
/// <summary>
/// Checks if the player meets role requirements.
/// </summary>
/// <param name="player">The player.</param>
/// <param name="antags">A list of role prototype IDs</param>
/// <returns>Returns true if all requirements were met or there were no requirements.</returns>
public bool IsAllowed(ICommonSession player, List<ProtoId<AntagPrototype>>? antags)
{
if (antags is null)
return true;
foreach (var antag in antags)
{
if (!IsAllowed(player, antag))
return false;
}
return true;
}
/// <summary>
/// Checks if the player meets role requirements.
/// </summary>
/// <param name="player">The player.</param>
/// <param name="job">A list of role prototype IDs</param>
/// <returns>Returns true if all requirements were met or there were no requirements.</returns>
public bool IsAllowed(ICommonSession player, ProtoId<JobPrototype> job)
{
if (!_cfg.GetCVar(CCVars.GameRoleTimers))
return true;
if (!_tracking.TryGetTrackerTimes(player, out var playTimes))
@@ -199,7 +247,43 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
playTimes = new Dictionary<string, TimeSpan>();
}
return JobRequirements.TryRequirementsMet(job, playTimes, out _, EntityManager, _prototypes, (HumanoidCharacterProfile?) _preferencesManager.GetPreferences(player.UserId).SelectedCharacter);
var requirements = _roles.GetRoleRequirements(job);
return JobRequirements.TryRequirementsMet(
requirements,
playTimes,
out _,
EntityManager,
_prototypes,
(HumanoidCharacterProfile?)
_preferencesManager.GetPreferences(player.UserId).SelectedCharacter);
}
/// <summary>
/// Checks if the player meets role requirements.
/// </summary>
/// <param name="player">The player.</param>
/// <param name="antag">A list of role prototype IDs</param>
/// <returns>Returns true if all requirements were met or there were no requirements.</returns>
public bool IsAllowed(ICommonSession player, ProtoId<AntagPrototype> antag)
{
if (!_cfg.GetCVar(CCVars.GameRoleTimers))
return true;
if (!_tracking.TryGetTrackerTimes(player, out var playTimes))
{
Log.Error($"Unable to check playtimes {Environment.StackTrace}");
playTimes = new Dictionary<string, TimeSpan>();
}
var requirements = _roles.GetRoleRequirements(antag);
return JobRequirements.TryRequirementsMet(
requirements,
playTimes,
out _,
EntityManager,
_prototypes,
(HumanoidCharacterProfile?)
_preferencesManager.GetPreferences(player.UserId).SelectedCharacter);
}
public HashSet<ProtoId<JobPrototype>> GetDisallowedJobs(ICommonSession player)