确认吃牌时,判断卡牌是否在玩家手牌中

This commit is contained in:
zhl 2020-12-25 16:31:36 +08:00
parent 2ebcaee257
commit 2254dade50
2 changed files with 20 additions and 10 deletions

View File

@ -5,6 +5,7 @@ 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";
/**
*
@ -16,9 +17,18 @@ export class EatCardCommand extends Command<CardGameState, { client: Client, car
this.room.send(client,'eat_card_s2c', {errcode: 1, errmsg: 'player不存在或者'});
return;
}
if (!gameUtil.checkCardsExists(player.cards, cards)) {
this.room.send(client,'eat_card_s2c', {errcode: 2, errmsg: '要出的牌在手牌中不存在'});
return;
let tmpCards = [];
for (let id of cards) {
if (player.cards.has(id + '')) {
if (!player.cards.get(id + '').number) {
error(`${player.id} 的手牌 ${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: '不能吃自己的牌'});
@ -28,22 +38,19 @@ export class EatCardCommand extends Command<CardGameState, { client: Client, car
this.room.send(client,'eat_card_s2c', {errcode: 4, errmsg: '找不到要吃的牌'});
return;
}
let tmpCards = [];
for (let id of cards) {
tmpCards.push(player.cards.get(id + ''));
}
tmpCards.push(this.state.cards.get(target + ''));
if (!gameUtil.checkDiscard(tmpCards, new GameEnv().otherEatCount)) {
this.room.send(client,'discard_card_s2c', {errcode: 5, errmsg: '不符合吃牌规则'});
this.room.send(client,'eat_card_s2c', {errcode: 5, errmsg: '不符合吃牌规则'});
return;
}
if (this.state.gameState !== GameStateConst.STATE_BEGIN_EAT) {
this.room.send(client,'discard_card_s2c', {errcode: 7, errmsg: '不是吃牌轮'});
this.room.send(client,'eat_card_s2c', {errcode: 7, errmsg: '不是吃牌轮'});
return;
}
//将吃牌数据临时保存
if (this.state.tmpActionMap.has(client.sessionId)) {
this.room.send(client,'discard_card_s2c', {errcode: 8, errmsg: '不可更改操作'});
this.room.send(client,'eat_card_s2c', {errcode: 8, errmsg: '不可更改操作'});
return ;
}
this.state.tmpActionMap.set(client.sessionId, cards);

View File

@ -74,6 +74,9 @@ export class EatConfirmCommand extends Command<CardGameState, { timeUp: boolean
player.cardQueue.clear();
player.cardQueue.push(this.state.cards.values().next().value);
for (let id of cards) {
if (!player.cards.has(id + '')) {
continue;
}
this.state.cards.set(id + '', player.cards.get(id + ''));
player.cardQueue.push(player.cards.get(id + ''));
player.cards.delete(id + '');