From 41800aff7718de2ca8882a8bb85563ec85fc20c4 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Fri, 13 Jul 2018 14:32:42 +0300 Subject: [PATCH] Cherry-picked d0b61b3 from dev. --- .../Source/Items/Components/Signal/Wire.cs | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs index 63c32afde..cdbc012e9 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Signal/Wire.cs @@ -37,13 +37,20 @@ namespace Barotrauma.Items.Components private bool canPlaceNode; private Vector2 newNodePos; - + public bool Hidden, Locked; public Connection[] Connections { get { return connections; } } + + [Serialize(5000.0f, false)] + public float MaxLength + { + get; + set; + } public Wire(Item item, XElement element) : base(item, element) @@ -232,14 +239,43 @@ namespace Barotrauma.Items.Components newNodePos = RoundNode(item.Position, item.CurrentHull) - sub.HiddenSubPosition; 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 { newNodePos = RoundNode(item.Position, item.CurrentHull) - sub.HiddenSubPosition; canPlaceNode = true; - } + } } - + public override bool Use(float deltaTime, Character character = null) { if (character == null) return false;