-
-
Notifications
You must be signed in to change notification settings - Fork 60
/
SetRoleRpc.cs
50 lines (40 loc) · 1.36 KB
/
SetRoleRpc.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using ExtraRoles.Roles;
using ExtraRolesMod;
using Hazel;
using Reactor;
using static ExtraRolesMod.ExtraRoles;
namespace ExtraRoles.Rpc
{
[RegisterCustomRpc]
public class SetRoleRpc : PlayerCustomRpc<HarmonyMain, SetRoleRpc.SetRoleData>
{
public SetRoleRpc(HarmonyMain plugin) : base(plugin)
{
}
public override RpcLocalHandling LocalHandling => RpcLocalHandling.Before;
public override void Handle(PlayerControl innerNetObject, SetRoleData role)
{
PlayerTools.getPlayerById(role.Player).getModdedControl().Role = role.Role;
}
public override SetRoleData Read(MessageReader reader)
{
return new SetRoleData(player: reader.ReadByte(), role: (Role)reader.ReadByte());
}
public override void Write(MessageWriter writer, SetRoleData data)
{
writer.Write(data.Player);
writer.Write((byte)data.Role);
}
public struct SetRoleData
{
public SetRoleData(byte player, Role role)
{
Player = player;
Role = role;
}
public byte Player { get; }
public Role Role { get; }
public static implicit operator SetRoleData((byte PlayerId, Role Role) data) => new SetRoleData(data.PlayerId, data.Role);
}
}
}