/// Specifies the selected prototype and custom data for a loadout.
/// </summary>
[Serializable, NetSerializable, DataDefinition]
-public sealed partial class Loadout
+public sealed partial class Loadout : IEquatable<Loadout>
{
[DataField]
public ProtoId<LoadoutPrototype> 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();
+ }
}
{
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)