Added "user" parameter to Inventory.PutItem and Inventory.TryPutItem. + More descriptive wiring logging: the logs don't list all the wires in a connectionpanel but only the changes a player does to the wiring. Disconnecting wires by picking them up and wiring done by the host are also logged now.

This commit is contained in:
Joonas Rikkonen
2017-07-17 23:27:31 +03:00
parent f1edb14f3f
commit 575b643c62
16 changed files with 125 additions and 66 deletions
@@ -72,7 +72,7 @@ namespace Barotrauma.Items.Components
protected virtual bool OnPicked(Character picker)
{
if (picker.Inventory.TryPutItem(item, allowedSlots))
if (picker.Inventory.TryPutItem(item, picker, allowedSlots))
{
if (!picker.HasSelectedItem(item) && item.body != null) item.body.Enabled = false;
this.picker = picker;
@@ -183,7 +183,7 @@ namespace Barotrauma.Items.Components
{
if (!containableItems.Any(x => x.MatchesItem(item))) return false;
if (Inventory.TryPutItem(item))
if (Inventory.TryPutItem(item, null))
{
IsActive = true;
if (hideItems && item.body != null) item.body.Enabled = false;
@@ -200,10 +200,10 @@ namespace Barotrauma.Items.Components
for (ushort i = 0; i < itemIds.Length; i++)
{
Item item = MapEntity.FindEntityByID(itemIds[i]) as Item;
Item item = Entity.FindEntityByID(itemIds[i]) as Item;
if (item == null) continue;
Inventory.TryPutItem(item, i, false, false);
Inventory.TryPutItem(item, i, false, null, false);
}
itemIds = null;
@@ -154,7 +154,7 @@ 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<Wire>();
@@ -165,7 +165,7 @@ namespace Barotrauma.Items.Components
}
}
item.CreateServerEvent<ConnectionPanel>(this);
item.CreateServerEvent(this);
//check if the character can access this connectionpanel
//and all the wires they're trying to connect
@@ -182,25 +182,51 @@ namespace Barotrauma.Items.Components
}
}
}
Networking.GameServer.Log(item.Name + " rewired by " + c.Character.Name, ServerLog.MessageType.ItemInteraction);
//update the connections
for (int i = 0; i < Connections.Count; i++)
{
Wire[] prevWires = new Wire[Connections[i].Wires.Length];
Array.Copy(Connections[i].Wires, prevWires, prevWires.Length);
Connections[i].ClearConnections();
for (int j = 0; j < wireCounts[i]; j++)
{
if (wires[i, j] == null) continue;
if (wires[i, j] == null)
{
if (prevWires[j] != null)
{
if (prevWires[j].Connections[0] != null && prevWires[j].Connections[1] != null)
{
GameServer.Log(c.Character.Name + " disconnected a wire from " +
prevWires[j].Connections[0].Item.Name + " (" + prevWires[j].Connections[0].Name + ") to " +
prevWires[j].Connections[1].Item.Name + " (" + prevWires[j].Connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
}
else if (prevWires[j].Connections[0] != null)
{
GameServer.Log(c.Character.Name + " disconnected a wire from " +
prevWires[j].Connections[0].Item.Name + " (" + prevWires[j].Connections[0].Name + ")", ServerLog.MessageType.ItemInteraction);
}
else if (prevWires[j].Connections[1] != null)
{
GameServer.Log(c.Character.Name + " disconnected a wire from " +
prevWires[j].Connections[1].Item.Name + " (" + prevWires[j].Connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
}
}
continue;
}
//already connected, no need to do anything
if (wires[i, j] == prevWires[j]) continue;
Connections[i].Wires[j] = wires[i,j];
wires[i, j].Connect(Connections[i], true);
var otherConnection = Connections[i].Wires[j].OtherConnection(Connections[i]);
Networking.GameServer.Log(
item.Name + " (" + Connections[i].Name + ") -> " +
GameServer.Log(item.Name + " rewired by " + c.Character.Name+ ": " +
Connections[i].Name + " -> " +
(otherConnection == null ? "none" : otherConnection.Item.Name + " (" + (otherConnection.Name) + ")"), ServerLog.MessageType.ItemInteraction);
}
}
@@ -187,21 +187,21 @@ namespace Barotrauma.Items.Components
public override void Equip(Character character)
{
ClearConnections();
ClearConnections(character);
IsActive = true;
}
public override void Unequip(Character character)
{
ClearConnections();
ClearConnections(character);
IsActive = false;
}
public override void Drop(Character dropper)
{
ClearConnections();
ClearConnections(dropper);
IsActive = false;
}
@@ -252,7 +252,7 @@ namespace Barotrauma.Items.Components
public override bool Pick(Character picker)
{
ClearConnections();
ClearConnections(picker);
return true;
}
@@ -295,10 +295,30 @@ namespace Barotrauma.Items.Components
Drawable = IsActive || sections.Count > 0;
}
private void ClearConnections()
private void ClearConnections(Character user = null)
{
nodes.Clear();
sections.Clear();
if (user != null)
{
if (connections[0] != null && connections[1] != null)
{
GameServer.Log(Character.Controlled.Name + " disconnected a wire from " +
connections[0].Item.Name + " (" + connections[0].Name + ") to "+
connections[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
}
else if (connections[0] != null)
{
GameServer.Log(Character.Controlled.Name + " disconnected a wire from " +
connections[0].Item.Name + " (" + connections[0].Name + ")", ServerLog.MessageType.ItemInteraction);
}
else if (connections[1] != null)
{
GameServer.Log(Character.Controlled.Name + " disconnected a wire from " +
connections[1].Item.Name + " (" + connections[1].Name + ")", ServerLog.MessageType.ItemInteraction);
}
}
for (int i = 0; i < 2; i++)
{