Fixed wires not being dropped server-side when a player drops a connected wire without dragging it to their inventory first (or client-side when a host does so).
Closes #96
This commit is contained in:
@@ -102,11 +102,11 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
if (GameMain.Client != null)
|
if (GameMain.Client != null)
|
||||||
{
|
{
|
||||||
panel.Item.CreateClientEvent<ConnectionPanel>(panel);
|
panel.Item.CreateClientEvent(panel);
|
||||||
}
|
}
|
||||||
else if (GameMain.Server != null)
|
else if (GameMain.Server != null)
|
||||||
{
|
{
|
||||||
panel.Item.CreateServerEvent<ConnectionPanel>(panel);
|
panel.Item.CreateServerEvent(panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
draggingConnected = null;
|
draggingConnected = null;
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
HighlightedWire = null;
|
HighlightedWire = null;
|
||||||
Connection.DrawConnections(spriteBatch, this, character);
|
Connection.DrawConnections(spriteBatch, this, character);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,13 +231,30 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
GameServer.Log(c.Character.Name + " disconnected a wire from " +
|
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);
|
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<ConnectionPanel>());
|
||||||
|
existingWire.Item.Drop(c.Character);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (existingWire.Connections[1] != null)
|
else if (existingWire.Connections[1] != null)
|
||||||
{
|
{
|
||||||
GameServer.Log(c.Character.Name + " disconnected a wire from " +
|
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);
|
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<ConnectionPanel>());
|
||||||
|
existingWire.Item.Drop(c.Character);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Connections[i].Wires[j] = null;
|
Connections[i].Wires[j] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,6 +298,9 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
|
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
|
||||||
{
|
{
|
||||||
|
List<Wire> prevWires = Connections.SelectMany(c => Array.FindAll(c.Wires, w => w != null)).ToList();
|
||||||
|
List<Wire> newWires = new List<Wire>();
|
||||||
|
|
||||||
foreach (Connection connection in Connections)
|
foreach (Connection connection in Connections)
|
||||||
{
|
{
|
||||||
connection.ClearConnections();
|
connection.ClearConnections();
|
||||||
@@ -289,16 +309,33 @@ namespace Barotrauma.Items.Components
|
|||||||
{
|
{
|
||||||
ushort wireId = msg.ReadUInt16();
|
ushort wireId = msg.ReadUInt16();
|
||||||
|
|
||||||
Item wireItem = MapEntity.FindEntityByID(wireId) as Item;
|
Item wireItem = Entity.FindEntityByID(wireId) as Item;
|
||||||
if (wireItem == null) continue;
|
if (wireItem == null) continue;
|
||||||
|
|
||||||
Wire wireComponent = wireItem.GetComponent<Wire>();
|
Wire wireComponent = wireItem.GetComponent<Wire>();
|
||||||
if (wireComponent == null) continue;
|
if (wireComponent == null) continue;
|
||||||
|
|
||||||
|
newWires.Add(wireComponent);
|
||||||
|
|
||||||
connection.Wires[i] = wireComponent;
|
connection.Wires[i] = wireComponent;
|
||||||
wireComponent.Connect(connection, false);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user