From 708f72c8832fa7e789c89adede899bb2de111f86 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 2 Aug 2018 13:24:56 +0300 Subject: [PATCH] Fixed items occasionally dropping instead of being moved to another inventory client-side. Closes #558 --- .../Source/Items/Inventory.cs | 21 ++++++++++++------- .../Source/Items/Inventory.cs | 20 ++++++++++-------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs b/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs index 06a11e43c..c4a963467 100644 --- a/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs +++ b/Barotrauma/BarotraumaClient/Source/Items/Inventory.cs @@ -487,13 +487,18 @@ namespace Barotrauma } else { + if (syncItemsCoroutine != null) + { + CoroutineManager.StopCoroutines(syncItemsCoroutine); + syncItemsCoroutine = null; + } ApplyReceivedState(); } } private IEnumerable SyncItemsAfterDelay() { - while (syncItemsDelay > 0.0f && GameMain.Client != null && GameMain.Client.MidRoundSyncing) + while (syncItemsDelay > 0.0f || (GameMain.Client != null && GameMain.Client.MidRoundSyncing)) { syncItemsDelay -= CoroutineManager.DeltaTime; yield return CoroutineStatus.Running; @@ -511,19 +516,21 @@ namespace Barotrauma private void ApplyReceivedState() { - if (receivedItemIDs == null) return; - for (int i = 0; i < capacity; i++) { - if (receivedItemIDs[i] == 0) + if (receivedItemIDs[i] == 0 || (Entity.FindEntityByID(receivedItemIDs[i]) as Item != Items[i])) { if (Items[i] != null) Items[i].Drop(); + System.Diagnostics.Debug.Assert(Items[i] == null); } - else + } + + for (int i = 0; i < capacity; i++) + { + if (receivedItemIDs[i] > 0) { var item = Entity.FindEntityByID(receivedItemIDs[i]) as Item; - if (item == null) continue; - + if (item == null || item == Items[i]) continue; TryPutItem(item, i, true, true, null, false); } } diff --git a/Barotrauma/BarotraumaShared/Source/Items/Inventory.cs b/Barotrauma/BarotraumaShared/Source/Items/Inventory.cs index 0c76077c3..96333d162 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Inventory.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Inventory.cs @@ -202,20 +202,22 @@ namespace Barotrauma { newItemIDs[i] = msg.ReadUInt16(); } - - if (c == null || c.Character == null || !c.Character.CanAccessInventory(this)) - { - return; - } + + if (c == null || c.Character == null || !c.Character.CanAccessInventory(this)) return; for (int i = 0; i < capacity; i++) { - if (newItemIDs[i] == 0) + if (newItemIDs[i] == 0 || (Entity.FindEntityByID(newItemIDs[i]) as Item != Items[i])) { - if (Items[i] != null) Items[i].Drop(c.Character); - System.Diagnostics.Debug.Assert(Items[i]==null); + if (Items[i] != null) Items[i].Drop(); + System.Diagnostics.Debug.Assert(Items[i] == null); } - else + } + + + for (int i = 0; i < capacity; i++) + { + if (newItemIDs[i] > 0) { var item = Entity.FindEntityByID(newItemIDs[i]) as Item; if (item == null || item == Items[i]) continue;