card_svr/src/rooms/schema/CardGameState.ts
2021-03-02 13:55:56 +08:00

106 lines
2.2 KiB
TypeScript

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<Player>();
/**
* 游戏阶段, 值定义查看 GameStateConst.ts
* 1: 等待玩家准备
* 2: 游戏进行中-出牌轮
* 3: 游戏进行中-吃碰轮
* 4: 游戏中吃牌后的选随从轮
* 9: 游戏结束
*/
@type("number")
gameState: number = GameStateConst.STATE_WAIT_JOIN;
@type("string")
currentTurn: string;
/**
* 用于替换currentTurn的字段,
* 格式: playerId:eatCount
* @type {string}
*/
@type("string")
playerTurn: string;
/**
* currentTurn当中当前玩家吃牌次数
* @type {number}
*/
@type("number")
eatCount: number;
/**
* 用于吃牌时的计轮, 只有在gameState==3的时候才需要判断
*/
@type("string")
subTurn: string;
/**
* 轮次
*/
@type("number")
round: number;
/**
* 游戏模式
* 1: 匹配
* 2: 好友对战
* 3: 娱乐
* @type {number}
*/
@type("number")
mode: number;
/**
* 当局游戏卡组队列
*/
cardQueue: Card[] = [];
/**
* 上轮玩家出的牌
*/
@type({map: Card})
cards = new MapSchema<Card>() ;
/**
* 先手玩家
*/
firstPlayer: string;
/**
* 用于临时存放吃牌的数据
*/
tmpActionMap: Map<string, string[] | number> = new Map();
/**
* 点击重开的玩家数量
*/
restartCount = 0;
/**
* 当前牌局扩展卡库当前最大的card id
*/
maxCardId = 0;
updateGameState(val: number) {
let preVal = this.gameState;
this.gameState = val;
this.$listeners?.gameState?.invoke(val, preVal);
}
updateGameTurn(val: string, eatCount: number) {
let preVal = this.currentTurn;
this.currentTurn = val;
this.eatCount = eatCount;
this.$listeners?.currentTurn?.invoke(val, preVal);
let prePlayerTurn = this.playerTurn
this.playerTurn = `${this.currentTurn}:${this.eatCount}`
this.$listeners?.playerTurn?.invoke(this.playerTurn, prePlayerTurn);
}
get advMode() {
return this.mode == 1 || this.mode == 2
}
}