增加吃牌的超时设置

This commit is contained in:
zhl 2020-12-07 20:17:27 +08:00
parent a8c44ea05a
commit cffd7f8db1
5 changed files with 34 additions and 2 deletions

View File

@ -6,6 +6,8 @@ import {NextSubCommand} from "./NextSubCommand";
import {GameStateConst} from "../../constants/GameStateConst"; import {GameStateConst} from "../../constants/GameStateConst";
import {singleton} from "../../common/Singleton"; import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv"; import {GameEnv} from "../../cfg/GameEnv";
import {debugRoom} from "../../common/Debug";
import {TurnEndCommand} from "./TurnEndCommand";
/** /**
* *
@ -42,7 +44,7 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
} }
this.state.cards.clear(); this.state.cards.clear();
//停止计时, 并更新player.extraTime; //停止计时, 并更新player.extraTime;
if (this.room.mainClock) { if (this.room.mainClock && this.room.mainClock.active) {
let maxTime = singleton(GameEnv).maxDiscardTime * 1000; let maxTime = singleton(GameEnv).maxDiscardTime * 1000;
let count = this.room.mainClock.elapsedTime - maxTime; let count = this.room.mainClock.elapsedTime - maxTime;
let newCount = player.extraTime - count; let newCount = player.extraTime - count;
@ -64,6 +66,14 @@ export class DiscardCommand extends Command<CardGameState, { client: Client, car
return [new NextSubCommand()]; return [new NextSubCommand()];
} else { } else {
this.state.gameState = GameStateConst.STATE_PICK_PET; this.state.gameState = GameStateConst.STATE_PICK_PET;
let self = this;
let time = singleton(GameEnv).playerActTime * 1000 + player.extraTime;
this.room.mainClock = this.clock.setTimeout(function (){
player.extraTime = 0;
self.room.mainClock.clear();
debugRoom('选随从或者法术时间到, 自动出牌, 自动进入下一轮');
self.room.dispatcher.dispatch(new TurnEndCommand());
}.bind(this), time);
// return [new NextTurnCommand()]; // return [new NextTurnCommand()];
} }
} }

View File

@ -22,6 +22,7 @@ export class DrawCommand extends Command<CardGameState, {}> {
let client = self.room.getClient(sessionId); let client = self.room.getClient(sessionId);
let card = player.cards.values().next().value; let card = player.cards.values().next().value;
debugRoom('出牌时间到, 自动出牌: ', card.id); debugRoom('出牌时间到, 自动出牌: ', card.id);
player.extraTime = 0;
self.room.dispatcher.dispatch(new DiscardCommand(), {client, cards: [card.id], dtype: 1}); self.room.dispatcher.dispatch(new DiscardCommand(), {client, cards: [card.id], dtype: 1});
} }
}, maxTime + player.extraTime) }, maxTime + player.extraTime)

View File

@ -3,6 +3,10 @@ import {CardGameState} from "../schema/CardGameState";
import {Client} from "colyseus"; import {Client} from "colyseus";
import gameUtil from "../../utils/game.util"; import gameUtil from "../../utils/game.util";
import {GameStateConst} from "../../constants/GameStateConst"; import {GameStateConst} from "../../constants/GameStateConst";
import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv";
import {debugRoom} from "../../common/Debug";
import {TurnEndCommand} from "./TurnEndCommand";
/** /**
* *
@ -45,6 +49,14 @@ export class EatCardCommand extends Command<CardGameState, { client: Client, car
player.cardSet.delete(id+''); player.cardSet.delete(id+'');
} }
this.state.gameState = GameStateConst.STATE_PICK_PET; this.state.gameState = GameStateConst.STATE_PICK_PET;
let time = singleton(GameEnv).playerActTime * 1000 + player.extraTime;
let self = this;
this.room.mainClock = this.clock.setTimeout(function (){
player.extraTime = 0;
self.room.mainClock.clear();
debugRoom('选随从或者法术时间到, 自动出牌, 自动进入下一轮');
self.room.dispatcher.dispatch(new TurnEndCommand());
}.bind(this), time);
let fromPlayer = this.state.players.get(this.state.currentTurn); let fromPlayer = this.state.players.get(this.state.currentTurn);
if (fromPlayer.id !== player.id) { if (fromPlayer.id !== player.id) {
this.room.battleMan.onCardLinkReady(player, fromPlayer); this.room.battleMan.onCardLinkReady(player, fromPlayer);

View File

@ -5,6 +5,7 @@ import {singleton} from "../../common/Singleton";
import {GameEnv} from "../../cfg/GameEnv"; import {GameEnv} from "../../cfg/GameEnv";
import {NextTurnCommand} from "./NextTurnCommand"; import {NextTurnCommand} from "./NextTurnCommand";
import {TurnEndCommand} from "./TurnEndCommand"; import {TurnEndCommand} from "./TurnEndCommand";
import {debugRoom, error} from "../../common/Debug";
/** /**
* *
@ -16,7 +17,9 @@ export class NextSubCommand extends Command<CardGameState, {}> {
this.state.giveUpCount = 0; this.state.giveUpCount = 0;
let time = singleton(GameEnv).maxEatTime * 1000; let time = singleton(GameEnv).maxEatTime * 1000;
let self = this; let self = this;
// 启动定时, 到时后自动进入下一轮
this.room.mainClock = this.clock.setTimeout(function (){ this.room.mainClock = this.clock.setTimeout(function (){
debugRoom('吃牌时间到, 进入下一轮')
self.room.mainClock.clear(); self.room.mainClock.clear();
self.room.dispatcher.dispatch(new TurnEndCommand()); self.room.dispatcher.dispatch(new TurnEndCommand());
}, time); }, time);

View File

@ -71,7 +71,13 @@ export class SelectPetCommand extends Command<CardGameState, {client: Client,
if (!targetCard) { if (!targetCard) {
return; return;
} }
//停止计时, 并更新player.extraTime;
if (this.room.mainClock && this.room.mainClock.active) {
let count = this.room.mainClock.elapsedTime - singleton(GameEnv).playerActTime * 1000;
let newCount = player.extraTime - count;
player.extraTime = Math.max(newCount, 0);
this.room.mainClock.clear();
}
let dstplayer = this.state.players.get(playerId); let dstplayer = this.state.players.get(playerId);
let dstpet; let dstpet;