Skip to content

Commit

Permalink
BorgSystem: check droppable items for duped mods
Browse files Browse the repository at this point in the history
  • Loading branch information
whatston3 committed Feb 9, 2025
1 parent 77a4744 commit bc89ac1
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion Content.Server/Silicons/Borgs/BorgSystem.Modules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ public bool CanInsertModule(EntityUid uid, EntityUid module, BorgChassisComponen
continue;

if (containedItemModuleComp.Items.Count == itemModuleComp.Items.Count &&
containedItemModuleComp.Items.All(itemModuleComp.Items.Contains))
containedItemModuleComp.DroppableItems.Count == itemModuleComp.DroppableItems.Count && // Frontier
containedItemModuleComp.Items.All(itemModuleComp.Items.Contains) &&
containedItemModuleComp.DroppableItems.All(x => itemModuleComp.DroppableItems.Contains(x, new DroppableBorgItemComparer()))) // Frontier
{
if (user != null)
Popup.PopupEntity(Loc.GetString("borg-module-duplicate"), uid, user.Value);
Expand All @@ -381,6 +383,29 @@ public bool CanInsertModule(EntityUid uid, EntityUid module, BorgChassisComponen
return true;
}

// Frontier: droppable borg item comparator
private sealed class DroppableBorgItemComparer : IEqualityComparer<DroppableBorgItem>
{
public bool Equals(DroppableBorgItem? x, DroppableBorgItem? y)
{
// Same object
if (ReferenceEquals(x, y))
return true;
// Comparisons vs. null
if (x is null || y is null)
return false;
// Otherwise, use EntProtoId of item to keep
return x.ID == y.ID;
}

public int GetHashCode(DroppableBorgItem obj)
{
if (obj is null) return 0;
return obj.ID.GetHashCode();
}
}
// End Frontier

/// <summary>
/// Check if a module can be removed from a borg.
/// </summary>
Expand Down

0 comments on commit bc89ac1

Please sign in to comment.