Slackwolf\Game\GameManager::changeGameState PHP Method

changeGameState() public method

public changeGameState ( $gameId, $newGameState )
$gameId
$newGameState
    public function changeGameState($gameId, $newGameState)
    {
        $game = $this->getGame($gameId);
        if (!$game) {
            throw new Exception();
        }
        if ($game->hunterNeedsToShoot) {
            $this->sendMessageToChannel($game, "Hunter still needs to kill someone.");
            return;
        }
        if ($game->hunterNeedsToShoot) {
            $this->sendMessageToChannel($game, "It is still night, and the Hunter still needs to kill someone.");
            return;
        }
        if ($game->isOver()) {
            $this->onGameOver($game);
            return;
        }
        // changing from night to day
        if ($game->getState() == GameState::NIGHT && $newGameState == GameState::DAY && !$game->nightEnded) {
            $numSeer = $game->getNumRole(Role::SEER);
            if ($numSeer && !$game->seerSeen()) {
                return;
            }
            $numWolf = count($game->getWerewolves());
            if ($numWolf && !$game->getWolvesVoted()) {
                return;
            }
            $numBodyguard = $game->getNumRole(Role::BODYGUARD);
            if ($numBodyguard && !$game->getGuardedUserId()) {
                return;
            }
            $numWitch = $game->getNumRole(Role::WITCH);
            if ($numWitch && !$game->getWitchHealed()) {
                return;
            }
            if ($numWitch && !$game->getWitchPoisoned()) {
                return;
            }
            $this->onNightEnd($game);
            if ($game->hunterNeedsToShoot) {
                return;
            }
            if ($game->isOver()) {
                $this->onGameOver($game);
                return;
            }
        }
        $game->changeState($newGameState);
        if ($newGameState == GameState::FIRST_NIGHT) {
            $this->onFirstNight($game);
        }
        if ($newGameState == GameState::DAY) {
            $this->onDay($game);
        }
        if ($newGameState == GameState::NIGHT) {
            $this->onNight($game);
        }
    }