v0.12.0.2

This commit is contained in:
Joonas Rikkonen
2021-02-10 17:08:21 +02:00
parent 5c80a59bdd
commit 694cdfee7b
353 changed files with 12897 additions and 5028 deletions
@@ -3,6 +3,7 @@ using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Barotrauma
{
@@ -22,19 +23,21 @@ namespace Barotrauma
public override int FindAllowedSlot(Item item)
{
if (ItemOwnsSelf(item)) return -1;
if (ItemOwnsSelf(item)) { return -1; }
//item is already in the inventory!
if (Contains(item)) { return -1; }
if (!container.CanBeContained(item)) { return -1; }
//try to stack first
for (int i = 0; i < capacity; i++)
{
//item is already in the inventory!
if (Items[i] == item) return -1;
if (slots[i].Any() && CanBePut(item, i)) { return i; }
}
if (!container.CanBeContained(item)) return -1;
for (int i = 0; i < capacity; i++)
{
if (Items[i] == null) return i;
if (CanBePut(item, i)) { return i; }
}
return -1;
@@ -42,12 +45,50 @@ namespace Barotrauma
public override bool CanBePut(Item item, int i)
{
if (ItemOwnsSelf(item)) return false;
if (i < 0 || i >= Items.Length) return false;
return (item != null && Items[i] == null && container.CanBeContained(item));
if (ItemOwnsSelf(item)) { return false; }
if (i < 0 || i >= slots.Length) { return false; }
if (!container.CanBeContained(item)) { return false; }
return item != null && slots[i].CanBePut(item) && slots[i].ItemCount < container.MaxStackSize;
}
public override bool TryPutItem(Item item, Character user, List<InvSlotType> allowedSlots = null, bool createNetworkEvent = true)
public override bool CanBePut(ItemPrefab itemPrefab, int i)
{
if (i < 0 || i >= slots.Length) { return false; }
if (!container.CanBeContained(itemPrefab)) { return false; }
return itemPrefab != null && slots[i].CanBePut(itemPrefab) && slots[i].ItemCount < container.MaxStackSize;
}
public override int HowManyCanBePut(ItemPrefab itemPrefab, int i)
{
if (itemPrefab == null) { return 0; }
if (i < 0 || i >= slots.Length) { return 0; }
if (!container.CanBeContained(itemPrefab)) { return 0; }
return slots[i].HowManyCanBePut(itemPrefab, maxStackSize: Math.Min(itemPrefab.MaxStackSize, container.MaxStackSize));
}
public override bool IsFull(bool takeStacksIntoAccount = false)
{
if (takeStacksIntoAccount)
{
for (int i = 0; i < capacity; i++)
{
if (!slots[i].Any()) { return false; }
var item = slots[i].FirstOrDefault();
if (slots[i].ItemCount < Math.Min(item.Prefab.MaxStackSize, container.MaxStackSize)) { return false; }
}
}
else
{
for (int i = 0; i < capacity; i++)
{
if (!slots[i].Any()) { return false; }
}
}
return true;
}
public override bool TryPutItem(Item item, Character user, IEnumerable<InvSlotType> allowedSlots = null, bool createNetworkEvent = true)
{
bool wasPut = base.TryPutItem(item, user, allowedSlots, createNetworkEvent);
@@ -55,8 +96,7 @@ namespace Barotrauma
{
foreach (Character c in Character.CharacterList)
{
if (!c.HasSelectedItem(item)) continue;
if (!c.HeldItems.Contains(item)) { continue; }
item.Unequip(c);
break;
}
@@ -71,13 +111,11 @@ namespace Barotrauma
public override bool TryPutItem(Item item, int i, bool allowSwapping, bool allowCombine, Character user, bool createNetworkEvent = true)
{
bool wasPut = base.TryPutItem(item, i, allowSwapping, allowCombine, user, createNetworkEvent);
if (wasPut)
{
foreach (Character c in Character.CharacterList)
{
if (!c.HasSelectedItem(item)) continue;
if (!c.HeldItems.Contains(item)) { continue; }
item.Unequip(c);
break;
}