合并吃牌和出牌流程
This commit is contained in:
parent
c38c0f1c23
commit
2599b711cd
@ -66,7 +66,7 @@ export class GeneralRoom extends Room {
|
||||
});
|
||||
this.onMessage("discard_card_c2s", (client, message) => {
|
||||
msgLog('discard_card from ', client.sessionId, JSON.stringify(message));
|
||||
this.dispatcher.dispatch(new DiscardCommand(), {client, cards: message.cards, dtype: 0});
|
||||
this.dispatcher.dispatch(new DiscardCommand(), {client, cards: message.cards, target: message.target, dtype: 0});
|
||||
});
|
||||
this.onMessage("eat_card_c2s", (client, message) => {
|
||||
msgLog('eat_card from ', client.sessionId, JSON.stringify(message));
|
||||
|
@ -14,16 +14,17 @@ import {StateTypeEnum} from "../enums/StateTypeEnum";
|
||||
|
||||
/**
|
||||
* 出牌
|
||||
* target: 如果是吃牌, 则带上此字段
|
||||
* type: 0, 正常的抽牌
|
||||
* type: 1, 到时间后, 自动的抽牌
|
||||
*/
|
||||
export class DiscardCommand extends Command<CardGameState, { client: Client, cards: [string], dtype: number }> {
|
||||
export class DiscardCommand extends Command<CardGameState, { client: Client, cards: [string], target?: string, dtype: number }> {
|
||||
// validate({ client, cards } = this.payload) {
|
||||
// const player = this.state.players.get(client.sessionId);
|
||||
// return player !== undefined && gameUtil.checkCardsExists(player.cards, cards);
|
||||
// }
|
||||
|
||||
async execute({ client, cards , dtype} = this.payload) {
|
||||
async execute({ client, cards , target, dtype} = this.payload) {
|
||||
const player = this.state.players.get(client.sessionId);
|
||||
if (!player) {
|
||||
this.room.send(client,'discard_card_s2c', {errcode: 1, errmsg: 'player不存在'});
|
||||
@ -52,9 +53,21 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
|
||||
this.room.send(client,'discard_card_s2c', {errcode: 4, errmsg: '出牌不符合规则'});
|
||||
return;
|
||||
}
|
||||
for (let [key, val] of this.state.cards) {
|
||||
this.state.cards.delete(key);
|
||||
if (target) {
|
||||
if (this.state.cards.size > 1) {
|
||||
this.room.send(client,'discard_card_s2c', {errcode: 6, errmsg: '不符合吃牌规则'});
|
||||
return;
|
||||
}
|
||||
if (!this.state.cards.has(target)) {
|
||||
this.room.send(client,'discard_card_s2c', {errcode: 5, errmsg: '找不到要吃的牌'});
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
for (let [key, val] of this.state.cards) {
|
||||
this.state.cards.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
//停止出牌计时, 并更新player.extraTime;
|
||||
let elapsedTime = this.room.stopSchedule('draw_card');
|
||||
if (elapsedTime >= 0) {
|
||||
@ -78,17 +91,18 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
|
||||
let cardArr: Card[] = [...this.state.cards.values()];
|
||||
let time =this.room.battleMan.onCardDiscarded(player, cardArr[0])
|
||||
await this.delay(time);
|
||||
// return [new NextSubCommand()];
|
||||
if (cardArr[0].type == CardType.general || cardArr[0].type == CardType.variable_unit) {
|
||||
return [new NextSubCommand()];
|
||||
} else {
|
||||
return [new Wait().setPayload(new GameEnv().emptyRoundTime), new TurnEndCommand()];
|
||||
}
|
||||
// 20210219 修改: 出单张牌后直接进入下个玩家的出牌时间
|
||||
// if (cardArr[0].type == CardType.general || cardArr[0].type == CardType.variable_unit) {
|
||||
// return [new NextSubCommand()];
|
||||
// } else {
|
||||
// return [new Wait().setPayload(new GameEnv().emptyRoundTime), new TurnEndCommand()];
|
||||
// }
|
||||
return [new Wait().setPayload(new GameEnv().emptyRoundTime), new TurnEndCommand()];
|
||||
} else {
|
||||
let cardArr: Card[] = [...this.state.cards.values()];
|
||||
let cardids = cardArr.map(o => o.id)
|
||||
let self = this;
|
||||
this.room.send(client,'eat_card_s2c', {player: player.id, errcode: 0, errmsg: '', cards: cardids});
|
||||
this.room.send(client,'eat_card_s2c', {player: player.id, errcode: 0, errmsg: '', cards: cards});
|
||||
let delay = this.room.battleMan.onCardLinkOver(player, cardArr);
|
||||
player.statData.inc(StateTypeEnum.EATCOUNT, 1);
|
||||
await this.delay(delay);
|
||||
|
Loading…
x
Reference in New Issue
Block a user