(c01fdfc22) Attempt to fix items dropping out of the inventory in multiplayer, part 527: Inventory.ServerRead first drops all items that are in incorrect slots from the inventory, and then places the current items into correct slots. I think the problem was that the items were not necessarily dropped at the exact position of the character, because the physics update is run between the item position update and reading the network event. This occasionally caused the item to end up in a position where the character can't pick it again when placing the items into correct slots. Now the position of the item is forced to the position of the character during the dropping, and the CanClientAccess check is not done on items that were already in the character's inventory.

This commit is contained in:
Joonas Rikkonen
2019-05-23 15:17:55 +03:00
parent 4c3e5f324f
commit 5c06210265
@@ -62,7 +62,16 @@ namespace Barotrauma
if (newItemIDs[i] == 0 || (newItem != Items[i]))
{
if (Items[i] != null) Items[i].Drop(null);
if (Items[i] != null)
{
Item droppedItem = Items[i];
Entity prevOwner = Owner;
droppedItem.Drop(null);
if (droppedItem.body != null && prevOwner != null)
{
droppedItem.body.SetTransform(prevOwner.SimPosition, 0.0f);
}
}
System.Diagnostics.Debug.Assert(Items[i] == null);
}
}
@@ -79,7 +88,10 @@ namespace Barotrauma
var holdable = item.GetComponent<Holdable>();
if (holdable != null && !holdable.CanBeDeattached()) continue;
if (!item.CanClientAccess(c)) continue;
if (!prevItems.Contains(item) && !item.CanClientAccess(c))
{
continue;
}
}
TryPutItem(item, i, true, true, c.Character, false);
for (int j = 0; j < capacity; j++)