v0.12.0.2
This commit is contained in:
@@ -14,7 +14,7 @@ namespace Barotrauma
|
||||
|
||||
partial class CharacterInventory : Inventory
|
||||
{
|
||||
private Character character;
|
||||
private readonly Character character;
|
||||
|
||||
public InvSlotType[] SlotTypes
|
||||
{
|
||||
@@ -33,8 +33,14 @@ namespace Barotrauma
|
||||
private set;
|
||||
}
|
||||
|
||||
private static string[] ParseSlotTypes(XElement element)
|
||||
{
|
||||
string slotString = element.GetAttributeString("slots", null);
|
||||
return slotString == null ? new string[0] : slotString.Split(',');
|
||||
}
|
||||
|
||||
public CharacterInventory(XElement element, Character character)
|
||||
: base(character, element.GetAttributeString("slots", "").Split(',').Count())
|
||||
: base(character, ParseSlotTypes(element).Length)
|
||||
{
|
||||
this.character = character;
|
||||
IsEquipped = new bool[capacity];
|
||||
@@ -42,7 +48,7 @@ namespace Barotrauma
|
||||
|
||||
AccessibleWhenAlive = element.GetAttributeBool("accessiblewhenalive", true);
|
||||
|
||||
string[] slotTypeNames = element.GetAttributeString("slots", "").Split(',');
|
||||
string[] slotTypeNames = ParseSlotTypes(element);
|
||||
System.Diagnostics.Debug.Assert(slotTypeNames.Length == capacity);
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
@@ -56,11 +62,9 @@ namespace Barotrauma
|
||||
SlotTypes[i] = parsedSlotType;
|
||||
switch (SlotTypes[i])
|
||||
{
|
||||
//case InvSlotType.Head:
|
||||
//case InvSlotType.OuterClothes:
|
||||
case InvSlotType.LeftHand:
|
||||
case InvSlotType.RightHand:
|
||||
hideEmptySlot[i] = true;
|
||||
slots[i].HideIfEmpty = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -83,7 +87,7 @@ namespace Barotrauma
|
||||
continue;
|
||||
}
|
||||
|
||||
Entity.Spawner?.AddToSpawnQueue(itemPrefab, this);
|
||||
Entity.Spawner?.AddToSpawnQueue(itemPrefab, this, ignoreLimbSlots: subElement.GetAttributeBool("forcetoslot", false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,18 +95,28 @@ namespace Barotrauma
|
||||
|
||||
public int FindLimbSlot(InvSlotType limbSlot)
|
||||
{
|
||||
for (int i = 0; i < Items.Length; i++)
|
||||
for (int i = 0; i < slots.Length; i++)
|
||||
{
|
||||
if (SlotTypes[i] == limbSlot) { return i; }
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public Item GetItemInLimbSlot(InvSlotType limbSlot)
|
||||
{
|
||||
for (int i = 0; i < slots.Length; i++)
|
||||
{
|
||||
if (SlotTypes[i] == limbSlot) { return slots[i].FirstOrDefault(); }
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public bool IsInLimbSlot(Item item, InvSlotType limbSlot)
|
||||
{
|
||||
for (int i = 0; i < Items.Length; i++)
|
||||
for (int i = 0; i < slots.Length; i++)
|
||||
{
|
||||
if (Items[i] == item && SlotTypes[i] == limbSlot) { return true; }
|
||||
if (SlotTypes[i] == limbSlot && slots[i].Contains(item)) { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -118,9 +132,9 @@ namespace Barotrauma
|
||||
foreach (var allowedSlot in item.AllowedSlots)
|
||||
{
|
||||
InvSlotType slotsFree = InvSlotType.None;
|
||||
for (int i = 0; i < Items.Length; i++)
|
||||
for (int i = 0; i < slots.Length; i++)
|
||||
{
|
||||
if (allowedSlot.HasFlag(SlotTypes[i]) && Items[i] == null) { slotsFree |= SlotTypes[i]; }
|
||||
if (allowedSlot.HasFlag(SlotTypes[i]) && slots[i].Empty()) { slotsFree |= SlotTypes[i]; }
|
||||
}
|
||||
if (allowedSlot == slotsFree) { return true; }
|
||||
}
|
||||
@@ -130,7 +144,7 @@ namespace Barotrauma
|
||||
/// <summary>
|
||||
/// If there is no room in the generic inventory (InvSlotType.Any), check if the item can be auto-equipped into its respective limbslot
|
||||
/// </summary>
|
||||
public bool TryPutItemWithAutoEquipCheck(Item item, Character user, List<InvSlotType> allowedSlots = null, bool createNetworkEvent = true)
|
||||
public bool TryPutItemWithAutoEquipCheck(Item item, Character user, IEnumerable<InvSlotType> allowedSlots = null, bool createNetworkEvent = true)
|
||||
{
|
||||
// Does not auto-equip the item if specified and no suitable any slot found (for example handcuffs are not auto-equipped)
|
||||
if (item.AllowedSlots.Contains(InvSlotType.Any))
|
||||
@@ -148,7 +162,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, Character user, List<InvSlotType> allowedSlots = null, bool createNetworkEvent = true)
|
||||
public override bool TryPutItem(Item item, Character user, IEnumerable<InvSlotType> allowedSlots = null, bool createNetworkEvent = true)
|
||||
{
|
||||
if (allowedSlots == null || !allowedSlots.Any()) { return false; }
|
||||
if (item == null)
|
||||
@@ -174,7 +188,7 @@ namespace Barotrauma
|
||||
int currentSlot = -1;
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (Items[i] == item)
|
||||
if (slots[i].Contains(item))
|
||||
{
|
||||
currentSlot = i;
|
||||
if (allowedSlots.Any(a => a.HasFlag(SlotTypes[i])))
|
||||
@@ -208,18 +222,18 @@ namespace Barotrauma
|
||||
bool free = true;
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (allowedSlot.HasFlag(SlotTypes[i]) && item.AllowedSlots.Any(s => s.HasFlag(SlotTypes[i])) && Items[i] != null && Items[i] != item)
|
||||
if (allowedSlot.HasFlag(SlotTypes[i]) && item.AllowedSlots.Any(s => s.HasFlag(SlotTypes[i])) && slots[i].Items.Any(it => it != item))
|
||||
{
|
||||
#if CLIENT
|
||||
if (PersonalSlots.HasFlag(SlotTypes[i])) { hidePersonalSlots = false; }
|
||||
#endif
|
||||
if (!Items[i].AllowedSlots.Contains(InvSlotType.Any) || !TryPutItem(Items[i], character, new List<InvSlotType> { InvSlotType.Any }, true))
|
||||
if (!slots[i].First().AllowedSlots.Contains(InvSlotType.Any) || !TryPutItem(slots[i].FirstOrDefault(), character, new List<InvSlotType> { InvSlotType.Any }, true))
|
||||
{
|
||||
free = false;
|
||||
#if CLIENT
|
||||
for (int j = 0; j < capacity; j++)
|
||||
{
|
||||
if (slots != null && Items[j] == Items[i]) slots[j].ShowBorderHighlight(GUI.Style.Red, 0.1f, 0.9f);
|
||||
if (visualSlots != null && slots[j] == slots[i]) { visualSlots[j].ShowBorderHighlight(GUI.Style.Red, 0.1f, 0.9f); }
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -230,7 +244,7 @@ namespace Barotrauma
|
||||
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (allowedSlot.HasFlag(SlotTypes[i]) && item.AllowedSlots.Any(s => s.HasFlag(SlotTypes[i])) && Items[i] == null)
|
||||
if (allowedSlot.HasFlag(SlotTypes[i]) && item.AllowedSlots.Any(s => s.HasFlag(SlotTypes[i])) && slots[i].Empty())
|
||||
{
|
||||
#if CLIENT
|
||||
if (PersonalSlots.HasFlag(SlotTypes[i])) { hidePersonalSlots = false; }
|
||||
@@ -238,7 +252,7 @@ namespace Barotrauma
|
||||
bool removeFromOtherSlots = item.ParentInventory != this;
|
||||
if (placedInSlot == -1 && inWrongSlot)
|
||||
{
|
||||
if (!hideEmptySlot[i] || SlotTypes[currentSlot] != InvSlotType.Any) removeFromOtherSlots = true;
|
||||
if (!slots[i].HideIfEmpty || SlotTypes[currentSlot] != InvSlotType.Any) { removeFromOtherSlots = true; }
|
||||
}
|
||||
|
||||
PutItem(item, i, user, removeFromOtherSlots, createNetworkEvent);
|
||||
@@ -254,35 +268,51 @@ namespace Barotrauma
|
||||
|
||||
public int CheckIfAnySlotAvailable(Item item, bool inWrongSlot)
|
||||
{
|
||||
for (int i = 0; i < capacity; i++)
|
||||
//attempt to stack first
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (SlotTypes[i] != InvSlotType.Any) { continue; }
|
||||
if (!slots[i].Empty() && CanBePut(item, i))
|
||||
{
|
||||
if (SlotTypes[i] != InvSlotType.Any) continue;
|
||||
if (Items[i] == item)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (SlotTypes[i] != InvSlotType.Any) continue;
|
||||
if (inWrongSlot)
|
||||
{
|
||||
if (Items[i] != item && Items[i] != null) continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Items[i] != null) continue;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (SlotTypes[i] != InvSlotType.Any) { continue; }
|
||||
if (slots[i].Contains(item))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (SlotTypes[i] != InvSlotType.Any) { continue; }
|
||||
if (CanBePut(item, i))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (SlotTypes[i] != InvSlotType.Any) { continue; }
|
||||
if (inWrongSlot)
|
||||
{
|
||||
//another item already in the slot
|
||||
if (slots[i].Any() && slots[i].Items.Any(it => it != item)) { continue; }
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!CanBePut(item, i)) { continue; }
|
||||
}
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public override bool TryPutItem(Item item, int index, bool allowSwapping, bool allowCombine, Character user, bool createNetworkEvent = true)
|
||||
{
|
||||
if (index < 0 || index >= Items.Length)
|
||||
if (index < 0 || index >= slots.Length)
|
||||
{
|
||||
string errorMsg = "CharacterInventory.TryPutItem failed: index was out of range(" + index + ").\n" + Environment.StackTrace.CleanupStackTrace();
|
||||
GameAnalyticsManager.AddErrorEventOnce("CharacterInventory.TryPutItem:IndexOutOfRange", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
|
||||
@@ -292,18 +322,16 @@ namespace Barotrauma
|
||||
if (PersonalSlots.HasFlag(SlotTypes[index])) { hidePersonalSlots = false; }
|
||||
#endif
|
||||
//there's already an item in the slot
|
||||
if (Items[index] != null)
|
||||
if (slots[index].Any())
|
||||
{
|
||||
if (Items[index] == item) return false;
|
||||
|
||||
if (slots[index].Contains(item)) { return false; }
|
||||
return base.TryPutItem(item, index, allowSwapping, allowCombine, user, createNetworkEvent);
|
||||
}
|
||||
|
||||
if (SlotTypes[index] == InvSlotType.Any)
|
||||
{
|
||||
if (!item.AllowedSlots.Contains(InvSlotType.Any)) return false;
|
||||
if (Items[index] != null) return Items[index] == item;
|
||||
|
||||
if (!item.AllowedSlots.Contains(InvSlotType.Any)) { return false; }
|
||||
if (slots[index].Any()) { return slots[index].Contains(item); }
|
||||
PutItem(item, index, user, true, createNetworkEvent);
|
||||
return true;
|
||||
}
|
||||
@@ -311,28 +339,24 @@ namespace Barotrauma
|
||||
InvSlotType placeToSlots = InvSlotType.None;
|
||||
|
||||
bool slotsFree = true;
|
||||
List<InvSlotType> allowedSlots = item.AllowedSlots;
|
||||
foreach (InvSlotType allowedSlot in allowedSlots)
|
||||
foreach (InvSlotType allowedSlot in item.AllowedSlots)
|
||||
{
|
||||
if (!allowedSlot.HasFlag(SlotTypes[index])) continue;
|
||||
if (!allowedSlot.HasFlag(SlotTypes[index])) { continue; }
|
||||
#if CLIENT
|
||||
if (PersonalSlots.HasFlag(allowedSlot)) { hidePersonalSlots = false; }
|
||||
#endif
|
||||
for (int i = 0; i < capacity; i++)
|
||||
{
|
||||
if (allowedSlot.HasFlag(SlotTypes[i]) && Items[i] != null && Items[i] != item)
|
||||
if (allowedSlot.HasFlag(SlotTypes[i]) && slots[i].Any() && !slots[i].Contains(item))
|
||||
{
|
||||
slotsFree = false;
|
||||
break;
|
||||
}
|
||||
|
||||
placeToSlots = allowedSlot;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!slotsFree) return false;
|
||||
if (!slotsFree) { return false; }
|
||||
|
||||
return TryPutItem(item, user, new List<InvSlotType>() { placeToSlots }, createNetworkEvent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user