Merge branch 'dev' of https://github.com/Regalis11/Barotrauma.git into unstable-tests

This commit is contained in:
Evil Factory
2022-04-08 12:52:28 -03:00
990 changed files with 44338 additions and 38589 deletions
@@ -10,7 +10,7 @@ namespace Barotrauma
{
partial class Inventory : IServerSerializable, IClientSerializable
{
public const int MaxStackSize = 32;
public const int MaxStackSize = (1 << 6) - 1; //the max value that will fit in 6 bits, i.e 63
public class ItemSlot
{
@@ -18,15 +18,7 @@ namespace Barotrauma
public bool HideIfEmpty;
public IEnumerable<Item> Items
{
get { return items; }
}
public int ItemCount
{
get { return items.Count; }
}
public IReadOnlyList<Item> Items => items;
public bool CanBePut(Item item, bool ignoreCondition = false)
{
@@ -287,7 +279,7 @@ namespace Barotrauma
if (DraggableIndicator == null)
{
DraggableIndicator = GUI.Style.GetComponentStyle("GUIDragIndicator").GetDefaultSprite();
DraggableIndicator = GUIStyle.GetComponentStyle("GUIDragIndicator").GetDefaultSprite();
slotHotkeySprite = new Sprite("Content/UI/InventoryUIAtlas.png", new Rectangle(258, 7, 120, 120), null, 0);
@@ -479,15 +471,15 @@ namespace Barotrauma
{
if (i < 0 || i >= slots.Length)
{
string thisItemStr = item?.prefab.Identifier ?? "null";
string thisItemStr = item?.Prefab.Identifier.Value ?? "null";
string ownerStr = "null";
if (Owner is Item ownerItem)
{
ownerStr = ownerItem.prefab.Identifier;
ownerStr = ownerItem.Prefab.Identifier.Value;
}
else if (Owner is Character ownerCharacter)
{
ownerStr = ownerCharacter.SpeciesName;
ownerStr = ownerCharacter.SpeciesName.Value;
}
string errorMsg = $"Inventory.TryPutItem failed: index was out of range (item: {thisItemStr}, inventory: {ownerStr}).";
GameAnalyticsManager.AddErrorEventOnce("Inventory.TryPutItem:IndexOutOfRange", GameAnalyticsManager.ErrorSeverity.Error, errorMsg);
@@ -533,7 +525,7 @@ namespace Barotrauma
else
{
#if CLIENT
if (visualSlots != null && createNetworkEvent) { visualSlots[i].ShowBorderHighlight(GUI.Style.Red, 0.1f, 0.9f); }
if (visualSlots != null && createNetworkEvent) { visualSlots[i].ShowBorderHighlight(GUIStyle.Red, 0.1f, 0.9f); }
#endif
return false;
}
@@ -636,7 +628,7 @@ namespace Barotrauma
{
if (!slots[i].Any()) { return false; }
var item = slots[i].FirstOrDefault();
if (slots[i].ItemCount < item.Prefab.MaxStackSize) { return false; }
if (slots[i].Items.Count < item.Prefab.MaxStackSize) { return false; }
}
}
else
@@ -776,11 +768,11 @@ namespace Barotrauma
{
for (int j = 0; j < capacity; j++)
{
if (slots[j].Contains(item)) { visualSlots[j].ShowBorderHighlight(GUI.Style.Green, 0.1f, 0.9f); }
if (slots[j].Contains(item)) { visualSlots[j].ShowBorderHighlight(GUIStyle.Green, 0.1f, 0.9f); }
}
for (int j = 0; j < otherInventory.capacity; j++)
{
if (otherInventory.slots[j].Contains(existingItems.FirstOrDefault())) { otherInventory.visualSlots[j].ShowBorderHighlight(GUI.Style.Green, 0.1f, 0.9f); }
if (otherInventory.slots[j].Contains(existingItems.FirstOrDefault())) { otherInventory.visualSlots[j].ShowBorderHighlight(GUIStyle.Green, 0.1f, 0.9f); }
}
}
#endif
@@ -841,7 +833,7 @@ namespace Barotrauma
{
if (slots[j].Contains(existingItems.FirstOrDefault()))
{
visualSlots[j].ShowBorderHighlight(GUI.Style.Red, 0.1f, 0.9f);
visualSlots[j].ShowBorderHighlight(GUIStyle.Red, 0.1f, 0.9f);
}
}
}
@@ -852,29 +844,30 @@ namespace Barotrauma
public virtual void CreateNetworkEvent()
{
if (GameMain.NetworkMember != null)
if (GameMain.NetworkMember == null) { return; }
if (GameMain.NetworkMember.IsClient) { syncItemsDelay = 1.0f; }
if (Owner is Character character)
{
if (GameMain.NetworkMember.IsClient) { syncItemsDelay = 1.0f; }
GameMain.NetworkMember.CreateEntityEvent(Owner as INetSerializable, new object[] { NetEntityEvent.Type.InventoryState });
GameMain.NetworkMember.CreateEntityEvent(character, new Character.InventoryStateEventData());
}
else if (Owner is Item item)
{
GameMain.NetworkMember.CreateEntityEvent(item, new Item.InventoryStateEventData());
}
}
public Item FindItem(Func<Item, bool> predicate, bool recursive)
{
Item match = AllItems.FirstOrDefault(i => predicate(i));
Item match = AllItems.FirstOrDefault(predicate);
if (match == null && recursive)
{
foreach (var item in AllItems)
{
if (item == null) { continue; }
if (item.OwnInventory != null)
{
match = item.OwnInventory.FindItem(predicate, recursive: true);
if (match != null)
{
return match;
}
}
if (item?.OwnInventory == null) { continue; }
match = item.OwnInventory.FindItem(predicate, recursive: true);
if (match != null) { return match; }
}
}
return match;
@@ -900,15 +893,15 @@ namespace Barotrauma
return list;
}
public Item FindItemByTag(string tag, bool recursive = false)
public Item FindItemByTag(Identifier tag, bool recursive = false)
{
if (tag == null) { return null; }
if (tag.IsEmpty) { return null; }
return FindItem(i => i.HasTag(tag), recursive);
}
public Item FindItemByIdentifier(string identifier, bool recursive = false)
public Item FindItemByIdentifier(Identifier identifier, bool recursive = false)
{
if (identifier == null) { return null; }
if (identifier.IsEmpty) { return null; }
return FindItem(i => i.Prefab.Identifier == identifier, recursive);
}
@@ -956,16 +949,31 @@ namespace Barotrauma
slots[index].RemoveItem(item);
}
public void SharedWrite(IWriteMessage msg, object[] extraData = null)
public void SharedRead(IReadMessage msg, out List<ushort>[] newItemIds)
{
byte slotCount = msg.ReadByte();
newItemIds = new List<ushort>[slotCount];
for (int i = 0; i < slotCount; i++)
{
newItemIds[i] = new List<ushort>();
int itemCount = msg.ReadRangedInteger(0, MaxStackSize);
for (int j = 0; j < itemCount; j++)
{
newItemIds[i].Add(msg.ReadUInt16());
}
}
}
public void SharedWrite(IWriteMessage msg, NetEntityEvent.IData extraData = null)
{
msg.Write((byte)capacity);
for (int i = 0; i < capacity; i++)
{
msg.WriteRangedInteger(slots[i].ItemCount, 0, MaxStackSize);
foreach (Item item in slots[i].Items)
msg.WriteRangedInteger(slots[i].Items.Count, 0, MaxStackSize);
for (int j = 0; j < Math.Min(slots[i].Items.Count, MaxStackSize); j++)
{
msg.Write((ushort)(item == null ? 0 : item.ID));
var item = slots[i].Items[j];
msg.Write(item?.ID ?? (ushort)0);
}
}
}