> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 库存集合

> 使用 PlayFab Economy v2 库存集合将玩家库存划分为角色、装载或存储容器的命名组。

# 集合

<Info>
  Economy v2 现已正式发布。如需支持和反馈，请访问 [PlayFab 论坛](https://community.playfab.com)。
</Info>

Economy v2 库存服务引入了集合的概念，可以为你的库存需求增加更大的灵活性和支持。集合是允许单个玩家/PlayerId 拥有多个库存的机制。此功能可用于管理同一玩家的不同角色的多个库存、为不同平台设置单独的库存等！

库存 API 调用可以接受 `CollectionId` 参数，该参数指定要执行操作的集合/库存。通过将物品/堆栈添加到未使用的 CollectionId，可创建新集合。

## 管理库存集合

### GetInventoryCollectionIds

使用 `GetInventoryCollectionIds` API，你可以获取给定玩家的 `CollectionId` 列表。玩家仅限于访问自己的 ID 列表。Title Entities 可以传入 `Entity` 参数以指示他们希望访问哪个玩家的库存。

`GetInventoryCollectionIds` 请求示例：

```json theme={null}
{
  "Entity": {
    "Type": "title_player_account",
    "Id": "ABCD12345678"
  },
  "Count": 15,
  "ContinuationToken": "abc="
}
```

此请求将返回以下响应：

```json theme={null}
{
  "data": {
  "CollectionIds": [
    "default",
    "main_character"
    ]
  }
}
```

#### 延续令牌

从搜索响应返回的 `ContinuationToken` 字段可以传入库存请求，以分页浏览多个计数的结果。

### 添加新库存集合

通过使用新的 CollectionId 执行任何写入请求，即可为玩家创建新集合。

例如，以下 `AddInventoryItems` 请求使用 collectionId `main_character`

```json theme={null}
{
    "Entity": {
        "Type": "title_player_account",
        "Id": "ABCD12345678"
    },
    "CollectionId": "main_character",
    "Item": {
        "Id": "0b440353-bdbc-48d8-8873-f0988c1f9d8b",
    },
    "Amount": 10,
}
```

上述请求要么创建一个全新的库存集合并向其添加 10 个物品，要么如果 `main_character` 库存集合已经存在，则向其添加 10 个物品。

### DeleteInventoryCollection

在 `DeleteInventoryCollectionId` API 中，你可以定义要删除的 `CollectionId`。删除是一个异步操作，对于较大的集合可能需要更长的时间。在删除操作完成之前，将无法重新创建该集合。

`DeleteInventoryCollectionIds` 请求示例：

```json theme={null}
{
  "Entity": {
    "Type": "title_player_account",
    "Id": "ABCD12345678"
  },
  "CollectionId": "main_character"
}
```

<Note>
  目前，API 是删除库存集合的唯一方法。Game Manager 目前只能用于查看和向新集合和现有集合添加物品。将来会添加其他功能。
</Note>

### ExecuteInventoryOperations API

你可以在 `ExecuteInventoryOperations` API 中设置 `CollectionId` 参数。此参数允许你定义要在其中执行操作的集合。

带堆栈的 `ExecuteInventoryOperations` 请求示例：

```json theme={null}
{
    "Entity": {
        "Type": "title_player_account",
        "Id": "ABCD12345678"
    },
    "CollectionId": "main_character",
    "Operations": [
        {
            "Update": {
                "Item" {
                    "Id": "0b440353-bdbc-48d8-8873-f0988c1f9d8b",
                    "Amount": 10
                }
            }
        },
        {
            "Subtract": {
                "Item" {
                    "Id": "0b440353-bdbc-48d8-8873-f0988c1f9d8b",
                },
                "Amount": 5
            }
        }
    ]
}
```


## Related topics

- [Economy V2 限制](/zh-CN/services/playfab/economy-monetization/economy-v2/limits.md)
- [PlayFab 库存 API](/zh-CN/services/playfab/economy-monetization/economy-v2/inventory/index.md)
- [PFInventoryDeleteInventoryCollectionAsync](/zh-CN/services/playfab/api-references/c/pfinventory/functions/pfinventorydeleteinventorycollectionasync.md)
- [库存 ETag](/zh-CN/services/playfab/economy-monetization/economy-v2/inventory/etags.md)
- [物品和库存概览](/zh-CN/services/playfab/economy-monetization/economy-v2/inventory/items-and-inventory-overview.md)
