]> git.deb.at Git - rhonda/impostor.git/commitdiff
Implement GameOptions V8
authorminiduikboot <mini@duikbo.at>
Tue, 18 Jun 2024 17:45:17 +0000 (19:45 +0200)
committerminiduikboot <mini@duikbo.at>
Tue, 20 Aug 2024 19:41:38 +0000 (21:41 +0200)
This adds a field for RulesPresets and SpecialGameModes, as well as
RoleOptions for the new roles.

src/Impostor.Api/Innersloth/GameOptions/HideNSeekGameOptions.cs
src/Impostor.Api/Innersloth/GameOptions/IGameOptions.cs
src/Impostor.Api/Innersloth/GameOptions/LegacyGameOptionsData.cs
src/Impostor.Api/Innersloth/GameOptions/NormalGameOptions.cs
src/Impostor.Api/Innersloth/GameOptions/RoleOptions/NoisemakerRoleOptions.cs [new file with mode: 0644]
src/Impostor.Api/Innersloth/GameOptions/RoleOptions/PhantomRoleOptions.cs [new file with mode: 0644]
src/Impostor.Api/Innersloth/GameOptions/RoleOptions/RoleOptionsCollection.cs
src/Impostor.Api/Innersloth/GameOptions/RoleOptions/TrackerRoleOptions.cs [new file with mode: 0644]

