- converting NetworkEvent sending time to local time before doing any comparisons
- using mersenne twister for random number generation due to differences in Mono and .NET implementations of the Random library - password prompt for password-protected private servers - fixed deconstructor, fabricator and railgun connection panels closing immediately after opening - fixed editor saving newly created subs to the root folder instead of the Submarines folder - keeping items in the same inventory slots between clients instead of just syncing which items are in the inventory - fixed crashing when swapping items between different limbslots
This commit is contained in:
@@ -149,7 +149,7 @@ namespace Barotrauma
|
||||
return placed;
|
||||
}
|
||||
|
||||
public override bool TryPutItem(Item item, int index, bool createNetworkEvent)
|
||||
public override bool TryPutItem(Item item, int index, bool allowSwapping, bool createNetworkEvent)
|
||||
{
|
||||
//there's already an item in the slot
|
||||
if (Items[index] != null)
|
||||
@@ -173,7 +173,7 @@ namespace Barotrauma
|
||||
combined = true;
|
||||
}
|
||||
//if moving the item between slots in the same inventory
|
||||
else if (item.ParentInventory == this)
|
||||
else if (item.ParentInventory == this && allowSwapping)
|
||||
{
|
||||
int currentIndex = Array.IndexOf(Items, item);
|
||||
|
||||
@@ -182,16 +182,19 @@ 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, false) &&
|
||||
TryPutItem(item, index, false, false))
|
||||
{
|
||||
new Networking.NetworkEvent(Networking.NetworkEventType.InventoryUpdate, Owner.ID, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Items[currentIndex] = null;
|
||||
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, false);
|
||||
TryPutItem(existingItem, index, false, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -416,7 +419,7 @@ namespace Barotrauma
|
||||
|
||||
if (Items[i] != item && Items[i] != null) Items[i].Drop(character, false);
|
||||
|
||||
if (TryPutItem(item, i, false))
|
||||
if (TryPutItem(item, i, false, false))
|
||||
{
|
||||
if (droppedItems.Contains(item))
|
||||
{
|
||||
|
||||
@@ -241,7 +241,7 @@ namespace Barotrauma.Items.Components
|
||||
Item item = MapEntity.FindEntityByID(itemIds[i]) as Item;
|
||||
if (item == null) continue;
|
||||
|
||||
Inventory.TryPutItem(item, i, false);
|
||||
Inventory.TryPutItem(item, i, false, false);
|
||||
}
|
||||
|
||||
itemIds = null;
|
||||
|
||||
@@ -104,7 +104,7 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool TryPutItem(Item item, int i, bool createNetworkEvent = true)
|
||||
public virtual bool TryPutItem(Item item, int i, bool allowSwapping, bool createNetworkEvent)
|
||||
{
|
||||
if (Owner == null) return false;
|
||||
if (CanBePut(item,i))
|
||||
@@ -274,7 +274,7 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
//selectedSlot = slotIndex;
|
||||
TryPutItem(draggingItem, slotIndex);
|
||||
TryPutItem(draggingItem, slotIndex, true, true);
|
||||
draggingItem = null;
|
||||
}
|
||||
|
||||
@@ -351,11 +351,9 @@ namespace Barotrauma
|
||||
|
||||
public virtual bool FillNetworkData(NetworkEventType type, NetBuffer message, object data)
|
||||
{
|
||||
var foundItems = Array.FindAll(Items, i => i != null);
|
||||
message.Write((byte)foundItems.Count());
|
||||
foreach (Item item in foundItems)
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
message.Write((ushort)item.ID);
|
||||
message.Write((ushort)(Items[i]==null ? 0 : Items[i].ID));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -368,31 +366,21 @@ namespace Barotrauma
|
||||
List<ushort> newItemIDs = new List<ushort>();
|
||||
List<Item> droppedItems = new List<Item>();
|
||||
List<Item> prevItems = new List<Item>(Items);
|
||||
|
||||
byte count = message.ReadByte();
|
||||
for (int i = 0; i<count; i++)
|
||||
{
|
||||
newItemIDs.Add(message.ReadUInt16());
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (Items[i] == null) continue;
|
||||
if (!newItemIDs.Contains(Items[i].ID))
|
||||
ushort itemId = message.ReadUInt16();
|
||||
if (itemId==0)
|
||||
{
|
||||
droppedItems.Add(Items[i]);
|
||||
Items[i].Drop(null, false);
|
||||
|
||||
continue;
|
||||
if (Items[i] != null) Items[i].Drop();
|
||||
}
|
||||
}
|
||||
foreach (ushort itemId in newItemIDs)
|
||||
{
|
||||
Item item = Entity.FindEntityByID(itemId) as Item;
|
||||
if (item == null) continue;
|
||||
else
|
||||
{
|
||||
var item = Entity.FindEntityByID(itemId) as Item;
|
||||
if (item == null) continue;
|
||||
|
||||
TryPutItem(item, item.AllowedSlots, false);
|
||||
if (droppedItems.Contains(item)) droppedItems.Remove(item);
|
||||
TryPutItem(item, i, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
lastUpdate = sendingTime;
|
||||
|
||||
@@ -44,9 +44,9 @@ namespace Barotrauma
|
||||
return (item!=null && Items[i]==null && container.CanBeContained(item));
|
||||
}
|
||||
|
||||
public override bool TryPutItem(Item item, int i, bool createNetworkEvent)
|
||||
public override bool TryPutItem(Item item, int i, bool allowSwapping, bool createNetworkEvent)
|
||||
{
|
||||
bool wasPut = base.TryPutItem(item, i, createNetworkEvent);
|
||||
bool wasPut = base.TryPutItem(item, i, allowSwapping, createNetworkEvent);
|
||||
|
||||
if (wasPut)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user