From 3bc52e2d9512ef5532dee4df4e2732d9b8477411 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 4 Jun 2019 16:42:57 +0300 Subject: [PATCH] (b4fd73057) Reset item position update interval when a client fails to pick it up due to it being accessible (should cause the position of the item to be corrected if the client failed to pick it up due to the position not matching the server position). --- .../BarotraumaServer/Source/Items/Inventory.cs | 14 +++++++------- Barotrauma/BarotraumaShared/Source/Items/Item.cs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Barotrauma/BarotraumaServer/Source/Items/Inventory.cs b/Barotrauma/BarotraumaServer/Source/Items/Inventory.cs index 6083c156e..dde6cbbad 100644 --- a/Barotrauma/BarotraumaServer/Source/Items/Inventory.cs +++ b/Barotrauma/BarotraumaServer/Source/Items/Inventory.cs @@ -43,8 +43,8 @@ namespace Barotrauma CreateNetworkEvent(); for (int i = 0; i < capacity; i++) { - var item = Entity.FindEntityByID(newItemIDs[i]) as Item; - if (item == null) continue; + if (!(Entity.FindEntityByID(newItemIDs[i]) is Item item)) { continue; } + item.PositionUpdateInterval = 0.0f; if (item.ParentInventory != null && item.ParentInventory != this) { item.ParentInventory.CreateNetworkEvent(); @@ -80,16 +80,16 @@ namespace Barotrauma { if (newItemIDs[i] > 0) { - var item = Entity.FindEntityByID(newItemIDs[i]) as Item; - if (item == null || item == Items[i]) continue; + if (!(Entity.FindEntityByID(newItemIDs[i]) is Item item) || item == Items[i]) { continue; } if (GameMain.Server != null) { var holdable = item.GetComponent(); - if (holdable != null && !holdable.CanBeDeattached()) continue; + if (holdable != null && !holdable.CanBeDeattached()) { continue; } if (!prevItems.Contains(item) && !item.CanClientAccess(c)) { + item.PositionUpdateInterval = 0.0f; continue; } } @@ -112,7 +112,7 @@ namespace Barotrauma foreach (Item item in Items.Distinct()) { - if (item == null) continue; + if (item == null) { continue; } if (!prevItems.Contains(item)) { if (Owner == c.Character) @@ -127,7 +127,7 @@ namespace Barotrauma } foreach (Item item in prevItems.Distinct()) { - if (item == null) continue; + if (item == null) { continue; } if (!Items.Contains(item)) { if (Owner == c.Character) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index 9f66bfd6e..964e2651c 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -201,7 +201,7 @@ namespace Barotrauma public float PositionUpdateInterval { get; - private set; + set; } = float.PositiveInfinity; protected Color spriteColor;