From 4811ec796f767ada562b0fd09697883aa8de8272 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 8 Apr 2019 19:18:04 +0300 Subject: [PATCH] (50447ac17) Inventory syncing fixes. Could be related to #768. - When moving an item from an inventory to another, create the event for the target inventory first, then for the inventory the item is being removed from. Otherwise clients would first drop the item, and then put it in the container with the next event, which works most of the time, but if the second event is delayed enough that the item is not within the character's reach by the time it arrives, the client will be unable to put it in the container and the item will just be dropped. - Fixed item velocities not being reset when they're dropped from a character's inventory. I'm not exactly sure why, but sometimes they had very high downwards velocities (even though the body was previously inactive), which caused them to launch through floors and made the previous inventory syncing issue much worse (because a delay of just a couple of frames was enough to move the item out of the character's reach). --- .../Source/GameSession/CrewManager.cs | 3 +++ .../Source/Items/Inventory.cs | 14 ++++++------- .../BarotraumaShared/Source/Items/Item.cs | 20 +++++++++++-------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs index 1a7eaf05b..6b9d55aee 100644 --- a/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs +++ b/Barotrauma/BarotraumaClient/Source/GameSession/CrewManager.cs @@ -276,6 +276,9 @@ namespace Barotrauma characterInfos.Add(characterInfo); } + characterInfos.Add(characterInfo); + } + /// /// Remove the character from the crew (and crew menus). /// diff --git a/Barotrauma/BarotraumaShared/Source/Items/Inventory.cs b/Barotrauma/BarotraumaShared/Source/Items/Inventory.cs index 678582ed2..e6e6a9541 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Inventory.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Inventory.cs @@ -170,6 +170,13 @@ namespace Barotrauma Inventory prevInventory = item.ParentInventory; + if (createNetworkEvent) + { + CreateNetworkEvent(); + //also delay syncing the inventory the item was inside + if (prevInventory != null && prevInventory != this) prevInventory.syncItemsDelay = 1.0f; + } + if (removeItem) { item.Drop(user); @@ -187,13 +194,6 @@ namespace Barotrauma { item.body.Enabled = false; } - - if (createNetworkEvent) - { - CreateNetworkEvent(); - //also delay syncing the inventory the item was inside - if (prevInventory != null && prevInventory != this) prevInventory.syncItemsDelay = 1.0f; - } } public bool IsEmpty() diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 35e8db773..cf37c8e41 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -1630,21 +1630,25 @@ namespace Barotrauma } } - foreach (ItemComponent ic in components) { ic.Drop(dropper); } + if (body != null) + { + body.Enabled = true; + body.ResetDynamics(); + if (dropper != null) + { + body.SetTransform(dropper.SimPosition, 0.0f); + } + } + foreach (ItemComponent ic in components) { ic.Drop(dropper); } + if (Container != null) { - if (body != null) - { - body.Enabled = true; - body.LinearVelocity = Vector2.Zero; - } SetTransform(Container.SimPosition, 0.0f); - Container.RemoveContained(this); Container = null; } - + if (parentInventory != null) { parentInventory.RemoveItem(this);