From ebe958fde1309748184ccbf52cd9391ce13a9b6b Mon Sep 17 00:00:00 2001 From: zhl Date: Wed, 2 Dec 2020 18:02:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=94=BE=E5=BC=83=E5=90=83?= =?UTF-8?q?=E7=89=8C=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rooms/GeneralRoom.ts | 3 ++- src/rooms/commands/GiveUpCommand.ts | 17 +++++++++++++++++ src/rooms/commands/NextSubCommand.ts | 1 + src/rooms/schema/CardGameState.ts | 4 ++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/rooms/commands/GiveUpCommand.ts diff --git a/src/rooms/GeneralRoom.ts b/src/rooms/GeneralRoom.ts index 9074e8b..76d0ea8 100644 --- a/src/rooms/GeneralRoom.ts +++ b/src/rooms/GeneralRoom.ts @@ -9,6 +9,7 @@ import {SelectPetCommand} from "./commands/SelectPetCommand"; import {ChangeCardCommand} from "./commands/ChangeCardCommand"; import {SelectHeroCommand} from "./commands/SelectHeroCommand"; import {EatCardCommand} from "./commands/EatCardCommand"; +import {GiveUpCommand} from "./commands/GiveUpCommand"; export class GeneralRoom extends Room { dispatcher = new Dispatcher(this); @@ -37,7 +38,7 @@ export class GeneralRoom extends Room { this.onMessage("give_up_eat_c2s", (client, message) => { console.log('give_up_take from ', client.sessionId, message); - // this.dispatcher.dispatch(new NextSubCommand(), {}); + this.dispatcher.dispatch(new GiveUpCommand(), {client}); }); this.onMessage("select_pet_c2s", (client, message) => { diff --git a/src/rooms/commands/GiveUpCommand.ts b/src/rooms/commands/GiveUpCommand.ts new file mode 100644 index 0000000..999d111 --- /dev/null +++ b/src/rooms/commands/GiveUpCommand.ts @@ -0,0 +1,17 @@ +import {Command} from "@colyseus/command"; +import {CardGameState} from "../schema/CardGameState"; +import {NextTurnCommand} from "./NextTurnCommand"; +import {Client} from "colyseus"; + +/** + * 放弃吃牌 + */ +export class GiveUpCommand extends Command { + execute({client} = this.payload) { + this.state.giveUpCount += 1; + this.room.broadcast('give_up_eat_s2c', {player: client.sessionId}); + if (this.state.giveUpCount >= this.room.maxClients - 1) { + return [new NextTurnCommand()]; + } + } +} diff --git a/src/rooms/commands/NextSubCommand.ts b/src/rooms/commands/NextSubCommand.ts index 043acc0..78bb45e 100644 --- a/src/rooms/commands/NextSubCommand.ts +++ b/src/rooms/commands/NextSubCommand.ts @@ -10,6 +10,7 @@ export class NextSubCommand extends Command { execute() { this.state.gameState = GameStateConst.STATE_BEGIN_EAT; + this.state.giveUpCount = 0; // const sessionIds = [...this.state.players.keys()]; // let nextSubTurn = this.state.subTurn ? // sessionIds[(sessionIds.indexOf(this.state.subTurn) + 1) % sessionIds.length] diff --git a/src/rooms/schema/CardGameState.ts b/src/rooms/schema/CardGameState.ts index 31a1ea0..60e4536 100644 --- a/src/rooms/schema/CardGameState.ts +++ b/src/rooms/schema/CardGameState.ts @@ -46,5 +46,9 @@ export class CardGameState extends Schema { * 先手玩家 */ firstPlayer: string; + /** + * 放弃吃牌玩家数量 + */ + giveUpCount: number; }