Files
netease-bedrock-wiki/mcguide/26-联机大厅/7-竞技模式组件文档.md
2025-08-25 18:36:29 +08:00

258 lines
5.4 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
front: https://nie.res.netease.com/r/pic/20220408/06a1fb24-d76a-4d82-816c-96489966196c.png
hard: 入门
time: 15分钟
---
# 竞技模式组件文档
竞技模式组件为MOD开发者提供统一的竞技模式开始与结算通知事件通过调用相关API和监听固定事件可以将必要的参数通过竞技组件通知webhttpserver进行分数结算。此外游戏过程中的逃跑惩罚也由竞技模式组件通知webhttpserver服务器。
## MOD客户端接入
### API
- SetArenaGamePlayerReady
- 说明
设置当前玩家准备完毕时调用
- 参数
无参数
- 示例
```python
import mod.client.extraClientApi as clientApi
clientApi.SetArenaGamePlayerReady()
```
- 备注
MOD开发者必须调用此函数
- CancelArenaGamePlayerReady
- 说明
设置玩家取消准备时调用
- 参数
无参数
- 示例
```python
import mod.client.extraClientApi as clientApi
clientApi.CancelArenaGamePlayerReady()
```
- 备注
此接口为可选调用
### 事件
- ClientArenaGameAllPlayerReadyEvent
- 说明
当前游戏所有玩家准备完毕后,竞技组件向客户端发出的事件
- 参数
无参数
- 备注
MOD开发者可选择监听此事件切换游戏状态也可以忽略由自定义的MOD服务端逻辑控制游戏状态切换
- ClientArenaGameFinishEvent
- 说明
MOD开发者调用结束API后竞技组件向客户端发出的结束事件
- 参数
游戏结果
```python
[
{
"camp_id": 1,
"result": 1,
"score": 100,
"uid": [
uid1
]
},
{
"camp_id": 2,
"result": 2,
"score": 50,
"uid": [
uid2
]
}
]
```
| 关键字 | 数据类型 | 说明 |
| --- | --- | --- |
| camp_id | int | 阵营不区分默认选0区分最多三个阵营123 |
| result | int | 比赛胜负0平局1胜利2失败 |
| score | int | 分数不需要时传null |
| uid | list string array | 玩家id列表 |
- 备注
MOD开发者可选择监听此事件获取游戏结果也可以由自定义事件从MOD服务端获取结果。在收到此事件后5秒后竞技组件服务端会自动远程调用关闭当前游戏。
## MOD服务端接入
### API
- SetArenaGameResult
- 说明
当前游戏结束时调用,由开发者传入最后结果
- 参数
| 关键字 | 数据类型 | 说明 |
| --- | --- | ---|
| camp_id | int | 阵营不区分默认选0区分最多三个阵营123 |
| result | int | 比赛胜负0平局1胜利2失败 |
| score | int | 分数不需要时传null |
| uid | list string array | 玩家id列表 |
- 示例
```python
resList = [
{
"camp_id": 1,
"result": 1,
"score": 100,
"uid": [
uid1
]
},
{
"camp_id": 2,
"result": 2,
"score": 50,
"uid": [
uid2
]
}
]
serverApi.SetArenaGameResult(resList)
```
- 备注
- 分数设置相关:
- 如果指定自定义的分数,则每项都需要设置`score`的分数。
- 如果使用排行系统默认设置的分数,则每项`score`的值需要设置为None。
- 如果设置`result`为2时即设置为输时分时需要传递扣去分数`score`正数而不是负数
- MOD开发者必须调用此函数设置比赛结果。
### 事件
- ServerArenaGameAllPlayerReadyEvent
- 说明
当前游戏所有玩家准备完毕后,竞技组件向服务端发出的事件
- 参数
无参数
- 备注
MOD开发者可选择监听此事件切换游戏状态也可以忽略由自定义的MOD服务端逻辑控制游戏状态切换
- ServerArenaGamePlayerReconnectSuccessEvent
- 说明
玩家掉线后再次连入时,如果没有超时则触发该事件
- 参数
| 关键字 | 数据类型 | 说明 |
| --- | --- | --- |
| playerId | str | player的entityId |
| uid | str | 玩家的uid |
- 备注
MOD开发者可选择监听此事件决定玩家重连状态。
- ServerArenaGamePlayerReconnectFailedEvent
- 说明
玩家掉线后再次连入时,超时则触发该事件
- 参数
| 关键字 | 数据类型 | 说明 |
| --- | --- | --- |
| playerId | str | player的entityId |
| uid | str | 玩家的uid |
- 备注
MOD开发者可选择监听此事件玩家超时重连会被竞技组件发送消息强制退出该局游戏。
- ServerSetGameResultFailed
- 说明
开发者设置有结果失败时触发该事件
- 参数
| 关键字 | 数据类型 | 说明 |
| :--- | :--- | :--- |
| rcode | int | 错误码 |
| msg | str | 错误信息 |
| detail | str | 错误原因 |
- 备注
错误码含义和对应的详细信息如下:
> **4**:参数为空,缺少某个参数
>
> **12**:参数错误具体见details
> teams 必须为数组
>
> team 参数缺失
>
> result 超出范围 {发送的结果值} (0:平局,1:胜利,2:失败)
>
> camp_id 超出范围 camp_id:{发送的camp_id} camp_num:{阵营数} (阵营数为0camp_id只能为0阵营数大于0,为numcamp_id范围[1,num])
>
> uid 必须为数组
>
> uid 不是房间成员 room_id:{房间id} user_id:{玩家id}
>
> **13**:操作失败具体见details
>
> 房间找不到 {房间id}
>
> 找不到房间成员 {房间id}
>
> 找不到组件信息 {组件id}
>
> 匹配状态错误 room_id:{房间id} user_id:{玩家id} state:{匹配状态} (防止重复结算)
>
> 结算失败
>
> **12028**:房间秘钥计算错误