From 3e506bad45286577c02f46176d7984f71094bae7 Mon Sep 17 00:00:00 2001 From: zhl Date: Mon, 7 Dec 2020 17:04:47 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=A9=E5=AE=B6=E5=8F=AF=E7=9C=8B=E5=88=B0?= =?UTF-8?q?=E8=87=AA=E5=B7=B1=E7=89=8C=E7=9A=84=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/commands/DrawCommand.ts | 9 ++++++++- src/rooms/commands/NextTurnCommand.ts | 4 +++- src/rooms/schema/Player.ts | 6 +++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/rooms/commands/DrawCommand.ts b/src/rooms/commands/DrawCommand.ts index 39ce509..62f3299 100644 --- a/src/rooms/commands/DrawCommand.ts +++ b/src/rooms/commands/DrawCommand.ts @@ -3,13 +3,20 @@ import {CardGameState} from "../schema/CardGameState"; import {singleton} from "../../common/Singleton"; import {GameEnv} from "../../cfg/GameEnv"; import gameUtil from "../../utils/game.util"; +import {error} from "../../common/Debug"; /** * 正常的抽卡 */ export class DrawCommand extends Command { - execute() { + async execute() { let sessionId = this.state.currentTurn; this.room.addCard(sessionId, singleton(GameEnv).roundDrawNum, 0); + let maxTime = singleton(GameEnv).maxDiscardTime; + await this.delay(maxTime * 1000); + if (sessionId == this.state.currentTurn) { + error('出牌时间到, 自动出牌'); + //TODO: 自动出牌 + } } } diff --git a/src/rooms/commands/NextTurnCommand.ts b/src/rooms/commands/NextTurnCommand.ts index dd9cb09..fdd2f14 100644 --- a/src/rooms/commands/NextTurnCommand.ts +++ b/src/rooms/commands/NextTurnCommand.ts @@ -5,13 +5,15 @@ import {GameStateConst} from "../../constants/GameStateConst"; import {PlayerStateConst} from "../../constants/PlayerStateConst"; import {error} from "../../common/Debug"; import {TurnEndCommand} from "./TurnEndCommand"; +import {singleton} from "../../common/Singleton"; +import {GameEnv} from "../../cfg/GameEnv"; /** * 下一轮 */ export class NextTurnCommand extends Command { - execute() { + async execute() { this.state.gameState = GameStateConst.STATE_BEGIN_DRAW; const sessionIds = [...this.state.players.keys()]; if (!this.state.currentTurn) { diff --git a/src/rooms/schema/Player.ts b/src/rooms/schema/Player.ts index bbbfb17..4d94440 100644 --- a/src/rooms/schema/Player.ts +++ b/src/rooms/schema/Player.ts @@ -1,4 +1,4 @@ -import {MapSchema, SetSchema, Schema, type} from "@colyseus/schema"; +import {MapSchema, SetSchema, Schema, type, filter} from "@colyseus/schema"; import {Pet} from "./Pet"; import {Card} from "./Card"; import {singleton} from "../../common/Singleton"; @@ -15,6 +15,10 @@ export class Player extends Schema { /** * 手牌 */ + @filter(function(this: Player, client, value, root) { + return (client.sessionId == this.id); + }) + @type({ map: Card }) cards = new MapSchema(); @type({ set: "string" })