using Impostor.Api.Innersloth;
using Impostor.Api.Net;
using Impostor.Api.Net.Inner;
+using Impostor.Api.Net.Inner.Objects;
using Impostor.Api.Net.Messages;
namespace Impostor.Api.Games
/// Syncs the internal <see cref="GameOptionsData"/> to all players.
/// Necessary to do if you modified it, otherwise it won't be used.
/// </summary>
- /// <returns></returns>
+ /// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
ValueTask SyncSettingsAsync();
+ /// <summary>
+ /// Sets the specified list as Impostor on all connected players.
+ /// </summary>
+ /// <param name="players">List of players to be Impostor.</param>
+ /// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
+ ValueTask SetInfectedAsync(IEnumerable<IInnerPlayerControl> players);
+
/// <summary>
/// Send the message to all players.
/// </summary>
/// <returns>A <see cref="ValueTask"/> representing the asynchronous operation.</returns>
ValueTask SendToAsync(IMessageWriter writer, int id);
}
-}
\ No newline at end of file
+}
/// </summary>
LimboStates Limbo { get; set; }
- IInnerPlayerControl Character { get; }
+ IInnerPlayerControl? Character { get; }
public bool IsHost { get; }
ValueTask BanAsync();
}
-}
\ No newline at end of file
+}
{
public interface IInnerPlayerControl : IInnerNetObject
{
+ /// <summary>
+ /// Gets the <see cref="PlayerId"/> assigned by the client of the host of the game.
+ /// </summary>
+ byte PlayerId { get; }
+
/// <summary>
/// Gets the <see cref="IInnerPlayerPhysics"/> of the <see cref="IInnerPlayerControl"/>.
/// Contains vent logic.
/// <returns>Task that must be awaited.</returns>
ValueTask SendChatToPlayerAsync(string text, IInnerPlayerControl? player = null);
- /// <summary>
- /// Sets the current to infected (impostor) <see cref="IInnerPlayerControl"/>.
- /// Visible to all players.
- /// </summary>
- /// <returns>Task that must be awaited.</returns>
- ValueTask SetInfectedAsync();
-
/// <summary>
/// Sets the current to be murdered <see cref="IInnerPlayerControl"/>.
/// Visible to all players.
return _allPlayers.TryGetValue(id, out var player) ? player : null;
}
- public override ValueTask HandleRpc(ClientPlayer sender, ClientPlayer? target, RpcCalls call,
- IMessageReader reader)
+ public override ValueTask HandleRpc(ClientPlayer sender, ClientPlayer? target, RpcCalls call, IMessageReader reader)
{
switch (call)
{
writer.Write((byte)NetId);
await _game.FinishRpcAsync(writer);
}
-
- public async ValueTask SetInfectedAsync()
- {
- var writer = _game.StartRpc(NetId, RpcCalls.SetInfected);
- writer.Write((byte)NetId);
- await _game.FinishRpcAsync(writer);
- }
}
}
IGame IClientPlayer.Game => Game;
/// <inheritdoc />
- IInnerPlayerControl IClientPlayer.Character => Character;
+ IInnerPlayerControl? IClientPlayer.Character => Character;
}
-}
\ No newline at end of file
+}
/// <inheritdoc />
public LimboStates Limbo { get; set; }
- public InnerPlayerControl Character { get; internal set; }
+ public InnerPlayerControl? Character { get; internal set; }
public bool IsHost => Game?.Host == this;
-using System.IO;
+using System.Collections.Generic;
+using System.IO;
using System.Net;
using System.Threading.Tasks;
+using Impostor.Api;
using Impostor.Api.Games;
using Impostor.Api.Innersloth;
using Impostor.Api.Net;
using Impostor.Api.Net.Inner;
+using Impostor.Api.Net.Inner.Objects;
using Impostor.Server.Net.Inner;
namespace Impostor.Server.Net.State
public async ValueTask SyncSettingsAsync()
{
+ if (Host.Character == null)
+ {
+ throw new ImpostorException("Attempted to set infected when the host was not spawned.");
+ }
+
using (var writer = StartRpc(Host.Character.NetId, RpcCalls.SyncSettings))
{
// Someone will probably forget to do this, so we include it here.
await FinishRpcAsync(writer);
}
}
+
+ public async ValueTask SetInfectedAsync(IEnumerable<IInnerPlayerControl> players)
+ {
+ if (Host.Character == null)
+ {
+ throw new ImpostorException("Attempted to set infected when the host was not spawned.");
+ }
+
+ using (var writer = StartRpc(Host.Character.NetId, RpcCalls.SetInfected))
+ {
+ writer.Write((byte)Host.Character.NetId);
+
+ foreach (var player in players)
+ {
+ writer.Write((byte)player.PlayerId);
+ }
+
+ await FinishRpcAsync(writer);
+ }
+ }
}
-}
\ No newline at end of file
+}