index 6d061a906c38f691fb7c3616cf3b5dc1d4eb9165..87b01adcb35ba1df76e9157d1e52114452cb050e 100644 (file)
@@ -2,7 +2,7 @@ namespace Impostor.Api.Innersloth.GameOptions;
 
 public class HideNSeekGameOptions : IGameOptions
 {
-    public const int LatestVersion = 7;
+    public const int LatestVersion = 8;
 
     public HideNSeekGameOptions(byte version = LatestVersion)
     {
@@ -16,6 +16,12 @@ public class HideNSeekGameOptions : IGameOptions
     /// <inheritdoc />
     public GameModes GameMode => GameModes.HideNSeek;
 
+    /// <inheritdoc />
+    public SpecialGameModes SpecialMode { get; set; } = SpecialGameModes.None;
+
+    /// <inheritdoc />
+    public RulesPresets RulesPreset { get; set; } = RulesPresets.Custom;
+
     /// <inheritdoc />
     public byte MaxPlayers { get; set; } = 15;
 
@@ -96,6 +102,12 @@ public class HideNSeekGameOptions : IGameOptions
 
     public void Deserialize(IMessageReader reader)
     {
+        if (Version >= 8)
+        {
+            SpecialMode = (SpecialGameModes)reader.ReadByte();
+            RulesPreset = (RulesPresets)reader.ReadByte();
+        }
+
         MaxPlayers = reader.ReadByte();
         Keywords = (GameKeywords)reader.ReadInt32();
         Map = (MapTypes)reader.ReadByte();
@@ -121,7 +133,7 @@ public class HideNSeekGameOptions : IGameOptions
         MaxPingTime = reader.ReadSingle();
         CrewmateTimeInVent = reader.ReadSingle();
 
-        if (Version > 7)
+        if (Version > LatestVersion)
         {
             IGameOptions.ThrowUnknownVersion<HideNSeekGameOptions>(Version);
         }
@@ -129,6 +141,12 @@ public class HideNSeekGameOptions : IGameOptions
 
     public void Serialize(IMessageWriter writer)
     {
+        if (Version >= 8)
+        {
+            writer.Write((byte)SpecialMode);
+            writer.Write((byte)RulesPreset);
+        }
+
         writer.Write(MaxPlayers);
         writer.Write((uint)Keywords);
         writer.Write((byte)Map);
@@ -154,7 +172,7 @@ public class HideNSeekGameOptions : IGameOptions
         writer.Write(MaxPingTime);
         writer.Write(CrewmateTimeInVent);
 
-        if (Version > 7)
+        if (Version > LatestVersion)
         {
             IGameOptions.ThrowUnknownVersion<HideNSeekGameOptions>(Version);
         }
index 10200c15b7ddf214657325a1bc2b4939443d823e..fd6049580f9c355f506bc2660ba39813d95d9d71 100644 (file)
@@ -10,10 +10,20 @@ public interface IGameOptions
     public byte Version { get; }
 
     /// <summary>
-    ///     Gets the currently active gamemode.
+    ///     Gets the currently active gamemode. This is currently used for the Normal and HideAndSeek gamemodes.
     /// </summary>
     public GameModes GameMode { get; }
 
+    /// <summary>
+    ///    Gets the currently active special gamemode. This is currently used for the AprilFools gamemode.
+    /// </summary>
+    public SpecialGameModes SpecialMode { get; }
+
+    /// <summary>
+    ///    Gets the rule preset.
+    /// </summary>
+    public RulesPresets RulesPreset { get; }
+
     /// <summary>
     ///     Gets or sets the maximum amount of players for this lobby.
     /// </summary>
index 1ed7ecc5044f14e898c5d480f5f235e4606e5f98..25862c4633b1c766ca4c38e2af1221157483cd51 100644 (file)
@@ -21,6 +21,12 @@ public class LegacyGameOptionsData : IGameOptions
 
     public GameModes GameMode => GameModes.Normal;
 
+    /// <inheritdoc />
+    public SpecialGameModes SpecialMode { get; } = SpecialGameModes.None;
+
+    /// <inheritdoc />
+    public RulesPresets RulesPreset { get; } = RulesPresets.Custom;
+
     /// <summary>
     ///     Gets or sets the maximum amount of players for this lobby.
     /// </summary>
index 537a0ed8900bf8a18388afd8044da50b28671a28..7095f6de3274b2003dcb384de5addf083c45ae4d 100644 (file)
@@ -4,7 +4,7 @@ namespace Impostor.Api.Innersloth.GameOptions;
 
 public class NormalGameOptions : IGameOptions
 {
-    public const int LatestVersion = 7;
+    public const int LatestVersion = 8;
 
     public NormalGameOptions(byte version = LatestVersion)
     {
@@ -19,6 +19,12 @@ public class NormalGameOptions : IGameOptions
     /// <inheritdoc />
     public GameModes GameMode => GameModes.Normal;
 
+    /// <inheritdoc />
+    public SpecialGameModes SpecialMode { get; set; } = SpecialGameModes.None;
+
+    /// <inheritdoc />
+    public RulesPresets RulesPreset { get; set; } = RulesPresets.Custom;
+
     /// <inheritdoc />
     public byte MaxPlayers { get; set; } = 10;
 
@@ -133,6 +139,12 @@ public class NormalGameOptions : IGameOptions
 
     public void Deserialize(IMessageReader reader)
     {
+        if (Version >= 8)
+        {
+            SpecialMode = (SpecialGameModes)reader.ReadByte();
+            RulesPreset = (RulesPresets)reader.ReadByte();
+        }
+
         MaxPlayers = reader.ReadByte();
         Keywords = (GameKeywords)reader.ReadUInt32();
         Map = (MapTypes)reader.ReadByte();
@@ -163,7 +175,7 @@ public class NormalGameOptions : IGameOptions
 
         RoleOptions.Deserialize(reader);
 
-        if (Version > 7)
+        if (Version > LatestVersion)
         {
             IGameOptions.ThrowUnknownVersion<NormalGameOptions>(Version);
         }
@@ -171,6 +183,12 @@ public class NormalGameOptions : IGameOptions
 
     public void Serialize(IMessageWriter writer)
     {
+        if (Version >= 8)
+        {
+            writer.Write((byte)SpecialMode);
+            writer.Write((byte)RulesPreset);
+        }
+
         writer.Write(MaxPlayers);
         writer.Write((uint)Keywords);
         writer.Write((byte)Map);
@@ -201,7 +219,7 @@ public class NormalGameOptions : IGameOptions
 
         RoleOptions.Serialize(writer);
 
-        if (Version > 7)
+        if (Version > LatestVersion)
         {
             IGameOptions.ThrowUnknownVersion<NormalGameOptions>(Version);
         }
diff --git a/src/Impostor.Api/Innersloth/GameOptions/RoleOptions/NoisemakerRoleOptions.cs b/src/Impostor.Api/Innersloth/GameOptions/RoleOptions/NoisemakerRoleOptions.cs
new file mode 100644 (file)
index 0000000..d84a88d
--- /dev/null
@@ -0,0 +1,33 @@
+namespace Impostor.Api.Innersloth.GameOptions.RoleOptions;
+
+public class NoisemakerRoleOptions : IRoleOptions
+{
+    public NoisemakerRoleOptions(byte version)
+    {
+        Version = version;
+    }
+
+    public byte Version { get; }
+
+    public RoleTypes Type => RoleTypes.Noisemaker;
+
+    public bool ImpostorAlert { get; set; } = true;
+
+    public byte AlertDuration { get; set; } = 10;
+
+    public static NoisemakerRoleOptions Deserialize(IMessageReader reader, byte version)
+    {
+        var options = new NoisemakerRoleOptions(version);
+
+        options.AlertDuration = reader.ReadByte();
+        options.ImpostorAlert = reader.ReadBoolean();
+
+        return options;
+    }
+
+    public void Serialize(IMessageWriter writer)
+    {
+        writer.Write(AlertDuration);
+        writer.Write(ImpostorAlert);
+    }
+}
diff --git a/src/Impostor.Api/Innersloth/GameOptions/RoleOptions/PhantomRoleOptions.cs b/src/Impostor.Api/Innersloth/GameOptions/RoleOptions/PhantomRoleOptions.cs
new file mode 100644 (file)
index 0000000..7257622
--- /dev/null
@@ -0,0 +1,33 @@
+namespace Impostor.Api.Innersloth.GameOptions.RoleOptions;
+
+public class PhantomRoleOptions : IRoleOptions
+{
+    public PhantomRoleOptions(byte version)
+    {
+        Version = version;
+    }
+
+    public byte Version { get; }
+
+    public RoleTypes Type => RoleTypes.Phantom;
+
+    public byte Cooldown { get; set; } = 15;
+
+    public byte Duration { get; set; } = 30;
+
+    public static PhantomRoleOptions Deserialize(IMessageReader reader, byte version)
+    {
+        var options = new PhantomRoleOptions(version);
+
+        options.Cooldown = reader.ReadByte();
+        options.Duration = reader.ReadByte();
+
+        return options;
+    }
+
+    public void Serialize(IMessageWriter writer)
+    {
+        writer.Write(Cooldown);
+        writer.Write(Duration);
+    }
+}
index d8b70764a5d7b0c5cd4e99264197233e0b21756d..6e2da0690714db84a2570427b8203b1547c223e3 100644 (file)
@@ -31,6 +31,9 @@ public class RoleOptionsCollection
                 RoleTypes.Engineer => EngineerRoleOptions.Deserialize(roleOptionsReader, Version),
                 RoleTypes.GuardianAngel => GuardianAngelRoleOptions.Deserialize(roleOptionsReader, Version),
                 RoleTypes.Shapeshifter => ShapeshifterRoleOptions.Deserialize(roleOptionsReader, Version),
+                RoleTypes.Noisemaker => NoisemakerRoleOptions.Deserialize(roleOptionsReader, Version),
+                RoleTypes.Phantom => PhantomRoleOptions.Deserialize(roleOptionsReader, Version),
+                RoleTypes.Tracker => TrackerRoleOptions.Deserialize(roleOptionsReader, Version),
                 _ => throw new ArgumentOutOfRangeException(nameof(roleType), roleType, null),
             };
 
diff --git a/src/Impostor.Api/Innersloth/GameOptions/RoleOptions/TrackerRoleOptions.cs b/src/Impostor.Api/Innersloth/GameOptions/RoleOptions/TrackerRoleOptions.cs
new file mode 100644 (file)
index 0000000..4b8f50f
--- /dev/null
@@ -0,0 +1,37 @@
+namespace Impostor.Api.Innersloth.GameOptions.RoleOptions;
+
+public class TrackerRoleOptions : IRoleOptions
+{
+    public TrackerRoleOptions(byte version)
+    {
+        Version = version;
+    }
+
+    public byte Version { get; }
+
+    public RoleTypes Type => RoleTypes.Tracker;
+
+    public byte Cooldown { get; set; } = 15;
+
+    public byte Duration { get; set; } = 30;
+
+    public byte Delay { get; set; } = 1;
+
+    public static TrackerRoleOptions Deserialize(IMessageReader reader, byte version)
+    {
+        var options = new TrackerRoleOptions(version);
+
+        options.Cooldown = reader.ReadByte();
+        options.Duration = reader.ReadByte();
+        options.Delay = reader.ReadByte();
+
+        return options;
+    }
+
+    public void Serialize(IMessageWriter writer)
+    {
+        writer.Write(Cooldown);
+        writer.Write(Duration);
+        writer.Write(Delay);
+    }
+}