Fixed items attached mid-round by other clients or the host being impossible to interact with and occasionally being attached to an incorrect position. Closes #296
This commit is contained in:
@@ -126,7 +126,15 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public override void Drop(Character dropper)
|
||||
{
|
||||
DropConnectedWires(dropper);
|
||||
Drop(true, dropper);
|
||||
}
|
||||
|
||||
private void Drop(bool dropConnectedWires, Character dropper)
|
||||
{
|
||||
if (dropConnectedWires)
|
||||
{
|
||||
DropConnectedWires(dropper);
|
||||
}
|
||||
|
||||
if (attachable)
|
||||
{
|
||||
@@ -147,7 +155,7 @@ namespace Barotrauma.Items.Components
|
||||
picker = dropper;
|
||||
}
|
||||
if (picker.Inventory == null) return;
|
||||
|
||||
|
||||
item.Submarine = picker.Submarine;
|
||||
if (item.body != null)
|
||||
{
|
||||
@@ -360,6 +368,12 @@ namespace Barotrauma.Items.Components
|
||||
item.body.Dir = -item.body.Dir;
|
||||
}
|
||||
|
||||
public override void OnItemLoaded()
|
||||
{
|
||||
if (item.Submarine != null && item.Submarine.Loading) return;
|
||||
OnMapLoaded();
|
||||
}
|
||||
|
||||
public override void OnMapLoaded()
|
||||
{
|
||||
if (!attachable) return;
|
||||
@@ -384,17 +398,20 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
public void ServerWrite(NetBuffer msg, Client c, object[] extraData = null)
|
||||
{
|
||||
if (!attachable)
|
||||
if (!attachable || body == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Sent an attachment event for an item that's not attachable.");
|
||||
}
|
||||
|
||||
msg.Write(Attached);
|
||||
msg.Write(body.SimPosition.X);
|
||||
msg.Write(body.SimPosition.Y);
|
||||
}
|
||||
|
||||
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime)
|
||||
{
|
||||
bool isAttached = msg.ReadBoolean();
|
||||
Vector2 simPosition = new Vector2(msg.ReadFloat(), msg.ReadFloat());
|
||||
|
||||
if (!attachable)
|
||||
{
|
||||
@@ -404,10 +421,8 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (isAttached)
|
||||
{
|
||||
if (item.ParentInventory != null)
|
||||
{
|
||||
item.ParentInventory.RemoveItem(item);
|
||||
}
|
||||
Drop(false, null);
|
||||
item.SetTransform(simPosition, 0.0f);
|
||||
AttachToWall();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -208,7 +208,7 @@ namespace Barotrauma.Items.Components
|
||||
|
||||
if (item.body != null && !item.body.Enabled)
|
||||
{
|
||||
item.body.ResetDynamics();
|
||||
item.body.ResetDynamics();
|
||||
item.SetTransform(bodyDropPos, 0.0f);
|
||||
item.body.Enabled = true;
|
||||
}
|
||||
|
||||
@@ -575,7 +575,15 @@ namespace Barotrauma.Items.Components
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when all items have been loaded. Use to initialize connections between items.
|
||||
/// </summary>
|
||||
public virtual void OnMapLoaded() { }
|
||||
|
||||
/// <summary>
|
||||
/// Called when all the components of the item have been loaded. Use to initialize connections between components and such.
|
||||
/// </summary>
|
||||
public virtual void OnItemLoaded() { }
|
||||
|
||||
public static ItemComponent Load(XElement element, Item item, string file, bool errorMessages = true)
|
||||
{
|
||||
|
||||
@@ -23,12 +23,6 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
get
|
||||
{
|
||||
if (powerConnections == null)
|
||||
{
|
||||
var connections = Item.Connections;
|
||||
powerConnections = connections == null ? new List<Connection>() : connections.FindAll(c => c.IsPower);
|
||||
|
||||
}
|
||||
return powerConnections;
|
||||
}
|
||||
}
|
||||
@@ -338,18 +332,18 @@ namespace Barotrauma.Items.Components
|
||||
connectionDirty[connection] = true;
|
||||
}
|
||||
|
||||
public override void OnMapLoaded()
|
||||
public override void OnItemLoaded()
|
||||
{
|
||||
var connections = item.Connections;
|
||||
var connections = Item.Connections;
|
||||
powerConnections = connections == null ? new List<Connection>() : connections.FindAll(c => c.IsPower);
|
||||
if (connections == null)
|
||||
{
|
||||
IsActive = false;
|
||||
return;
|
||||
}
|
||||
|
||||
SetAllConnectionsDirty();
|
||||
}
|
||||
|
||||
|
||||
public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power)
|
||||
{
|
||||
base.ReceiveSignal(stepsTaken, signal, connection, source, sender, power);
|
||||
|
||||
@@ -461,6 +461,11 @@ namespace Barotrauma
|
||||
|
||||
InsertToList();
|
||||
ItemList.Add(this);
|
||||
|
||||
foreach (ItemComponent ic in components)
|
||||
{
|
||||
ic.OnItemLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
public override MapEntity Clone()
|
||||
|
||||
Reference in New Issue
Block a user