Implement MushroomMixupSabotage

This commit is contained in:
js6pak committed 2023-12-16 23:55:58 +01:00
1 parent 389b7dfc0a
commit c6121eed49
3 files changed
+79 -1

No files matched your search

@@ -4,5 +4,7 @@ namespace Impostor.Api.Innersloth.Customization
{
Default,
Shapeshifted,
HorseWrangler,
MushroomMixup,
}
}
@@ -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());
}
}
}
@@ -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(),
};
}
}
}