diff --git a/LabApi/Features/Extensions/RoleExtensions.cs b/LabApi/Features/Extensions/RoleExtensions.cs new file mode 100644 index 00000000..3ce24eaa --- /dev/null +++ b/LabApi/Features/Extensions/RoleExtensions.cs @@ -0,0 +1,73 @@ +using PlayerRoles; +using UnityEngine; + +namespace LabApi.Features.Extensions; + +/// +/// Adds extension methods to access information about s. +/// +public static class RoleExtensions +{ + /// + /// Gets the from a . + /// + /// The . + /// The . + public static PlayerRoleBase GetRoleBase(this RoleTypeId roleType) => PlayerRoleLoader.TryGetRoleTemplate(roleType, out PlayerRoleBase role) ? role : null!; + + /// + /// Gets the that a belongs to. + /// + /// The . + /// The . + public static Team GetTeam(this RoleTypeId roleType) => PlayerRoleLoader.AllRoles.TryGetValue(roleType, out PlayerRoleBase prb) ? prb.Team : Team.OtherAlive; + + /// + /// Gets the human-readable version of a 's name. + /// + /// The . + /// The name of the role. + public static string GetFullName(this RoleTypeId roleType) => roleType.GetRoleBase().RoleName; + + /// + /// Checks if the role is an SCP role. + /// + /// The . + /// A boolean which is true when the role is an SCP role. + public static bool IsScp(this RoleTypeId roleType) => roleType.GetTeam() == Team.SCPs; + + /// + /// Checks if the role is a dead role. + /// + /// The . + /// A boolean which is true when the role is a dead role. + public static bool IsDead(this RoleTypeId roleType) => roleType.GetTeam() == Team.Dead; + + /// + /// Checks if the role is an NTF role. + /// + /// The . + /// A boolean which is true when the role is an NTF role. Does not include Facility Guards. + public static bool IsNtf(this RoleTypeId roleType) => roleType.GetTeam() == Team.FoundationForces && roleType != RoleTypeId.FacilityGuard; + + /// + /// Checks if the role is a Chaos role. + /// + /// The . + /// A boolean which is true when the role is a Chaos role. + public static bool IsChaos(this RoleTypeId roleType) => roleType.GetTeam() == Team.ChaosInsurgency; + + /// + /// Checks if the role is a military role (Chaos Insurgency or NTF). + /// + /// The . + /// A boolean which is true when the role is a military role. + public static bool IsMilitary(this RoleTypeId roleType) => roleType.IsNtf() || roleType.IsChaos() || roleType == RoleTypeId.FacilityGuard; + + /// + /// Checks if the role is a civilian role (Scientists and Class-D). + /// + /// The . + /// A boolean which is true when the role is a civilian role. + public static bool IsCivilian(this RoleTypeId roleType) => roleType == RoleTypeId.ClassD || roleType == RoleTypeId.Scientist; +} \ No newline at end of file