import {Command} from "@colyseus/command"; import {CardGameState} from "../schema/CardGameState"; import {Client} from "colyseus"; import gameUtil from "../../utils/game.util"; import {GameStateConst} from "../../constants/GameStateConst"; import {EatConfirmCommand} from "./EatConfirmCommand"; import {GameEnv} from "../../cfg/GameEnv"; import {error} from "../../common/Debug"; /** * 吃牌 */ export class EatCardCommand extends Command { execute({ client, cards, target } = this.payload) { const player = this.state.players.get(client.sessionId); if (!player) { this.room.send(client,'eat_card_s2c', {errcode: 1, errmsg: 'player不存在或者'}); return; } let tmpCards = []; let cardIds = []; for (let id of cards) { if (player.cards.has(id + '')) { if (!player.cards.get(id + '').number) { error(`${player.id} 的手牌 ${id} 数据有问题`); continue; } cardIds.push(id); tmpCards.push(player.cards.get(id + '')); } else { error(`${player.id} 出的牌 ${id} 在手牌中不存在`) this.room.send(client,'eat_card_s2c', {errcode: 2, errmsg: `要出的牌 ${id} 在手牌中不存在`}); return; } } if (this.state.currentTurn == client.sessionId) { this.room.send(client,'eat_card_s2c', {errcode: 3, errmsg: '不能吃自己的牌'}); return; } if (!this.state.cards.has(target + '')) { this.room.send(client,'eat_card_s2c', {errcode: 4, errmsg: '找不到要吃的牌'}); return; } tmpCards.push(this.state.cards.get(target + '')); if (!gameUtil.checkDiscard(tmpCards, new GameEnv().otherEatCount)) { this.room.send(client,'eat_card_s2c', {errcode: 5, errmsg: '不符合吃牌规则'}); return; } if (this.state.gameState !== GameStateConst.STATE_BEGIN_EAT) { this.room.send(client,'eat_card_s2c', {errcode: 7, errmsg: '不是吃牌轮'}); return; } //将吃牌数据临时保存 if (this.state.tmpActionMap.has(client.sessionId)) { this.room.send(client,'eat_card_s2c', {errcode: 8, errmsg: '不可更改操作'}); return ; } this.state.tmpActionMap.set(client.sessionId, cardIds); return [new EatConfirmCommand().setPayload({timeUp: false})]; } }