diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Connection.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Connection.cs index 949859513..1bf1927b0 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Connection.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/Connection.cs @@ -102,11 +102,11 @@ namespace Barotrauma.Items.Components { if (GameMain.Client != null) { - panel.Item.CreateClientEvent(panel); + panel.Item.CreateClientEvent(panel); } else if (GameMain.Server != null) { - panel.Item.CreateServerEvent(panel); + panel.Item.CreateServerEvent(panel); } draggingConnected = null; diff --git a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/ConnectionPanel.cs b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/ConnectionPanel.cs index e66a28d9a..b2f10ae90 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/ConnectionPanel.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Components/Signal/ConnectionPanel.cs @@ -23,7 +23,6 @@ namespace Barotrauma.Items.Components HighlightedWire = null; Connection.DrawConnections(spriteBatch, this, character); - } } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/ConnectionPanel.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/ConnectionPanel.cs index 7b25c669b..cb4f18016 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/ConnectionPanel.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/ConnectionPanel.cs @@ -231,13 +231,30 @@ namespace Barotrauma.Items.Components { GameServer.Log(c.Character.Name + " disconnected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[0].Item.Name + " (" + existingWire.Connections[0].Name + ")", ServerLog.MessageType.ItemInteraction); + + //wires that are not in anyone's inventory (i.e. not currently being rewired) + //can never be connected to only one connection + // -> the client must have dropped the wire from the connection panel + if (existingWire.Item.ParentInventory == null) + { + //let other clients know the item was also disconnected from the other connection + existingWire.Connections[0].Item.CreateServerEvent(existingWire.Connections[0].Item.GetComponent()); + existingWire.Item.Drop(c.Character); + } } else if (existingWire.Connections[1] != null) { GameServer.Log(c.Character.Name + " disconnected a wire from " + Connections[i].Item.Name + " (" + Connections[i].Name + ") to " + existingWire.Connections[1].Item.Name + " (" + existingWire.Connections[1].Name + ")", ServerLog.MessageType.ItemInteraction); - } + if (existingWire.Item.ParentInventory == null) + { + //let other clients know the item was also disconnected from the other connection + existingWire.Connections[1].Item.CreateServerEvent(existingWire.Connections[1].Item.GetComponent()); + existingWire.Item.Drop(c.Character); + } + } + Connections[i].Wires[j] = null; } @@ -281,6 +298,9 @@ namespace Barotrauma.Items.Components public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { + List prevWires = Connections.SelectMany(c => Array.FindAll(c.Wires, w => w != null)).ToList(); + List newWires = new List(); + foreach (Connection connection in Connections) { connection.ClearConnections(); @@ -289,16 +309,33 @@ namespace Barotrauma.Items.Components { ushort wireId = msg.ReadUInt16(); - Item wireItem = MapEntity.FindEntityByID(wireId) as Item; + Item wireItem = Entity.FindEntityByID(wireId) as Item; if (wireItem == null) continue; Wire wireComponent = wireItem.GetComponent(); if (wireComponent == null) continue; + newWires.Add(wireComponent); + connection.Wires[i] = wireComponent; wireComponent.Connect(connection, false); } } + + foreach (Wire wire in prevWires) + { + if (wire.Connections[0] == null && wire.Connections[1] == null) + { + wire.Item.Drop(null); + } + //wires that are not in anyone's inventory (i.e. not currently being rewired) can never be connected to only one connection + // -> someone must have dropped the wire from the connection panel + else if (wire.Item.ParentInventory == null && + (wire.Connections[0] != null ^ wire.Connections[1] != null)) + { + wire.Item.Drop(null); + } + } } } }