- 添加 RoomTrusteePayload 接口定义和 ROOM_TRUSTEE 动作类型 - 在玩家状态中增加 trustee 字段用于标识托管状态 - 实现托管模式切换和状态同步功能 - 添加房间倒计时功能支持玩家操作限时 - 实现倒计时 UI 组件显示操作剩余时间 - 修改游戏开始逻辑避免回合开始后重复准备 - 更新 WebSocket 消息处理支持新的托管消息类型 - 添加托管玩家的视觉标识显示托管状态 - 移除房间创建时不必要的总回合数参数
95 lines
1.8 KiB
TypeScript
95 lines
1.8 KiB
TypeScript
import type {GameState, PendingClaimState} from "../types/state";
|
|
import type {Tile} from "../types/tile.ts";
|
|
|
|
export interface RoomPlayerUpdatePayload {
|
|
room_id?: string
|
|
status?: string
|
|
player_count?: number
|
|
player_ids?: string[]
|
|
players?: Array<{
|
|
Index?: number
|
|
index?: number
|
|
PlayerID?: string
|
|
player_id?: string
|
|
PlayerName?: string
|
|
player_name?: string
|
|
AvatarUrl?: string
|
|
avatar_url?: string
|
|
Ready?: boolean
|
|
ready?: boolean
|
|
MissingSuit?: string | null
|
|
missing_suit?: string | null
|
|
}>
|
|
}
|
|
|
|
export interface RoomTrusteePayload {
|
|
player_id?: string
|
|
playerId?: string
|
|
trustee?: boolean
|
|
reason?: string
|
|
}
|
|
|
|
|
|
/**
|
|
* 游戏动作定义(只描述“发生了什么”)
|
|
*/
|
|
export type GameAction =
|
|
// 初始化整局(进入房间 / 断线重连)
|
|
| {
|
|
type: 'GAME_INIT'
|
|
payload: GameState
|
|
}
|
|
|
|
// 开始游戏(发牌完成)
|
|
| {
|
|
type: 'GAME_START'
|
|
payload: {
|
|
dealerIndex: number
|
|
}
|
|
}
|
|
|
|
// 摸牌
|
|
| {
|
|
type: 'DRAW_TILE'
|
|
payload: {
|
|
playerId: string
|
|
tile: Tile
|
|
}
|
|
}
|
|
|
|
// 出牌
|
|
| {
|
|
type: 'PLAY_TILE'
|
|
payload: {
|
|
playerId: string
|
|
tile: Tile
|
|
nextSeat: number
|
|
}
|
|
}
|
|
|
|
// 进入操作窗口(碰/杠/胡)
|
|
| {
|
|
type: 'PENDING_CLAIM'
|
|
payload: PendingClaimState
|
|
}
|
|
|
|
// 操作结束(碰/杠/胡/过)
|
|
| {
|
|
type: 'CLAIM_RESOLVED'
|
|
payload: {
|
|
playerId: string
|
|
action: 'peng' | 'gang' | 'hu' | 'pass'
|
|
}
|
|
}
|
|
|
|
// 房间玩家更新(等待房间人数变化)
|
|
| {
|
|
type: 'ROOM_PLAYER_UPDATE'
|
|
payload: RoomPlayerUpdatePayload
|
|
}
|
|
|
|
| {
|
|
type: 'ROOM_TRUSTEE'
|
|
payload: RoomTrusteePayload
|
|
}
|