# Item Pouch

## 🎒 ItemPouch Class

An object that stores a pack of items.

> **Namespace:** `Esper.Inventool.Items`\
> **Access:** `public`\
> **Type:** `class`\
> **Inherits:** `ScriptableObject`

***

### 📦 Fields

| Access   | Field        | Type              | Description                          |
| -------- | ------------ | ----------------- | ------------------------------------ |
| `public` | `itemStacks` | `List<ItemStack>` | A list of item stacks in this pouch. |

***

### 🧰 Methods

| Access   | Method        | Returns           | Description                                                                                   |
| -------- | ------------- | ----------------- | --------------------------------------------------------------------------------------------- |
| `public` | `GetItems()`  | `List<ItemStack>` | Gets all items. Returns copies of each stack. Cleans invalid entries if found.                |
| `public` | `GetRandom()` | `ItemStack`       | Gets a random item stack from the pouch, or `null` if empty. Cleans invalid entries if found. |
| `public` | `Clean()`     | `void`            | Cleans the item list by removing deleted or invalid items, then updates profiles.             |
| `public` | `Save()`      | `void`            | Saves the object. *(Editor only)*                                                             |

## Creating an Item Pouch

Since item pouches are scriptable objects, you can create them with `ScriptableObject.CreateInstance`.

```csharp
ItemPouch itemPouch = ScriptableObject.CreateInstance<ItemPouch>();
```

## Working with an Item Pouch

### Setting Item Stacks

#### Adding

```csharp
itemPouch.itemStacks.Add(itemStack);
```

#### Remove

```csharp
itemPouch.itemStacks.Remove(itemStack);
```

### Getting Items

Its recommended to use the `GetItems` method to get all item stacks from an `ItemPouch`. However, you can get all items by simply accessing the `itemStacks` field.

```csharp
var itemStacks = itemPouch.GetItems();
```

You can also get a single random item from the pouch with the `GetRandom` method.

```csharp
var itemStack = itemPouch.GetRandom();
```
