From c7fd6818a4f5d279a8fe267551fd6cc55dd3931f Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 5 Jul 2017 20:14:51 +0300 Subject: [PATCH] Some tweaking to the item interaction logic: - FindItemAtPosition uses the distance calculated in CanInteractWith to determine how close an item is to the character. Otherwise very large items (such as ladders) wouldn't be possible to select with aim assist unless the player happens to be holding the cursor close to the center of the item. - The hull-parameter is taken into account in FindItemAtPosition. - Characters are considered to be inside a trigger if either their lower or upper body is inside it. - Added triggers to engines because they are often placed partially inside a wall, making it impossible to rewire them if the center is not inside the sub. --- .../BarotraumaShared/Content/Items/Engine/engine.xml | 4 ++++ .../BarotraumaShared/Source/Characters/Character.cs | 9 +++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Content/Items/Engine/engine.xml b/Barotrauma/BarotraumaShared/Content/Items/Engine/engine.xml index aedcec445..1f774a460 100644 --- a/Barotrauma/BarotraumaShared/Content/Items/Engine/engine.xml +++ b/Barotrauma/BarotraumaShared/Content/Items/Engine/engine.xml @@ -10,6 +10,8 @@ + + @@ -38,6 +40,8 @@ + + diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index e51ebe7f8..2cb4c7ea5 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -1028,7 +1028,7 @@ namespace Barotrauma // Get the point along the line between lowerBodyPosition and upperBodyPosition which is closest to the center of itemDisplayRect playerDistanceCheckPosition = Vector2.Clamp(transformedTrigger.Center.ToVector2(), lowerBodyPosition, upperBodyPosition); - if (!transformedTrigger.Contains(upperBodyPosition)) return false; + if (!transformedTrigger.Contains(upperBodyPosition) && !transformedTrigger.Contains(lowerBodyPosition)) return false; insideTrigger = true; } @@ -1099,9 +1099,11 @@ namespace Barotrauma foreach (Item item in Item.ItemList) { if (ignoredItems != null && ignoredItems.Contains(item)) continue; + if (hull != null && item.CurrentHull != hull) continue; if (item.body != null && !item.body.Enabled) continue; - - if (CanInteractWith(item)) + + float distanceToItem = float.PositiveInfinity; + if (CanInteractWith(item, out distanceToItem)) { if (item.IsMouseOn(displayPosition)) { @@ -1115,7 +1117,6 @@ namespace Barotrauma } else if (aimAssistModifier > 0.0f) { - float distanceToItem = Vector2.Distance(item.WorldPosition, displayPosition); if (distanceToItem < (100.0f * aimAssistModifier) && (closestItem == null || distanceToItem < closestItemDistance)) { closestItem = item;