import { Command } from '@colyseus/command';
import IChessState from '../../types/IChessState';
import { Message } from '../../types/Messages';

export default class NextTurnCommand extends Command<IChessState> {
  execute() {
    const activePlayer = this.room.state.activePlayer;

    if (activePlayer === 0) {
      this.room.state.activePlayer = 1;
    } else {
      this.room.state.activePlayer = 0;
    }

    // broadcast player"s turn
    this.room.broadcast(Message.PlayerIndex, this.room.state.activePlayer);
  }
}
