diff --git a/MiraAPI/Roles/ICustomRole.cs b/MiraAPI/Roles/ICustomRole.cs index 4a630f4..42cc91c 100644 --- a/MiraAPI/Roles/ICustomRole.cs +++ b/MiraAPI/Roles/ICustomRole.cs @@ -81,7 +81,6 @@ public interface ICustomRole ParentMod.PluginConfig.TryGetEntry(NumConfigDefinition, out var numEntry); ParentMod.PluginConfig.TryGetEntry(ChanceConfigDefinition, out var chanceEntry); - // TODO: use the RoleID class when that branch is merged - return new NetData((uint)((RoleBehaviour)this).Role, BitConverter.GetBytes(numEntry.Value).AddRangeToArray(BitConverter.GetBytes(chanceEntry.Value))); + return new NetData(RoleId.Get(GetType()), BitConverter.GetBytes(numEntry.Value).AddRangeToArray(BitConverter.GetBytes(chanceEntry.Value))); } } \ No newline at end of file diff --git a/MiraAPI/Roles/RoleId.cs b/MiraAPI/Roles/RoleId.cs index f9d30c0..d1174f6 100644 --- a/MiraAPI/Roles/RoleId.cs +++ b/MiraAPI/Roles/RoleId.cs @@ -14,4 +14,14 @@ public class RoleId return roleId; } + + public static ushort Get(Type type) + { + if (!CustomRoleManager.RoleIds.TryGetValue(type, out var roleId)) + { + throw new InvalidOperationException($"Role {type} is not registered"); + } + + return roleId; + } } \ No newline at end of file