3 using Microsoft.Xna.Framework;
5 using System.Collections.Generic;
15 get {
return container; }
21 this.container = container;
30 if (!container.CanBeContained(item)) {
return -1; }
49 if (i < 0 || i >=
slots.Length) {
return false; }
50 if (!container.CanBeContained(item, i)) {
return false; }
51 return item !=
null &&
slots[i].
CanBePut(item, ignoreCondition) &&
slots[i].
Items.Count < container.GetMaxStackSize(i);
56 if (i < 0 || i >=
slots.Length) {
return false; }
57 if (!container.CanBeContained(itemPrefab, i)) {
return false; }
58 return itemPrefab !=
null &&
slots[i].
CanBePut(itemPrefab, condition, quality) &&
slots[i].
Items.Count < container.GetMaxStackSize(i);
63 if (itemPrefab ==
null) {
return 0; }
64 if (i < 0 || i >=
slots.Length) {
return 0; }
65 if (!container.CanBeContained(itemPrefab, i)) {
return 0; }
69 public override bool IsFull(
bool takeStacksIntoAccount =
false)
71 if (takeStacksIntoAccount)
75 if (!
slots[i].
Any()) {
return false; }
77 if (
slots[i].Items.Count < Math.Min(item.Prefab.GetMaxStackSize(
this), container.GetMaxStackSize(i))) {
return false; }
84 if (!
slots[i].
Any()) {
return false; }
91 public override bool TryPutItem(
Item item,
Character user, IEnumerable<InvSlotType> allowedSlots =
null,
bool createNetworkEvent =
true,
bool ignoreCondition =
false)
93 bool wasPut = base.TryPutItem(item, user, allowedSlots, createNetworkEvent, ignoreCondition);
99 if (!c.
HeldItems.Contains(item)) {
continue; }
104 container.IsActive =
true;
105 container.OnItemContained(item);
107 GameMain.Server?.KarmaManager?.OnItemContained(item, container.
Item, user);
114 public override bool TryPutItem(
Item item,
int i,
bool allowSwapping,
bool allowCombine,
Character user,
bool createNetworkEvent =
true,
bool ignoreCondition =
false)
116 bool wasPut = base.TryPutItem(item, i, allowSwapping, allowCombine, user, createNetworkEvent, ignoreCondition);
121 if (!c.
HeldItems.Contains(item)) {
continue; }
126 container.IsActive =
true;
127 container.OnItemContained(item);
129 GameMain.Server?.KarmaManager?.OnItemContained(item, container.
Item, user);
140 string errorMsg =
"Attempted to create a network event for an item (" + container.Item.Name +
") that hasn't been fully initialized yet.\n" + Environment.StackTrace.CleanupStackTrace();
141 DebugConsole.ThrowError(errorMsg);
142 GameAnalyticsManager.AddErrorEventOnce(
143 "ItemInventory.CreateServerEvent:EventForUninitializedItem" + container.Item.Name + container.Item.ID,
144 GameAnalyticsManager.ErrorSeverity.Error, errorMsg);
148 if (!container.Item.Components.Contains(container))
150 DebugConsole.Log(
"Creating a network event for the item \"" + container.Item +
"\" failed, ItemContainer not found in components");
154 if (slotRange.Start.Value < 0 || slotRange.End.Value >
capacity)
156 DebugConsole.ThrowError($
"Error when creating an inventory event: invalid slot range ({slotRange})\n" + Environment.StackTrace);
169 base.RemoveItem(item);
170 container.OnItemRemoved(item);
static readonly List< Character > CharacterList
IEnumerable< Item >?? HeldItems
Items the character has in their hand slots. Doesn't return nulls and only returns items held in both...
static NetworkMember NetworkMember
int HowManyCanBePut(ItemPrefab itemPrefab, int? maxStackSize=null, float? condition=null, bool ignoreItemsInSlot=false)
Defaults to ItemPrefab.MaxStackSize if null
IReadOnlyList< Item > Items
bool CanBePut(Item item, bool ignoreCondition=false)
readonly int capacity
Capacity, or the number of slots in the inventory.
readonly ItemSlot[] slots
bool Contains(Item item)
Is the item contained in this inventory. Does not recursively check items inside items.
virtual bool ItemOwnsSelf(Item item)
Returns true if the item owns any of the parent inventories.
void Unequip(Character character)
Inventory ParentInventory
static readonly List< Item > ItemList
Item(ItemPrefab itemPrefab, Vector2 position, Submarine submarine, ushort id=Entity.NullEntityID, bool callOnItemLoaded=true)
override bool TryPutItem(Item item, Character user, IEnumerable< InvSlotType > allowedSlots=null, bool createNetworkEvent=true, bool ignoreCondition=false)
If there is room, puts the item in the inventory and returns true, otherwise returns false
override bool IsFull(bool takeStacksIntoAccount=false)
Is there room to put more items in the inventory. Doesn't take stacking into account by default.
override bool CanBePutInSlot(Item item, int i, bool ignoreCondition=false)
Can the item be put in the specified slot.
override void CreateNetworkEvent(Range slotRange)
ItemInventory(Item owner, ItemContainer container, int capacity, int slotsPerRow=5)
override bool CanBePutInSlot(ItemPrefab itemPrefab, int i, float? condition, int? quality=null)
override int HowManyCanBePut(ItemPrefab itemPrefab, int i, float? condition, bool ignoreItemsInSlot=false)
override int FindAllowedSlot(Item item, bool ignoreCondition=false)
override void RemoveItem(Item item)
override bool TryPutItem(Item item, int i, bool allowSwapping, bool allowCombine, Character user, bool createNetworkEvent=true, bool ignoreCondition=false)
int GetMaxStackSize(Inventory inventory)