import { Schema, MapSchema, type } from "@colyseus/schema"; import {Player} from "./Player"; import {Card} from "./Card"; import {GameStateConst} from "../../constants/GameStateConst"; export class CardGameState extends Schema { @type({ map: Player }) players = new MapSchema(); /** * 游戏阶段, 值定义查看 GameStateConst.ts * 1: 等待玩家准备 * 2: 游戏进行中-出牌轮 * 3: 游戏进行中-吃碰轮 * 4: 游戏中吃牌后的选随从轮 * 9: 游戏结束 */ @type("number") gameState: number = GameStateConst.STATE_WAIT_JOIN; @type("string") currentTurn: string; /** * 用于吃牌时的计轮, 只有在gameState==3的时候才需要判断 */ @type("string") subTurn: string; /** * 轮次 */ @type("number") round: number; /** * 当局游戏卡组队列 */ cardQueue: Card[] = []; /** * 上轮玩家出的牌 */ @type({map: Card}) cards = new MapSchema() ; /** * 先手玩家 */ firstPlayer: string; /** * 用于临时存放吃牌的数据 */ tmpActionMap: Map = new Map(); /** * 点击重开的玩家数量 */ restartCount = 0; updateGameState(val: number) { let preVal = this.gameState; this.gameState = val; this.$listeners.gameState.invoke(val, preVal); } updateGameTurn(val: string) { let preVal = this.currentTurn; this.currentTurn = val; this.$listeners.currentTurn.invoke(val, preVal); } }