public function toArray()
 {
     return ['dealerHand' => $this->serializeHand($this->table->getDealerHand()), 'seats' => $this->table->getSeats()->map(function (TableSeat $seat) {
         if ($seat->isFree()) {
             return ['seatIndex' => $seat->getSeatIndex(), 'free' => true];
         }
         return ['seatIndex' => $seat->getSeatIndex(), 'player' => $this->serializePlayer($seat->getPlayer()), 'hands' => $seat->getHands()->map(function (HandBetPair $hand) {
             return ['hand' => $this->serializeHand($hand->getHand()), 'bet' => $hand->getBet()];
         })->elements()];
     })->elements()];
 }
 public function distributePlayerWinnings(Player $player, HandBetPair $hand)
 {
     return parent::distributePlayerWinnings($player, $hand)->then(function ($winnings) use($player, $hand) {
         $this->broadcast(new PlayerHandResultMessage($player, $hand, $winnings));
         return $winnings;
     });
 }
Esempio n. 3
0
 /**
  * @return Promise
  */
 private function distributeWinnings()
 {
     $promise = \Blackjack\Promise\timedResolve(self::LONG_PAUSE_SPEED);
     foreach ($this->table->getSeats() as $seat) {
         if (!$seat->isInPlay()) {
             continue;
         }
         foreach ($seat->getHands() as $hand) {
             // Chain actions
             $promise = $promise->then(function () use($seat, $hand) {
                 return $this->table->distributePlayerWinnings($seat->getPlayer(), $hand)->then(function ($winnings) use($seat, $hand) {
                     if ($winnings === $hand->getBet()) {
                         $message = 'Player draws with dealer';
                     } elseif ($winnings > $hand->getBet()) {
                         $message = 'Player beats dealer';
                     } else {
                         $message = 'Player loses to dealer';
                     }
                     $this->logger->info($message, ['player' => $seat->getPlayer()->getName(), 'bet' => $hand->getBet(), 'winnings' => $winnings, 'playerHand' => (string) $hand->getHand(), 'dealerHand' => (string) $this->table->getDealerHand()]);
                 });
             });
         }
     }
     return $promise;
 }
Esempio n. 4
0
 public function log($level, $message, array $context = array())
 {
     $this->logger->log($level, $message, array_merge($context, ['table' => $this->table->getId()]));
 }
 public function broadcastMessageIgnoringPlayer(Table $table, Player $ignoredPlayer, ServerMessageInterface $message)
 {
     $promises = [];
     foreach ($table->getSeats() as $seat) {
         $player = $seat->getPlayer();
         if ($player === null || $player === $ignoredPlayer) {
             continue;
         }
         if (!$seat->isServerBot()) {
             $promises[] = $this->enqueueMessage($player, $message, 0);
         }
     }
     return \React\Promise\all($promises);
 }
 /**
  * @return array
  */
 public function toArray()
 {
     return ['table_id' => $this->table->getId()];
 }