Inventory syncing, objHeader is passed to the ClientRead/ServerRead methods so they can determine how to read the msg (is it an inventory update, position, input, etc)

This commit is contained in:
Regalis
2016-12-10 16:39:58 +02:00
parent 108dddf082
commit 1f454d593e
21 changed files with 262 additions and 166 deletions
+17 -17
View File
@@ -141,7 +141,7 @@ namespace Barotrauma
/// <summary>
/// If there is room, puts the item in the inventory and returns true, otherwise returns false
/// </summary>
public override bool TryPutItem(Item item, List<InvSlotType> allowedSlots = null)
public override bool TryPutItem(Item item, List<InvSlotType> allowedSlots = null, bool createNetworkEvent = true)
{
if (allowedSlots == null || ! allowedSlots.Any()) return false;
@@ -152,7 +152,7 @@ namespace Barotrauma
{
if (Items[i] != null || limbSlots[i] != InvSlotType.Any) continue;
PutItem(item, i);
PutItem(item, i, true, createNetworkEvent);
item.Unequip(character);
return true;
}
@@ -178,7 +178,7 @@ namespace Barotrauma
{
if (allowedSlot.HasFlag(limbSlots[i]) && Items[i] == null)
{
PutItem(item, i, !placed);
PutItem(item, i, !placed, createNetworkEvent);
item.Equip(character);
placed = true;
}
@@ -194,7 +194,7 @@ namespace Barotrauma
return placed;
}
public override bool TryPutItem(Item item, int index, bool allowSwapping)
public override bool TryPutItem(Item item, int index, bool allowSwapping, bool createNetworkEvent = true)
{
//there's already an item in the slot
if (Items[index] != null)
@@ -224,8 +224,8 @@ namespace Barotrauma
Items[currentIndex] = null;
Items[index] = null;
//if the item in the slot can be moved to the slot of the moved item
if (TryPutItem(existingItem, currentIndex, false) &&
TryPutItem(item, index, false))
if (TryPutItem(existingItem, currentIndex, false, createNetworkEvent) &&
TryPutItem(item, index, false, createNetworkEvent))
{
}
@@ -235,8 +235,8 @@ namespace Barotrauma
Items[index] = null;
//swapping the items failed -> move them back to where they were
TryPutItem(item, currentIndex, false);
TryPutItem(existingItem, index, false);
TryPutItem(item, currentIndex, false, createNetworkEvent);
TryPutItem(existingItem, index, false, createNetworkEvent);
}
}
@@ -248,7 +248,7 @@ namespace Barotrauma
if (!item.AllowedSlots.Contains(InvSlotType.Any)) return false;
if (Items[index] != null) return Items[index] == item;
PutItem(item, index, true);
PutItem(item, index, true, createNetworkEvent);
return true;
}
@@ -274,12 +274,12 @@ namespace Barotrauma
if (!slotsFree) return false;
return TryPutItem(item, new List<InvSlotType>() {placeToSlots});
return TryPutItem(item, new List<InvSlotType>() {placeToSlots}, createNetworkEvent);
}
protected override void PutItem(Item item, int i, bool removeItem = true)
protected override void PutItem(Item item, int i, bool removeItem = true, bool createNetworkEvent = true)
{
base.PutItem(item, i, removeItem);
base.PutItem(item, i, removeItem, createNetworkEvent);
CreateSlots();
}
@@ -321,7 +321,7 @@ namespace Barotrauma
{
if (doubleClickedItem.ParentInventory != this)
{
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots);
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots, true);
}
else
{
@@ -330,24 +330,24 @@ namespace Barotrauma
var selectedContainer = character.SelectedConstruction.GetComponent<ItemContainer>();
if (selectedContainer != null && selectedContainer.Inventory != null)
{
selectedContainer.Inventory.TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots);
selectedContainer.Inventory.TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots, true);
}
}
else if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null)
{
character.SelectedCharacter.Inventory.TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots);
character.SelectedCharacter.Inventory.TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots, true);
}
else //doubleclicked and no other inventory is selected
{
//not equipped -> attempt to equip
if (IsInLimbSlot(doubleClickedItem, InvSlotType.Any))
{
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any));
TryPutItem(doubleClickedItem, doubleClickedItem.AllowedSlots.FindAll(i => i != InvSlotType.Any), true);
}
//equipped -> attempt to unequip
else if (doubleClickedItem.AllowedSlots.Contains(InvSlotType.Any))
{
TryPutItem(doubleClickedItem, new List<InvSlotType>() { InvSlotType.Any });
TryPutItem(doubleClickedItem, new List<InvSlotType>() { InvSlotType.Any }, true);
}
}
}