增加放弃吃牌的处理
This commit is contained in:
parent
9cec61b712
commit
ebe958fde1
@ -9,6 +9,7 @@ import {SelectPetCommand} from "./commands/SelectPetCommand";
|
|||||||
import {ChangeCardCommand} from "./commands/ChangeCardCommand";
|
import {ChangeCardCommand} from "./commands/ChangeCardCommand";
|
||||||
import {SelectHeroCommand} from "./commands/SelectHeroCommand";
|
import {SelectHeroCommand} from "./commands/SelectHeroCommand";
|
||||||
import {EatCardCommand} from "./commands/EatCardCommand";
|
import {EatCardCommand} from "./commands/EatCardCommand";
|
||||||
|
import {GiveUpCommand} from "./commands/GiveUpCommand";
|
||||||
|
|
||||||
export class GeneralRoom extends Room {
|
export class GeneralRoom extends Room {
|
||||||
dispatcher = new Dispatcher(this);
|
dispatcher = new Dispatcher(this);
|
||||||
@ -37,7 +38,7 @@ export class GeneralRoom extends Room {
|
|||||||
|
|
||||||
this.onMessage("give_up_eat_c2s", (client, message) => {
|
this.onMessage("give_up_eat_c2s", (client, message) => {
|
||||||
console.log('give_up_take from ', client.sessionId, 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) => {
|
this.onMessage("select_pet_c2s", (client, message) => {
|
||||||
|
17
src/rooms/commands/GiveUpCommand.ts
Normal file
17
src/rooms/commands/GiveUpCommand.ts
Normal 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()];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,7 @@ export class NextSubCommand extends Command<CardGameState, {}> {
|
|||||||
|
|
||||||
execute() {
|
execute() {
|
||||||
this.state.gameState = GameStateConst.STATE_BEGIN_EAT;
|
this.state.gameState = GameStateConst.STATE_BEGIN_EAT;
|
||||||
|
this.state.giveUpCount = 0;
|
||||||
// const sessionIds = [...this.state.players.keys()];
|
// const sessionIds = [...this.state.players.keys()];
|
||||||
// let nextSubTurn = this.state.subTurn ?
|
// let nextSubTurn = this.state.subTurn ?
|
||||||
// sessionIds[(sessionIds.indexOf(this.state.subTurn) + 1) % sessionIds.length]
|
// sessionIds[(sessionIds.indexOf(this.state.subTurn) + 1) % sessionIds.length]
|
||||||
|
@ -46,5 +46,9 @@ export class CardGameState extends Schema {
|
|||||||
* 先手玩家
|
* 先手玩家
|
||||||
*/
|
*/
|
||||||
firstPlayer: string;
|
firstPlayer: string;
|
||||||
|
/**
|
||||||
|
* 放弃吃牌玩家数量
|
||||||
|
*/
|
||||||
|
giveUpCount: number;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user