using System;
using System.IO;
using Impostor.Api.Net.Messages;
namespace Impostor.Api.Innersloth
{
public class GameOptionsData
{
///
/// The latest major version of the game client.
///
public const int LatestVersion = 4;
///
/// Gets or sets host's version of the game.
///
public byte Version { get; set; }
///
/// Gets or sets the maximum amount of players for this lobby.
///
public byte MaxPlayers { get; set; }
///
/// Gets or sets the language of the lobby as per enum.
///
public GameKeywords Keywords { get; set; }
///
/// Gets or sets the MapId selected for this lobby
///
///
/// Skeld = 0, MiraHQ = 1, Polus = 2.
///
internal byte MapId { get; set; }
///
/// Gets or sets the map selected for this lobby
///
public MapTypes Map
{
get => (MapTypes)MapId;
set => MapId = (byte)value;
}
///
/// Gets or sets the Player speed modifier.
///
public float PlayerSpeedMod { get; set; }
///
/// Gets or sets the Light modifier for the players that are members of the crew as a multiplier value.
///
public float CrewLightMod { get; set; }
///
/// Gets or sets the Light modifier for the players that are Impostors as a multiplier value.
///
public float ImpostorLightMod { get; set; }
///
/// Gets or sets the Impostor cooldown to kill in seconds.
///
public float KillCooldown { get; set; }
///
/// Gets or sets the number of common tasks.
///
public int NumCommonTasks { get; set; }
///
/// Gets or sets the number of long tasks.
///
public int NumLongTasks { get; set; }
///
/// Gets or sets the number of short tasks.
///
public int NumShortTasks { get; set; }
///
/// Gets or sets the maximum amount of emergency meetings each player can call during the game in seconds.
///
public int NumEmergencyMeetings { get; set; }
///
/// Gets or sets the cooldown between each time any player can call an emergency meeting in seconds.
///
public int EmergencyCooldown { get; set; }
///
/// Gets or sets the number of impostors for this lobby.
///
public int NumImpostors { get; set; }
///
/// Gets or sets a value indicating whether ghosts (dead crew members) can do tasks.
///
public bool GhostsDoTasks { get; set; }
///
/// Gets or sets the Kill as per values in .
///
///
/// Short = 0, Normal = 1, Long = 2.
///
public KillDistances KillDistance { get; set; }
///
/// Gets or sets the time for discussion before voting time in seconds.
///
public int DiscussionTime { get; set; }
///
/// Gets or sets the time for voting in seconds.
///
public int VotingTime { get; set; }
///
/// Gets or sets a value indicating whether an ejected player is an impostor or not.
///
public bool ConfirmImpostor { get; set; }
///
/// Gets or sets a value indicating whether players are able to see tasks being performed by other players.
///
///
/// By being set to true, tasks such as Empty Garbage, Submit Scan, Clear asteroids, Prime shields execution will be visible to other players.
///
public bool VisualTasks { get; set; }
///
/// Gets or sets a value indicating whether the vote is anonymous.
///
public bool AnonymousVotes { get; set; }
///
/// Gets or sets the task bar update mode as per values in .
///
public TaskBarUpdate TaskBarUpdate { get; set; }
///
/// Gets or sets a value indicating whether the GameOptions are the default ones.
///
public bool IsDefaults { get; set; }
///
/// Deserialize a packet/message to a new GameOptionsData object.
///
/// Message reader object containing the raw message.
/// GameOptionsData object.
public static GameOptionsData DeserializeCreate(IMessageReader reader)
{
var options = new GameOptionsData();
options.Deserialize(reader.ReadBytesAndSize());
return options;
}
///
/// Serializes this instance of GameOptionsData object to a specified BinaryWriter.
///
/// The stream to write the message to.
/// The version of the game.
public void Serialize(BinaryWriter writer, byte version)
{
writer.Write((byte)version);
writer.Write((byte)MaxPlayers);
writer.Write((uint)Keywords);
writer.Write((byte)MapId);
writer.Write((float)PlayerSpeedMod);
writer.Write((float)CrewLightMod);
writer.Write((float)ImpostorLightMod);
writer.Write((float)KillCooldown);
writer.Write((byte)NumCommonTasks);
writer.Write((byte)NumLongTasks);
writer.Write((byte)NumShortTasks);
writer.Write((int)NumEmergencyMeetings);
writer.Write((byte)NumImpostors);
writer.Write((byte)KillDistance);
writer.Write((uint)DiscussionTime);
writer.Write((uint)VotingTime);
writer.Write((bool)IsDefaults);
if (version > 1)
{
writer.Write((byte)EmergencyCooldown);
}
if (version > 2)
{
writer.Write((bool)ConfirmImpostor);
writer.Write((bool)VisualTasks);
}
if (version > 3)
{
writer.Write((bool)AnonymousVotes);
writer.Write((byte)TaskBarUpdate);
}
if (version > 4)
{
throw new ImpostorException($"Unknown GameOptionsData version {Version}.");
}
}
///
/// Deserialize a ReadOnlyMemory object to this instance of the GameOptionsData object.
///
/// Memory containing the message/packet.
public void Deserialize(ReadOnlyMemory memory)
{
var bytes = memory.Span;
Version = bytes.ReadByte();
MaxPlayers = bytes.ReadByte();
Keywords = (GameKeywords)bytes.ReadUInt32();
MapId = bytes.ReadByte();
PlayerSpeedMod = bytes.ReadSingle();
CrewLightMod = bytes.ReadSingle();
ImpostorLightMod = bytes.ReadSingle();
KillCooldown = bytes.ReadSingle();
NumCommonTasks = bytes.ReadByte();
NumLongTasks = bytes.ReadByte();
NumShortTasks = bytes.ReadByte();
NumEmergencyMeetings = bytes.ReadInt32();
NumImpostors = bytes.ReadByte();
KillDistance = (KillDistances)bytes.ReadByte();
DiscussionTime = bytes.ReadInt32();
VotingTime = bytes.ReadInt32();
IsDefaults = bytes.ReadBoolean();
if (Version > 1)
{
EmergencyCooldown = bytes.ReadByte();
}
if (Version > 2)
{
ConfirmImpostor = bytes.ReadBoolean();
VisualTasks = bytes.ReadBoolean();
}
if (Version > 3)
{
AnonymousVotes = bytes.ReadBoolean();
TaskBarUpdate = (TaskBarUpdate)bytes.ReadByte();
}
if (Version > 4)
{
throw new ImpostorException($"Unknown GameOptionsData version {Version}.");
}
}
}
}