/**
  * @param GameEvent $event
  */
 public function onGameChangeStatusBefore(GameEvent $event)
 {
     if (!in_array($event->getGame()->getStatus(), [GameStatus::END, GameStatus::ABORTED])) {
         return;
     }
     $this->sendGameFinish($this->defaultWsServerUrl, $event->getGame()->getId());
 }
Beispiel #2
0
 /**
  * @param GameEvent $event
  */
 public function calculateGameRating(GameEvent $event)
 {
     if ($event->getGame()->getStatus() != GameStatus::END || !$event->getGame()->isRate()) {
         return;
     }
     if ($event->getGame()->getUserWhite()->isEngine() && !$event->getGame()->getUserBlack()->isEngine() || !$event->getGame()->getUserWhite()->isEngine() && $event->getGame()->getUserBlack()->isEngine()) {
         //            return; // uncomment this line to deny rate play against robots
     }
     $game = $event->getGame();
     $eloGame = $this->getEloGame($game);
     $this->eloCalculator->calculate($eloGame);
     $game->getUserWhite()->setRating($eloGame->getWhiteElo());
     $game->getUserBlack()->setRating($eloGame->getBlackElo());
 }
 /**
  * @param GameEvent $gameEvent
  */
 public function onGameChangeStatus(GameEvent $gameEvent)
 {
     if ($gameEvent->getGame()->getStatus() != GameStatus::END) {
         return;
     }
     try {
         $tournament = $this->getTournamentHandler()->getTournamentForGame($gameEvent->getGame());
     } catch (TournamentGameNotFoundException $e) {
         return;
     }
     if (!$this->getTournamentHandler()->isCurrentRoundFinished($tournament)) {
         return;
     }
     if ($tournament->getStatus() == TournamentStatus::END()) {
         // TODO: send message to users about finishing tournament
         return;
     }
     try {
         $this->assertEventNotExists($tournament);
         $this->addNextRoundToSchedule($tournament);
     } catch (EventAlreadyFoundException $e) {
         $this->container->get("logger")->error("Event is already found. Game #" . $gameEvent->getGame()->getId());
     }
 }
Beispiel #4
0
 /**
  * @param GameEvent $event
  */
 public function onGameChangeStatus(GameEvent $event)
 {
     $game = $event->getGame();
     if ($game->getStatus() != GameStatus::END) {
         return;
     }
     $userWhite = $game->getUserWhite();
     $userBlack = $game->getUserBlack();
     $this->updateWinDrawLoseForOneGame($userWhite, $game);
     $this->updateWinDrawLoseForOneGame($userBlack, $game);
     $this->updateRateTotals($game, $userWhite);
     $this->updateRateTotals($game, $userBlack);
     $this->changeUserLastMove($userWhite, $game);
     $this->changeUserLastMove($userBlack, $game);
 }
Beispiel #5
0
 /**
  * @param GameEvent $event
  */
 public function onGameChangeStatus(GameEvent $event)
 {
     if ($event->getGame()->getStatus() != GameStatus::END) {
         return;
     }
     $this->appendUserGameToHisPgn($event->getGame()->getUserWhite(), $event->getGame());
     $this->appendUserGameToHisPgn($event->getGame()->getUserBlack(), $event->getGame());
 }
Beispiel #6
0
 /**
  * @param GameEvent $gameEvent
  */
 public function onGameChangeStatus(GameEvent $gameEvent)
 {
     if ($gameEvent->getGame()->getStatus() != GameStatus::END) {
         return;
     }
     try {
         $tournament = $this->container->get("core.handler.tournament")->getTournamentForGame($gameEvent->getGame());
     } catch (TournamentGameNotFoundException $e) {
         return;
     }
     $this->updatePlayersTotals($gameEvent->getGame());
     if (!$this->container->get("core.handler.tournament")->isCurrentRoundFinished($tournament)) {
         return;
     }
     $this->container->get("event_dispatcher")->dispatch(TournamentEvents::ROUND_FINISHED, (new TournamentContainer())->setTournament($tournament));
     $this->recalculateCoefficients($tournament);
     if ($tournament->getRounds() == $tournament->getCurrentRound()) {
         $this->changeTournamentStatus($tournament, TournamentStatus::END());
         $this->manager->flush($tournament);
         $this->container->get("event_dispatcher")->dispatch(TournamentEvents::TOURNAMENT_FINISHED, (new TournamentContainer())->setTournament($tournament));
     }
 }