From 4e4983f0a6891855c88375a64c9ffa6eb8a3ce60 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sat, 8 Jul 2017 14:32:01 +0300 Subject: [PATCH] If focused on both a character and an item, the one that's closer to the cursor can be interacted with (instead of characters having higher priority, because that would make it impossible to interact with items that are next to a dead/unconscious character). Selected characters can also be deselected without highlighting the character with the cursor. + extra null check in HasRequiredItems --- .../Source/Characters/Character.cs | 28 +++++++++---------- .../Source/Items/Components/ItemComponent.cs | 3 +- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index 045877ef9..a85e46373 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -1232,13 +1232,14 @@ namespace Barotrauma if ((!isLocalPlayer && IsKeyHit(InputType.Select) && GameMain.Server == null) || (isLocalPlayer && (findFocusedTimer <= 0.0f || Screen.Selected == GameMain.EditMapScreen))) { focusedCharacter = FindCharacterAtPosition(mouseSimPos); - if (focusedCharacter != null) + focusedItem = FindItemAtPosition(mouseSimPos, AnimController.InWater ? 0.5f : 0.25f); + + if (focusedCharacter != null && focusedItem != null) { - focusedItem = null; // We can only focus one thing at a time - } - else - { - focusedItem = FindItemAtPosition(mouseSimPos, AnimController.InWater ? 0.5f : 0.25f); + if (Vector2.DistanceSquared(mouseSimPos, focusedCharacter.SimPosition) > Vector2.DistanceSquared(mouseSimPos, focusedItem.SimPosition)) + { + focusedCharacter = null; + } } findFocusedTimer = 0.05f; } @@ -1247,16 +1248,13 @@ namespace Barotrauma findFocusedTimer -= deltaTime; } - if (focusedCharacter != null && IsKeyHit(InputType.Select)) + if (selectedCharacter != null && IsKeyHit(InputType.Select)) { - if (selectedCharacter != null) - { - DeselectCharacter(); - } - else - { - SelectCharacter(focusedCharacter); - } + DeselectCharacter(); + } + else if (focusedCharacter != null && IsKeyHit(InputType.Select)) + { + SelectCharacter(focusedCharacter); } else if (focusedItem != null) { diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs index 5e7508af3..7a884cc10 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/ItemComponent.cs @@ -437,6 +437,7 @@ namespace Barotrauma.Items.Components public bool HasRequiredItems(Character character, bool addMessage) { if (!requiredItems.Any()) return true; + if (character.Inventory == null) return false; foreach (RelatedItem ri in requiredItems) { @@ -449,7 +450,7 @@ namespace Barotrauma.Items.Components } if (!hasItem && ri.Type.HasFlag(RelatedItem.RelationType.Picked)) { - if (character.Inventory.Items.FirstOrDefault(x => x!=null && x.Condition>0.0f && ri.MatchesItem(x))!=null) hasItem = true; + if (character.Inventory.Items.FirstOrDefault(x => x != null && x.Condition > 0.0f && ri.MatchesItem(x)) != null) hasItem = true; } if (!hasItem) {