Added RoleID further util methods

This commit is contained in:
David Higueros committed 2026-07-09 23:44:46 -06:00
1 parent 6598cb6933
commit e7184c9592
2 files changed
+58 -2

No files matched your search

+57 -1
View File
@@ -1,4 +1,5 @@
using System;
using AmongUs.GameOptions;
using System;
namespace MiraAPI.Roles;
@@ -38,4 +39,59 @@ public static class RoleId
return roleId;
}
/// <summary>
/// Gets the ID of a role.
/// </summary>
/// <param name="role">The <see cref="ICustomRole"/> role.</param>
/// <returns>The ID as a ushort.</returns>
/// <exception cref="InvalidOperationException">Thrown when the role is not registered.</exception>
public static ushort Get(ICustomRole role)
{
return Get(role.GetType());
}
/// <summary>
/// Gets the ID of an <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">The type of the role.</typeparam>
/// <returns>The role ID as a <see cref="RoleTypes"/>.</returns>
/// <exception cref="InvalidOperationException">Thrown when the role is not registered.</exception>
public static RoleTypes GetType<T>() where T : ICustomRole
{
return (RoleTypes)Get<T>();
}
/// <summary>
/// Gets the ID of a role.
/// </summary>
/// <param name="type">The type of the role.</param>
/// <returns>The ID as a <see cref="RoleTypes"/>.</returns>
/// <exception cref="InvalidOperationException">Thrown when the role is not registered.</exception>
public static RoleTypes GetType(Type type)
{
return (RoleTypes)Get(type);
}
/// <summary>
/// Gets the <typeparamref name="T"/> role.
/// </summary>
/// <typeparam name="T">The type of the role.</typeparam>
/// <returns>The <see cref="RoleBehaviour"/> object.</returns>
/// <exception cref="InvalidOperationException">Thrown when the role is not registered.</exception>
public static RoleBehaviour GetRole<T>() where T : ICustomRole
{
return RoleManager.Instance.GetRole(GetType<T>());
}
/// <summary>
/// Gets the role from its type.
/// </summary>
/// <param name="type">The type of the role.</param>
/// <returns>The <see cref="RoleBehaviour"/> object.</returns>
/// <exception cref="InvalidOperationException">Thrown when the role is not registered.</exception>
public static RoleBehaviour GetRole(Type type)
{
return RoleManager.Instance.GetRole(GetType(type));
}
}
+1 -1
View File
@@ -43,7 +43,7 @@ public static class Extensions
}
return new NetData(
RoleId.Get(role.GetType()),
RoleId.Get(role),
BitConverter.GetBytes(count.Value).AddRangeToArray(BitConverter.GetBytes(chance.Value)));
}