Skip to content
Merged
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();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently this includes Guards because of the other thing I mentioned, I think you should specify that this doesn't (or does if it's intended) include them

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should grab guards as they are military, but if you want the docs to be changed to mention guards are included in both foundation and military I can do that

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally I wouldn't count guards as military, that's why I'd like you to specifically mention if they're counted or not

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'll add smth to remove guards from military as I agree it's weird for them to be in there

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing from IsNtf

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you could specify in its docs that doesn't include guards that'd be great as well since some people might be confused

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just does
Ismilitary(this RoleTypeId roletype) => !roletype.IsCivilian()

I know this goes against what miki said but that what basegame believe for armor consumption of stamina for example

@VALERA771 VALERA771 Nov 20, 2024

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk can we count tutorial as civilian (iirc when I checked it last time RoleTypeId.Tutorial.IsCivilian() will return false)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tutorial is not civilian, no. so it will count as military, this change shouldn't be done @louis1706 as what I've done is perfect, this is just adding more work and more calculations for no reason.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically guard is a military class, I've said otherwise before because it doesn't make sense to me but that's how they're classified on the wiki, this method should reflect that

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way to late to say that now @Mikihero 😭

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make it work you can just add || roletype == RoleTypeId.FacilityGuard, I don't think there really is a better solution since negating IsCivilian would return shit like tutorial etc.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, but this PR has been merged, if I could directly commit I would


/// <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;

/// <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