Fixed items occasionally dropping instead of being moved to another inventory client-side. Closes #558

This commit is contained in:
Joonas Rikkonen
2018-08-02 13:24:56 +03:00
parent 9ab5d76ed1
commit 708f72c883
2 changed files with 25 additions and 16 deletions

View File

@@ -487,13 +487,18 @@ namespace Barotrauma
}
else
{
if (syncItemsCoroutine != null)
{
CoroutineManager.StopCoroutines(syncItemsCoroutine);
syncItemsCoroutine = null;
}
ApplyReceivedState();
}
}
private IEnumerable<object> 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);
}
}

View File

@@ -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;