diff --git a/Content.Shared/Preferences/Loadouts/Loadout.cs b/Content.Shared/Preferences/Loadouts/Loadout.cs index dbe440f58b..c1d20cd3de 100644 --- a/Content.Shared/Preferences/Loadouts/Loadout.cs +++ b/Content.Shared/Preferences/Loadouts/Loadout.cs @@ -7,8 +7,25 @@ namespace Content.Shared.Preferences.Loadouts; /// Specifies the selected prototype and custom data for a loadout. /// [Serializable, NetSerializable, DataDefinition] -public sealed partial class Loadout +public sealed partial class Loadout : IEquatable { [DataField] public ProtoId Prototype; + + public bool Equals(Loadout? other) + { + if (ReferenceEquals(null, other)) return false; + if (ReferenceEquals(this, other)) return true; + return Prototype.Equals(other.Prototype); + } + + public override bool Equals(object? obj) + { + return ReferenceEquals(this, obj) || obj is Loadout other && Equals(other); + } + + public override int GetHashCode() + { + return Prototype.GetHashCode(); + } } diff --git a/Content.Shared/Preferences/Loadouts/RoleLoadout.cs b/Content.Shared/Preferences/Loadouts/RoleLoadout.cs index 5f8e24621a..d2fc8df559 100644 --- a/Content.Shared/Preferences/Loadouts/RoleLoadout.cs +++ b/Content.Shared/Preferences/Loadouts/RoleLoadout.cs @@ -295,7 +295,25 @@ public sealed partial class RoleLoadout : IEquatable { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; - return Role.Equals(other.Role) && SelectedLoadouts.SequenceEqual(other.SelectedLoadouts) && Points == other.Points; + + if (!Role.Equals(other.Role) || + SelectedLoadouts.Count != other.SelectedLoadouts.Count || + Points != other.Points) + { + return false; + } + + // Tried using SequenceEqual but it stinky so. + foreach (var (key, value) in SelectedLoadouts) + { + if (!other.SelectedLoadouts.TryGetValue(key, out var otherValue) || + !otherValue.SequenceEqual(value)) + { + return false; + } + } + + return true; } public override bool Equals(object? obj)