Release v0.15.12.0

This commit is contained in:
Joonas Rikkonen
2021-10-27 18:50:57 +03:00
parent bf95e82d80
commit 234fb6bc06
450 changed files with 26042 additions and 10457 deletions
@@ -48,8 +48,8 @@ namespace Barotrauma
return false;
}
}
if (items[0].Prefab.Identifier != item.Prefab.Identifier ||
items.Count + 1 > item.Prefab.MaxStackSize)
if (items[0].Quality != item.Quality) { return false; }
if (items[0].Prefab.Identifier != item.Prefab.Identifier || items.Count + 1 > item.Prefab.MaxStackSize)
{
return false;
}
@@ -57,7 +57,7 @@ namespace Barotrauma
return true;
}
public bool CanBePut(ItemPrefab itemPrefab, float? condition = null)
public bool CanBePut(ItemPrefab itemPrefab, float? condition = null, int? quality = null)
{
if (itemPrefab == null) { return false; }
if (items.Count > 0)
@@ -82,6 +82,11 @@ namespace Barotrauma
if (items.Any(it => !it.IsFullCondition)) { return false; }
}
if (quality.HasValue)
{
if (items[0].Quality != quality.Value) { return false; }
}
if (items[0].Prefab.Identifier != itemPrefab.Identifier ||
items.Count + 1 > itemPrefab.MaxStackSize)
{
@@ -172,6 +177,11 @@ namespace Barotrauma
items.Clear();
}
public void RemoveWhere(Func<Item, bool> predicate)
{
items.RemoveAll(it => predicate(it));
}
public bool Any()
{
return items.Count > 0;
@@ -258,6 +268,8 @@ namespace Barotrauma
get { return capacity; }
}
public bool AllowSwappingContainedItems = true;
public Inventory(Entity owner, int capacity, int slotsPerRow = 5)
{
this.capacity = capacity;
@@ -420,16 +432,16 @@ namespace Barotrauma
return slots[i].CanBePut(item, ignoreCondition);
}
public bool CanBePut(ItemPrefab itemPrefab, float? condition = null)
public bool CanBePut(ItemPrefab itemPrefab, float? condition = null, int? quality = null)
{
for (int i = 0; i < capacity; i++)
{
if (CanBePutInSlot(itemPrefab, i, condition)) { return true; }
if (CanBePutInSlot(itemPrefab, i, condition, quality)) { return true; }
}
return false;
}
public virtual bool CanBePutInSlot(ItemPrefab itemPrefab, int i, float? condition = null)
public virtual bool CanBePutInSlot(ItemPrefab itemPrefab, int i, float? condition = null, int? quality = null)
{
if (i < 0 || i >= slots.Length) { return false; }
return slots[i].CanBePut(itemPrefab, condition);
@@ -496,12 +508,12 @@ namespace Barotrauma
var itemInSlot = slots[i].First();
if (itemInSlot.OwnInventory != null &&
!itemInSlot.OwnInventory.Contains(item) &&
(itemInSlot.GetComponent<ItemContainer>()?.MaxStackSize ?? 0) == 1 &&
(itemInSlot.GetComponent<ItemContainer>()?.GetMaxStackSize(0) ?? 0) == 1 &&
itemInSlot.OwnInventory.TrySwapping(0, item, user, createNetworkEvent, swapWholeStack: false))
{
return true;
}
return
return
TrySwapping(i, item, user, createNetworkEvent, swapWholeStack: true) ||
TrySwapping(i, item, user, createNetworkEvent, swapWholeStack: false);
}
@@ -623,6 +635,8 @@ namespace Barotrauma
protected bool TrySwapping(int index, Item item, Character user, bool createNetworkEvent, bool swapWholeStack)
{
if (item?.ParentInventory == null || !slots[index].Any()) { return false; }
if (slots[index].Items.Any(it => !it.IsInteractable(user))) { return false; }
if (!AllowSwappingContainedItems) { return false; }
//swap to InvSlotType.Any if possible
Inventory otherInventory = item.ParentInventory;
@@ -772,11 +786,17 @@ namespace Barotrauma
{
for (int j = 0; j < capacity; j++)
{
if (slots[j].Contains(item)) { slots[j].RemoveAllItems(); };
if (slots[j].Contains(item))
{
slots[j].RemoveWhere(it => existingItems.Contains(it) || stackedItems.Contains(it));
}
}
for (int j = 0; j < otherInventory.capacity; j++)
{
if (otherInventory.slots[j].Contains(existingItems.FirstOrDefault())) { otherInventory.slots[j].RemoveAllItems(); }
if (otherInventory.slots[j].Contains(existingItems.FirstOrDefault()))
{
otherInventory.slots[j].RemoveWhere(it => existingItems.Contains(it) || stackedItems.Contains(it));
}
}
}