增加放弃吃牌的处理

This commit is contained in:
zhl 2020-12-02 18:02:46 +08:00
parent 9cec61b712
commit ebe958fde1
4 changed files with 24 additions and 1 deletions

View File

@ -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) => {

View File

@ -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<CardGameState, {client: Client}> {
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()];
}
}
}

View File

@ -10,6 +10,7 @@ export class NextSubCommand extends Command<CardGameState, {}> {
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]

View File

@ -46,5 +46,9 @@ export class CardGameState extends Schema {
*
*/
firstPlayer: string;
/**
*
*/
giveUpCount: number;
}