Skip to content

Commit

Permalink
Add role checks (like IsScp) to Role Extensions / RoleTypeId (#177)
Browse files Browse the repository at this point in the history
* feat: add IsScp to RoleExtensions

* Discard changes to EXILED/EXILED.props

* style: move IsScp next to IsFpcRole

* feat: add more Is checks

* style: add back trailing commas

* feat: update player to use RoleExtensions

* fix: IsHuman

* fix: Player.IsHuman

* feat: facility guard are not NTF

* docs: IsNtf and IsMilitary don't include fac guards

* feat: revert back useless changes

* feat: remove IsHuman to avoid conflicts

---------

Co-authored-by: VALERA771 <72030575+VALERA771@users.noreply.github.com>
Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 20, 2024
1 parent ef52b45 commit debe235
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions EXILED/Exiled.API/Extensions/RoleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,48 @@ public static bool TryGetRoleBase<T>(this RoleTypeId roleType, out T roleBase)
/// <returns>Returns whether <paramref name="roleType"/> is an <see cref="IFpcRole"/> or not.</returns>
public static bool IsFpcRole(this RoleTypeId roleType) => roleType.GetRoleBase() is IFpcRole;

/// <summary>
/// Checks if the role is an SCP role.
/// </summary>
/// <param name="roleType">The <see cref="RoleTypeId"/>.</param>
/// <returns>A boolean which is true when the role is an SCP role.</returns>
public static bool IsScp(this RoleTypeId roleType) => roleType.GetTeam() == Team.SCPs;

/// <summary>
/// Checks if the role is a dead role.
/// </summary>
/// <param name="roleType">The <see cref="RoleTypeId"/>.</param>
/// <returns>A boolean which is true when the role is a dead role.</returns>
public static bool IsDead(this RoleTypeId roleType) => roleType.GetTeam() == Team.Dead;

/// <summary>
/// Checks if the role is an NTF role.
/// </summary>
/// <param name="roleType">The <see cref="RoleTypeId"/>.</param>
/// <returns>A boolean which is true when the role is an NTF role. Does not include Facility Guards.</returns>
public static bool IsNtf(this RoleTypeId roleType) => roleType.GetTeam() == Team.FoundationForces && roleType != RoleTypeId.FacilityGuard;

/// <summary>
/// Checks if the role is a Chaos role.
/// </summary>
/// <param name="roleType">The <see cref="RoleTypeId"/>.</param>
/// <returns>A boolean which is true when the role is a Chaos role.</returns>
public static bool IsChaos(this RoleTypeId roleType) => roleType.GetTeam() == Team.ChaosInsurgency;

/// <summary>
/// Checks if the role is a military role (Chaos Insurgency or NTF).
/// </summary>
/// <param name="roleType">The <see cref="RoleTypeId"/>.</param>
/// <returns>A boolean which is true when the role is a military role. Does not include Facility Guards.</returns>
public static bool IsMilitary(this RoleTypeId roleType) => roleType.IsNtf() || roleType.IsChaos();

/// <summary>
/// Checks if the role is a civilian role (Scientists and Class-D).
/// </summary>
/// <param name="roleType">The <see cref="RoleTypeId"/>.</param>
/// <returns>A boolean which is true when the role is a civilian role.</returns>
public static bool IsCivilian(this RoleTypeId roleType) => roleType == RoleTypeId.ClassD || roleType == RoleTypeId.Scientist;

This comment has been minimized.

Copy link
@adarkaz

adarkaz Nov 20, 2024

💀


/// <summary>
/// Gets a random spawn point of a <see cref="RoleTypeId"/>.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion EXILED/Exiled.API/Features/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ public ScpSpawnPreferences.SpawnPreferences ScpPreferences
/// Gets a value indicating whether or not the player's <see cref="RoleTypeId"/> is any SCP.
/// Equivalent to checking the player's <see cref="Team"/>.
/// </summary>
public bool IsScp => Role?.Team is Team.SCPs;
public bool IsScp => Role?.Type.IsScp() ?? false;

/// <summary>
/// Gets a value indicating whether or not the player's <see cref="RoleTypeId"/> is any human rank.
Expand Down

0 comments on commit debe235

Please sign in to comment.