From 3041138f0364a2c002e09c9144b1f6e88ed57980 Mon Sep 17 00:00:00 2001 From: Regalis Date: Tue, 10 Jan 2017 20:50:31 +0200 Subject: [PATCH] Inventory.TryPutItem doesn't put an item in the inventory (or create a NetEntityEvent) if the item is already in it --- Subsurface/Source/Items/CharacterInventory.cs | 11 ++++++++++- Subsurface/Source/Items/Inventory.cs | 2 +- .../NetEntityEvent/NetEntityEventManager.cs | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Subsurface/Source/Items/CharacterInventory.cs b/Subsurface/Source/Items/CharacterInventory.cs index 08f4d584e..928fccc9b 100644 --- a/Subsurface/Source/Items/CharacterInventory.cs +++ b/Subsurface/Source/Items/CharacterInventory.cs @@ -143,7 +143,16 @@ namespace Barotrauma /// public override bool TryPutItem(Item item, List allowedSlots = null, bool createNetworkEvent = true) { - if (allowedSlots == null || ! allowedSlots.Any()) return false; + if (allowedSlots == null || !allowedSlots.Any()) return false; + + for (int i = 0; i < capacity; i++) + { + //already in the inventory and in a suitable slot + if (Items[i] == item && allowedSlots.Any(a => a.HasFlag(limbSlots[i]))) + { + return true; + } + } //try to place the item in LimBlot.Any slot if that's allowed if (allowedSlots.Contains(InvSlotType.Any)) diff --git a/Subsurface/Source/Items/Inventory.cs b/Subsurface/Source/Items/Inventory.cs index e2d6b85b3..2bee29071 100644 --- a/Subsurface/Source/Items/Inventory.cs +++ b/Subsurface/Source/Items/Inventory.cs @@ -568,7 +568,7 @@ namespace Barotrauma else { var item = Entity.FindEntityByID(newItemIDs[i]) as Item; - if (item == null) continue; + if (item == null || item == Items[i]) continue; if (GameMain.Server != null) { diff --git a/Subsurface/Source/Networking/NetEntityEvent/NetEntityEventManager.cs b/Subsurface/Source/Networking/NetEntityEvent/NetEntityEventManager.cs index 2a76f05f6..ce179e20f 100644 --- a/Subsurface/Source/Networking/NetEntityEvent/NetEntityEventManager.cs +++ b/Subsurface/Source/Networking/NetEntityEvent/NetEntityEventManager.cs @@ -76,7 +76,7 @@ namespace Barotrauma.Networking { long msgPosition = msg.Position; - DebugConsole.NewMessage("received msg "+thisEventID, Microsoft.Xna.Framework.Color.Green); + DebugConsole.NewMessage("received msg "+thisEventID+ " ("+entity.ToString()+")", Microsoft.Xna.Framework.Color.Green); lastReceivedID++; try {