25 lines
863 B
TypeScript
25 lines
863 B
TypeScript
import { Command } from "@colyseus/command";
|
|
import { CardGameState } from "../schema/CardGameState";
|
|
import {NextTurnCommand} from "./NextTurnCommand";
|
|
import {GameStateConst} from "../../constants/GameStateConst";
|
|
|
|
/**
|
|
* 下一个吃牌轮
|
|
*/
|
|
export class NextSubCommand extends Command<CardGameState, {}> {
|
|
|
|
execute() {
|
|
this.state.gameState = GameStateConst.STATE_BEGIN_EAT;
|
|
const sessionIds = [...this.state.players.keys()];
|
|
let nextSubTurn = this.state.subTurn ?
|
|
sessionIds[(sessionIds.indexOf(this.state.subTurn) + 1) % sessionIds.length]
|
|
: sessionIds[(sessionIds.indexOf(this.state.currentTurn) + 1) % sessionIds.length];
|
|
if (nextSubTurn !== this.state.currentTurn) {
|
|
this.state.subTurn = nextSubTurn;
|
|
} else {
|
|
return [new NextTurnCommand()];
|
|
}
|
|
}
|
|
|
|
}
|