Show / Hide Table of Contents

Class InventoryUtils

Inheritance
System.Object
InventoryUtils
Namespace: Eco.Gameplay.Items
Assembly: Eco.Gameplay.dll
Syntax
public static class InventoryUtils : Object

Methods

AddItemsWithVoidStorageFallback(LocString, User, Item, Int32)

Declaration
public static void AddItemsWithVoidStorageFallback(LocString name, User user, Item item, int quantity)
Parameters
Type Name Description
LocString name
User user
Item item
System.Int32 quantity

AddItemsWithVoidStorageFallback(LocString, User, IEnumerable<ItemStack>)

Declaration
public static void AddItemsWithVoidStorageFallback(LocString name, User user, IEnumerable<ItemStack> stacks)
Parameters
Type Name Description
LocString name
User user
System.Collections.Generic.IEnumerable<ItemStack> stacks

AggregateStacks(IEnumerable<IEnumerable<IStack>>)

Declaration
public static IEnumerable<IStack> AggregateStacks(this IEnumerable<IEnumerable<IStack>> lists)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable<IStack>> lists
Returns
Type Description
System.Collections.Generic.IEnumerable<IStack>

ApplyRandomInventory(Inventory, Int32, Nullable<Boolean>, Int32, Boolean)

Declaration
public static void ApplyRandomInventory(this Inventory inv, int itemTypes, Nullable<bool> carried = null, int maxCount = 5, bool fixedCount = false)
Parameters
Type Name Description
Inventory inv
System.Int32 itemTypes
System.Nullable<System.Boolean> carried
System.Int32 maxCount
System.Boolean fixedCount

ApplyRandomInventory(SearchAndSelectInventory, Int32, Nullable<Boolean>, Int32)

Declaration
public static void ApplyRandomInventory(this SearchAndSelectInventory inv, int itemTypes, Nullable<bool> carried = null, int maxCount = 5)
Parameters
Type Name Description
SearchAndSelectInventory inv
System.Int32 itemTypes
System.Nullable<System.Boolean> carried
System.Int32 maxCount

CanMoveItems(Inventory, Type, Int32, User, AccessType)

Declaration
public static bool CanMoveItems(this Inventory inventory, Type itemType, int delta, User user, AccessType accessNeeded)
Parameters
Type Name Description
Inventory inventory
System.Type itemType
System.Int32 delta
User user
AccessType accessNeeded
Returns
Type Description
System.Boolean

CanMoveItems(Inventory, Type, Int32, User, ref Int32, AccessType)

Checks whether it's possible for the user to perform changes in this inventory.

Declaration
public static bool CanMoveItems(this Inventory inventory, Type itemType, int delta, User user, ref int allowedQuantity, AccessType accessNeeded)
Parameters
Type Name Description
Inventory inventory
System.Type itemType

Some inventories can allow to move item of specific types (like in workables).

System.Int32 delta

Signed amount of items being moved.

User user
System.Int32 allowedQuantity

Amount of items being moved, absolute value. The value may be adjusted by some restrictions (like in item distribution component).

AccessType accessNeeded
Returns
Type Description
System.Boolean

ContainsItem(Inventory, Item)

Checks if the inventory contains any instances of the requested search Item type instance.

Declaration
public static bool ContainsItem(this Inventory inventory, Item searchItem)
Parameters
Type Name Description
Inventory inventory

Inventory to search

Item searchItem

Item type instance to search for

Returns
Type Description
System.Boolean

True if an instance was found. Otherwise false

FindItemStack(Inventory, Item)

Attempts to find a ItemStack based on an Item type instance inside the Inventory

Declaration
public static ItemStack FindItemStack(this Inventory inventory, Item searchItem)
Parameters
Type Name Description
Inventory inventory

Inventory to search

Item searchItem

Item type instance to search for

Returns
Type Description
ItemStack

The first discovered ItemStack instance if found. Otherwise null

Intersection(IEnumerable<ItemStack>, IEnumerable<ItemStack>)

Declaration
public static IEnumerable<ItemStack> Intersection(this IEnumerable<ItemStack> stacksToCull, IEnumerable<ItemStack> contents)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<ItemStack> stacksToCull
System.Collections.Generic.IEnumerable<ItemStack> contents
Returns
Type Description
System.Collections.Generic.IEnumerable<ItemStack>

MakeGameAction(Inventory, Type, Int32, User, AccessType)

Declaration
public static InventoryAction MakeGameAction(this Inventory inventory, Type itemType, int delta, User user, AccessType accessNeeded)
Parameters
Type Name Description
Inventory inventory
System.Type itemType
System.Int32 delta
User user
AccessType accessNeeded
Returns
Type Description
InventoryAction

MoveItemsWithVoidStorageFallback(LocString, Inventory, Inventory, User, Vector3i, Func<ItemStack, Boolean>)

Move all items to destination, unless they dont all fit, then move all to void storage.

Declaration
public static InventoryMoveResult MoveItemsWithVoidStorageFallback(LocString voidStorageName, Inventory source, Inventory dest, User user, Vector3i pos, Func<ItemStack, bool> testFunc = null)
Parameters
Type Name Description
LocString voidStorageName
Inventory source
Inventory dest
User user
Vector3i pos
System.Func<ItemStack, System.Boolean> testFunc
Returns
Type Description
InventoryMoveResult

We get the quantity moved.

Randomize(SearchAndSelectItem, Int32)

Declaration
public static void Randomize(this SearchAndSelectItem item, int range = 5)
Parameters
Type Name Description
SearchAndSelectItem item
System.Int32 range

SumQuantites(IEnumerable<IStack>)

Declaration
public static int SumQuantites(this IEnumerable<IStack> stacks)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<IStack> stacks
Returns
Type Description
System.Int32

TryGetFirstStackMatchingOrEmpty(Inventory, Func<Item, Boolean>, out ItemStack)

Tries to find first stack matching predicate or if not found then uses first empty stack. It may fail if inventory is full.

Declaration
public static bool TryGetFirstStackMatchingOrEmpty(this Inventory inventory, Func<Item, bool> predicate, out ItemStack itemStack)
Parameters
Type Name Description
Inventory inventory
System.Func<Item, System.Boolean> predicate
ItemStack itemStack
Returns
Type Description
System.Boolean

true if either matching or empty stack was found; false if inventory is full and no matching stack.

☀
☾
In This Article
Back to top
Copyright (c) Strange Loop Games 2021
☀
☾