确认吃牌时,判断卡牌是否在玩家手牌中
This commit is contained in:
parent
2ebcaee257
commit
2254dade50
@ -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);
|
||||
|
@ -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 + '');
|
||||
|
Loading…
x
Reference in New Issue
Block a user