> ## 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 清單。遊戲實體可以傳入 `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-TW/services/playfab/economy-monetization/economy-v2/limits.md)
- [刪除庫存集合](/zh-TW/services/playfab/api-references/rest/economy/inventory/delete-inventory-collection.md)
- [取得庫存集合識別碼](/zh-TW/services/playfab/api-references/rest/economy/inventory/get-inventory-collection-ids.md)
- [PlayFab 庫存 API](/zh-TW/services/playfab/economy-monetization/economy-v2/inventory/index.md)
- [PFInventoryDeleteInventoryCollectionAsync](/zh-TW/services/playfab/api-references/c/pfinventory/functions/pfinventorydeleteinventorycollectionasync.md)
