Cherry-picked d0b61b3 from dev.

This commit is contained in:
Joonas Rikkonen
2018-07-13 14:32:42 +03:00
parent e0455caaaa
commit 41800aff77
@@ -45,6 +45,13 @@ namespace Barotrauma.Items.Components
get { return connections; } get { return connections; }
} }
[Serialize(5000.0f, false)]
public float MaxLength
{
get;
set;
}
public Wire(Item item, XElement element) public Wire(Item item, XElement element)
: base(item, element) : base(item, element)
{ {
@@ -232,6 +239,35 @@ namespace Barotrauma.Items.Components
newNodePos = RoundNode(item.Position, item.CurrentHull) - sub.HiddenSubPosition; newNodePos = RoundNode(item.Position, item.CurrentHull) - sub.HiddenSubPosition;
canPlaceNode = true; canPlaceNode = true;
} }
//prevent the wire from extending too far when rewiring
if (nodes.Count > 0)
{
Character user = item.ParentInventory?.Owner as Character;
if (user == null) return;
Vector2 prevNodePos = nodes[nodes.Count - 1];
prevNodePos += sub.HiddenSubPosition;
float currLength = 0.0f;
for (int i = 0; i < nodes.Count - 1; i++)
{
currLength += Vector2.Distance(nodes[i], nodes[i + 1]);
}
currLength += Vector2.Distance(nodes[nodes.Count - 1], newNodePos);
if (currLength > MaxLength)
{
Vector2 pullBackDir = Vector2.Normalize(nodes[nodes.Count - 1] - newNodePos);
user.AnimController.Collider.ApplyForce(pullBackDir * user.Mass * 50.0f);
user.AnimController.UpdateUseItem(true, user.SimPosition + pullBackDir * 2.0f);
if (currLength > MaxLength * 1.5f)
{
ClearConnections();
return;
}
}
}
} }
else else
{ {