card_svr/src/rooms/commands/NextTurnCommand.ts

51 lines
1.9 KiB
TypeScript

import {Command} from "@colyseus/command";
import {CardGameState} from "../schema/CardGameState";
import {DrawCommand} from "./DrawCommand";
import {GameStateConst} from "../../constants/GameStateConst";
import {PlayerStateConst} from "../../constants/PlayerStateConst";
import {error} from "../../common/Debug";
import {TurnEndCommand} from "./TurnEndCommand";
import {GameEnv} from "../../cfg/GameEnv";
/**
* 下一轮
*/
export class NextTurnCommand extends Command<CardGameState, {}> {
async execute(){
this.state.updateGameState(GameStateConst.STATE_BEGIN_DRAW);
const sessionIds = [...this.state.players.keys()];
if (!this.state.currentTurn) {
this.state.round = 0;
}
// 如果上一轮是最后一个玩家, 则round + 1;
if (this.state.currentTurn
&& sessionIds.indexOf(this.state.currentTurn) == (sessionIds.length - 1)) {
this.state.round += 1;
// 所有玩家根据配置, 增加5点灵活值
if (this.state.round > 0) {
let moreRoundTime = new GameEnv().roundExtTime * 1000;
let maxTime = new GameEnv().maxExtTime * 1000;
for (let [, p] of this.state.players) {
p.extraTime = Math.min(p.extraTime + moreRoundTime, maxTime);
}
}
}
this.state.updateGameTurn((this.state.currentTurn)
? sessionIds[(sessionIds.indexOf(this.state.currentTurn) + 1) % sessionIds.length]
: sessionIds[0]);
let player = this.state.players.get(this.state.currentTurn);
player.cardQueue.clear();
if (!player) {
error('未找到玩家');
}
this.room.battleMan.onPlayerRoundStart(player);
if (player.state == PlayerStateConst.PLAYER_DEAD) {
return [new TurnEndCommand()];
} else {
return [new DrawCommand()]
}
}
}