# 在你的多个游戏之间共享排行榜和成就

> 让智能体创建一个 Game Center 群组，把你的两个或更多游戏放进去，并为该群组添加群组中每个游戏共享的排行榜和成就。

Source: https://air.build/cn/docs/app-store/share-game-center-between-your-games/

Game Center 群组让你的两个或更多游戏共享排行榜、成就、挑战和活动，例如同一个游戏的免费版和付费版。Apple 的帮助说一个 App 只能属于一个群组，而且一个群组可以混合不同平台的 App，例如一个 iOS App 和一个 macOS App。参见 Apple 的 [Overview of Game Center groups](https://developer.apple.com/help/app-store-connect/configure-game-center/overview-of-game-center-groups)。

> [!NOTE]
> AirBuild 没有 Game Center 界面。你在项目的聊天中询问智能体，它会使用 `asc game-center groups` 和 `asc game-center details`（列在 [asc：App 与 App Store 页面](https://air.build/cn/docs/cli/asc-apps/#game-center) 的 `game-center` 下）。要查看结果，请询问智能体，或在 App Store Connect 中打开你的 App。

## 提出请求之前

- 每个游戏都需要 Game Center。参见[添加 Game Center 排行榜和成就](https://air.build/cn/docs/app-store/add-game-center-leaderboards/)。
- 这些游戏必须是你的智能体所用 Apple 团队中的 App。`asc` 使用团队拥有者在 AirBuild 中关联的 Apple 团队。参见[关联你的 Apple 开发者账户](https://air.build/cn/docs/app-store/connect-apple-developer-account/)。
- `asc` 可以把游戏放进群组，但它的帮助中没有再把游戏移出的方法。Apple 的 [Manage groups](https://developer.apple.com/help/app-store-connect/configure-game-center/manage-groups) 介绍了 App 何时以及如何在网页版 App Store Connect 中离开群组。
- 如果你的游戏已经有自己的排行榜或成就，`asc` 的帮助没有说明游戏加入群组时它们会怎样。在网页版 App Store Connect 中，Apple 会引导你选择群组保留哪些；参见 [Manage groups](https://developer.apple.com/help/app-store-connect/configure-game-center/manage-groups)。对于这样的游戏，你可能更愿意在那里进行。

## 创建群组

在任一游戏的项目聊天中提出请求，并说出两个游戏的名称，例如：

```text
Make a Game Center group called "Fox Run games" and put Fox Run and Fox Run Lite in it.
```

1. 智能体用 `asc game-center groups create` 创建群组。群组的参考名称是供你使用的，玩家看不到。
2. 对于每个游戏，它用 `asc game-center details update --game-center-group-id` 把该游戏的 Game Center 设置放进群组。
3. 它用 `asc game-center groups details list` 检查群组中有哪些游戏，并在聊天中告诉你。

## 添加共享的排行榜和成就

像为单个游戏那样提出请求，并说明它们是给群组的，例如：

```text
Add a shared leaderboard for the best score, highest first, to the Fox Run games group, and an achievement for the first win. Then update both games to use them.
```

- 智能体用 `--group-id` 创建它们，例如 `asc game-center leaderboards create --group-id`。挑战、活动和排行榜组也可以用同样的方式属于群组。
- 群组的排行榜和成就有自己的 ID，以 `grp.` 开头。没有这个前缀的 ID 会被 `asc` 拒绝。
- 每个游戏的代码按 ID 报告分数和成就，所以每个游戏都需要修改才能使用群组的 ID。智能体可以在每个游戏的项目中进行修改。

要查看群组包含什么，请问“Fox Run games 群组中有什么？”。智能体会用 `asc game-center groups leaderboards list`、`achievements list`、`leaderboard-sets list`、`activities list` 和 `challenges list` 列出。

### 你还可以设置什么

| 选项 | 方式 |
| --- | --- |
| 哪些排行榜或成就属于群组 | `asc game-center groups leaderboards set` 或 `achievements set`。每个命令都会用给出的列表替换群组的整个列表，所以需要 `--confirm`，智能体会先询问你。请说出完整的列表。 |
| 游戏首先显示哪个群组排行榜 | 为每个游戏运行 `asc game-center details update --default-group-leaderboard-v2-id`。 |
| 群组的参考名称 | `asc game-center groups update`。 |

## 发布游戏

新的群组排行榜和成就与单个游戏的一样需要经过 App 审核：让智能体把它们添加到你下一次 App 审核提交中（`asc review items add`），然后照常提交。参见[提交 App 审核并发布](https://air.build/cn/docs/app-store/submit-for-review/#submit-a-version)。

Apple 的 [Overview of Game Center groups](https://developer.apple.com/help/app-store-connect/configure-game-center/overview-of-game-center-groups) 说明了哪些内容随每个游戏的版本上线，以及哪些内容无需版本也会保持上线。

## 常见问题

**一个游戏可以属于两个群组吗？**

不可以。Apple 的帮助说一个 App 只能属于一个群组。

**可以把游戏移出群组吗？**

`asc` 没有这样的命令。Apple 的 [Manage groups](https://developer.apple.com/help/app-store-connect/configure-game-center/manage-groups) 介绍了如何在网页版 App Store Connect 中将 App 从群组中移除，以及何时可以这样做。

**智能体说 ID 必须以 grp. 开头。**

`asc` 停止并显示 `--vendor-id must start with "grp." when using --group-id`。为群组制作的排行榜、成就、挑战、活动和排行榜组需要以 `grp.` 开头的 ID。请让智能体用这样的 ID 再试一次。

**可以删除群组吗？**

询问智能体。`asc game-center groups delete` 需要 `--confirm`，所以它会先询问你。`asc` 没有恢复已删除群组的命令。

**两个游戏的玩家可以一起在线游玩吗？**

这是在 App Store Connect 中按游戏版本设置的多人游戏兼容性；`asc` 可以列出它，但不能设置。参见 Apple 的 [Add multiplayer compatibility](https://developer.apple.com/help/app-store-connect/configure-game-center/add-multiplayer-compatibility)，以及[用 Game Center 为在线对战匹配玩家](https://air.build/cn/docs/app-store/match-players-for-multiplayer/)。
