From b598459179b035bdcdbaffe226106df5aa886ec4 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 12 Jun 2019 16:44:18 +0300 Subject: [PATCH] (65e2b5073) Fixed crashing when an item that requires aim to use is used by something else than a character. Not sure if there are any vanilla items that can cause this error, but can be reproduced for example by creating a projectile that RequiresAimToUse and triggers the Use method when it hits something. Closes #1602 --- .../BarotraumaClient/Source/Map/MapEntity.cs | 52 ------------------- .../BarotraumaShared/Source/Items/Item.cs | 2 +- 2 files changed, 1 insertion(+), 53 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs b/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs index a739629e9..215e2db4d 100644 --- a/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs +++ b/Barotrauma/BarotraumaClient/Source/Map/MapEntity.cs @@ -632,58 +632,6 @@ namespace Barotrauma } } - if ((PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl))) - { - if (PlayerInput.KeyHit(Keys.N)) - { - float minX = selectedList[0].WorldRect.X, maxX = selectedList[0].WorldRect.Right; - for (int i = 0; i < selectedList.Count; i++) - { - minX = Math.Min(minX, selectedList[i].WorldRect.X); - maxX = Math.Max(maxX, selectedList[i].WorldRect.Right); - } - - float centerX = (minX + maxX) / 2.0f; - foreach (MapEntity me in selectedList) - { - me.FlipX(false); - me.Move(new Vector2((centerX - me.WorldPosition.X) * 2.0f, 0.0f)); - } - } - else if (PlayerInput.KeyHit(Keys.M)) - { - float minY = selectedList[0].WorldRect.Y - selectedList[0].WorldRect.Height, maxY = selectedList[0].WorldRect.Y; - for (int i = 0; i < selectedList.Count; i++) - { - minY = Math.Min(minY, selectedList[i].WorldRect.Y - selectedList[i].WorldRect.Height); - maxY = Math.Max(maxY, selectedList[i].WorldRect.Y); - } - - float centerY = (minY + maxY) / 2.0f; - foreach (MapEntity me in selectedList) - { - me.FlipY(false); - me.Move(new Vector2(0.0f, (centerY - me.WorldPosition.Y) * 2.0f)); - } - } - } - FilteredSelectedList.Clear(); - if (selectedList.Count == 0) return; - foreach (var e in selectedList) - { - if (e is Gap) { continue; } - FilteredSelectedList.Add(e); - } - var first = FilteredSelectedList.FirstOrDefault(); - if (first != null) - { - first.UpdateEditing(cam); - if (first.ResizeHorizontal || first.ResizeVertical) - { - first.UpdateResizing(cam); - } - } - if ((PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl))) { if (PlayerInput.KeyHit(Keys.N)) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index d62ab48bb..a5ab1fa32 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -1553,7 +1553,7 @@ namespace Barotrauma public void Use(float deltaTime, Character character = null, Limb targetLimb = null) { - if (RequireAimToUse && !character.IsKeyDown(InputType.Aim)) + if (RequireAimToUse && (character == null || !character.IsKeyDown(InputType.Aim))) { return; }