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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
using System.Threading.Tasks;
using Impostor.Api;
using Impostor.Api.Innersloth;
using Impostor.Api.Innersloth.Customization;
using Impostor.Api.Net;
using Impostor.Api.Net.Inner.Objects;
using Impostor.Api.Net.Inner.Objects.Components;
using Impostor.Server.Events.Player;
namespace Impostor.Server.Net.Inner.Objects
{
internal partial class InnerPlayerControl : IInnerPlayerControl
{
IInnerPlayerPhysics IInnerPlayerControl.Physics => Physics;
IInnerCustomNetworkTransform IInnerPlayerControl.NetworkTransform => NetworkTransform;
IInnerPlayerInfo IInnerPlayerControl.PlayerInfo => PlayerInfo;
public async ValueTask SetNameAsync(string name)
{
PlayerInfo.PlayerName = name;
using var writer = _game.StartRpc(NetId, RpcCalls.SetName);
writer.Write(name);
await _game.FinishRpcAsync(writer);
}
public async ValueTask SetColorAsync(byte colorId)
{
PlayerInfo.ColorId = colorId;
using var writer = _game.StartRpc(NetId, RpcCalls.SetColor);
writer.Write(colorId);
await _game.FinishRpcAsync(writer);
}
public ValueTask SetColorAsync(ColorType colorType)
{
return SetColorAsync((byte)colorType);
}
public async ValueTask SetHatAsync(uint hatId)
{
PlayerInfo.HatId = hatId;
using var writer = _game.StartRpc(NetId, RpcCalls.SetHat);
writer.WritePacked(hatId);
await _game.FinishRpcAsync(writer);
}
public ValueTask SetHatAsync(HatType hatType)
{
return SetHatAsync((uint)hatType);
}
public async ValueTask SetPetAsync(uint petId)
{
PlayerInfo.PetId = petId;
using var writer = _game.StartRpc(NetId, RpcCalls.SetPet);
writer.WritePacked(petId);
await _game.FinishRpcAsync(writer);
}
public ValueTask SetPetAsync(PetType petType)
{
return SetPetAsync((uint)petType);
}
public async ValueTask SetSkinAsync(uint skinId)
{
PlayerInfo.SkinId = skinId;
using var writer = _game.StartRpc(NetId, RpcCalls.SetSkin);
writer.WritePacked(skinId);
await _game.FinishRpcAsync(writer);
}
public ValueTask SetSkinAsync(SkinType skinType)
{
return SetSkinAsync((uint)skinType);
}
public async ValueTask SendChatAsync(string text)
{
using var writer = _game.StartRpc(NetId, RpcCalls.SendChat);
writer.Write(text);
await _game.FinishRpcAsync(writer);
}
public async ValueTask SendChatToPlayerAsync(string text, IInnerPlayerControl? player = null)
{
if (player == null)
{
player = this;
}
using var writer = _game.StartRpc(NetId, RpcCalls.SendChat);
writer.Write(text);
await _game.FinishRpcAsync(writer, player.OwnerId);
}
public async ValueTask SetMurderedByAsync(IClientPlayer impostor)
{
if (impostor.Character == null)
{
throw new ImpostorException("Character is null.");
}
if (!impostor.Character.PlayerInfo.IsImpostor)
{
throw new ImpostorProtocolException("Plugin tried to murder a player while the impostor specified was not an impostor.");
}
if (impostor.Character.PlayerInfo.IsDead)
{
throw new ImpostorProtocolException("Plugin tried to murder a player while the impostor specified was dead.");
}
if (PlayerInfo.IsDead)
{
return;
}
// Update player.
Die(DeathReason.Kill);
// Send RPC.
using var writer = _game.StartRpc(impostor.Character.NetId, RpcCalls.MurderPlayer);
writer.WritePacked(NetId);
await _game.FinishRpcAsync(writer);
// Notify plugins.
await _eventManager.CallAsync(new PlayerMurderEvent(_game, impostor, impostor.Character, this));
}
}
}
|