增加抽卡后超时自动出卡的设定

This commit is contained in:
zhl 2020-12-07 17:36:07 +08:00
parent 3e506bad45
commit 09480cd4c0
3 changed files with 11 additions and 4 deletions

View File

@ -36,7 +36,7 @@ export class GeneralRoom extends Room {
});
this.onMessage("discard_card_c2s", (client, message) => {
debugRoom('discard_card from ', client.sessionId, message);
this.dispatcher.dispatch(new DiscardCommand(), {client, cards: message.cards});
this.dispatcher.dispatch(new DiscardCommand(), {client, cards: message.cards, dtype: 0});
});
this.onMessage("eat_card_c2s", (client, message) => {
debugRoom('eat_card from ', client.sessionId, message);

View File

@ -7,14 +7,16 @@ import {GameStateConst} from "../../constants/GameStateConst";
/**
*
* type: 0,
* type: 1, ,
*/
export class DiscardCommand extends Command<CardGameState, { client: Client, cards: [string] }> {
export class DiscardCommand extends Command<CardGameState, { client: Client, cards: [string], dtype: number }> {
// validate({ client, cards } = this.payload) {
// const player = this.state.players.get(client.sessionId);
// return player !== undefined && gameUtil.checkCardsExists(player.cards, cards);
// }
execute({ client, cards } = this.payload) {
execute({ client, cards , dtype} = this.payload) {
const player = this.state.players.get(client.sessionId);
if (!player) {
client.send('discard_card_s2c', {errcode: 1, errmsg: 'player不存在'});
@ -47,6 +49,7 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
* ,
*
*/
client.send('discard_card_s2c', {errcode: 0, cards: cards, type: dtype})
if (cards.length === 1) {
return [new NextSubCommand()];
} else {

View File

@ -4,6 +4,7 @@ import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv";
import gameUtil from "../../utils/game.util";
import {error} from "../../common/Debug";
import {DiscardCommand} from "./DiscardCommand";
/**
*
@ -15,8 +16,11 @@ export class DrawCommand extends Command<CardGameState, {}> {
let maxTime = singleton(GameEnv).maxDiscardTime;
await this.delay(maxTime * 1000);
if (sessionId == this.state.currentTurn) {
let client = this.room.getClient(sessionId);
error('出牌时间到, 自动出牌');
//TODO: 自动出牌
let player = this.state.players.get(sessionId);
let card = player.cards.values().next().value;
return [new DiscardCommand().setPayload({client, cards: [card.id], dtype: 1})]
}
}
}