import delay from "delay" ; import { all , call , takeLatest , put } from "redux-saga/effects" ; import { GamePhase } from "@creature-chess/models" ; import { PlayerEvents , GameEvents } from "@creature-chess/gamemode" ; import { BotPersonality } from "@creature-chess/data" ; import { preparingPhase } from "./preparingPhase" ; import { putBenchOnBoard } from "./putBenchOnBoard" ; export const botLogicSaga = function * ( personality ) { yield all ( [ call ( putBenchOnBoard ) , takeLatest < GameEvents . GamePhaseStartedEvent > ( GameEvents . gamePhaseStartedEvent . toString ( ) , function * ( { payload : { phase } } ) { yield delay ( 1000 ) ; if ( phase === GamePhase . PREPARING ) { yield call ( preparingPhase , personality ) ; } else if ( phase === GamePhase . PLAYING ) { yield put ( PlayerEvents . clientFinishMatchEvent ( ) ) ; } } ) ] ) ; } ;