]> git.deb.at Git - rhonda/impostor.git/commitdiff
Implement MushroomMixupSabotage
authorjs6pak <me@6pak.dev>
Fri, 24 Nov 2023 17:35:33 +0000 (18:35 +0100)
committerjs6pak <me@6pak.dev>
Sat, 16 Dec 2023 22:55:58 +0000 (23:55 +0100)
src/Impostor.Api/Innersloth/Customization/PlayerOutfitType.cs
src/Impostor.Server/Net/Inner/Objects/ShipStatus/InnerFungleShipStatus.cs
src/Impostor.Server/Net/Inner/Objects/Systems/ShipStatus/MushroomMixupSabotageSystemType.cs [new file with mode: 0644]

index 55ba04c59b68f5d5a9e70ab7d77dd5ac920b76e5..17ed3516500352c498547089be90655192f4ebdc 100644 (file)
@@ -4,5 +4,7 @@ namespace Impostor.Api.Innersloth.Customization
     {
         Default,
         Shapeshifted,
+        HorseWrangler,
+        MushroomMixup,
     }
 }
index a868d7cc6a34ef4bc8aa5fbeb68465364de73a94..571bb632c9d013910156e60d4492d86f7b280d18 100644 (file)
@@ -20,7 +20,7 @@ namespace Impostor.Server.Net.Inner.Objects.ShipStatus
             systems.Add(SystemTypes.Comms, new HudOverrideSystemType());
             systems.Add(SystemTypes.Reactor, new ReactorSystemType());
             systems.Add(SystemTypes.Doors, new DoorsSystemType(Doors));
-            // systems.Add(SystemTypes.MushroomMixupSabotage, );
+            systems.Add(SystemTypes.MushroomMixupSabotage, new MushroomMixupSabotageSystemType());
         }
     }
 }
diff --git a/src/Impostor.Server/Net/Inner/Objects/Systems/ShipStatus/MushroomMixupSabotageSystemType.cs b/src/Impostor.Server/Net/Inner/Objects/Systems/ShipStatus/MushroomMixupSabotageSystemType.cs
new file mode 100644 (file)
index 0000000..0055608
--- /dev/null
@@ -0,0 +1,76 @@
+using System.Collections.Generic;
+
+namespace Impostor.Server.Net.Inner.Objects.Systems.ShipStatus;
+
+public class MushroomMixupSabotageSystemType : ISystemType
+{
+    private readonly Dictionary<byte, CondensedOutfit> _currentMixups = new();
+    private State _currentState;
+    private float _currentSecondsUntilHeal;
+
+    private enum State
+    {
+        Inactive,
+        JustTriggered,
+        IdleButMixedUp,
+    }
+
+    public void Serialize(IMessageWriter writer, bool initialState)
+    {
+        writer.Write((byte)_currentState);
+        writer.Write(_currentSecondsUntilHeal);
+
+        writer.WritePacked(_currentMixups.Count);
+        foreach (var (playerId, outfit) in _currentMixups)
+        {
+            writer.Write(playerId);
+            outfit.Serialize(writer);
+        }
+    }
+
+    public void Deserialize(IMessageReader reader, bool initialState)
+    {
+        _currentState = (State)reader.ReadByte();
+        _currentSecondsUntilHeal = reader.ReadSingle();
+
+        _currentMixups.Clear();
+        var num = reader.ReadByte();
+        for (var i = 0; i < num; i++)
+        {
+            var playerId = reader.ReadByte();
+            var outfit = CondensedOutfit.Deserialize(reader);
+
+            _currentMixups.Add(playerId, outfit);
+        }
+    }
+
+    private readonly record struct CondensedOutfit(
+        byte HatIndex,
+        byte VisorIndex,
+        byte SkinIndex,
+        byte PetIndex,
+        byte ColorPlayerId
+    )
+    {
+        public void Serialize(IMessageWriter writer)
+        {
+            writer.Write(ColorPlayerId);
+            writer.Write(HatIndex);
+            writer.Write(VisorIndex);
+            writer.Write(SkinIndex);
+            writer.Write(PetIndex);
+        }
+
+        public static CondensedOutfit Deserialize(IMessageReader reader)
+        {
+            return new CondensedOutfit
+            {
+                ColorPlayerId = reader.ReadByte(),
+                HatIndex = reader.ReadByte(),
+                VisorIndex = reader.ReadByte(),
+                SkinIndex = reader.ReadByte(),
+                PetIndex = reader.ReadByte(),
+            };
+        }
+    }
+}