protected function run() { if ($this->check == self::OK) { $cardBaseTypeRepository = new CardBaseTypeRepository(); $validCardBaseTypes = $cardBaseTypeRepository->getByValid(1); $validCardBaseTypesIdList = array(); foreach ($validCardBaseTypes as $cardBaseType) { $validCardBaseTypesIdList[] = $cardBaseType['id']; } $cardRepository = new CardRepository(); $where = array('column' => 'card_base_type', 'value' => $validCardBaseTypesIdList); $cardRepository->addAdditionalWhere($where); $gameSets = unserialize($this->room['game_sets']); if ($gameSets) { $where = array('column' => 'game_set', 'value' => $gameSets); $cardRepository->addAdditionalWhere($where); } $cards = $cardRepository->getCardIds(); shuffle($cards); // TODO prepare High noon draw pile // TODO - other extensions $players = $this->players; foreach ($players as $player) { $playerCards = array(); $character = $player->getAdditionalField('character'); $role = $player->getAdditionalField('role'); $player['actual_lifes'] = $character['lifes']; $cardsCount = $player->getIsBigSpencer() ? 5 : $player['actual_lifes']; for ($i = 0; $i < $cardsCount; $i++) { $playerCards[] = array_pop($cards); } if ($role['type'] == Role::SHERIFF) { $player['phase'] = Player::PHASE_DRAW; $player['actual_lifes'] = $player['actual_lifes'] + 1; } $player['max_lifes'] = $player['actual_lifes']; $player['hand_cards'] = serialize($playerCards); $player['table_cards'] = serialize(array()); $player['wait_cards'] = serialize(array()); $player->save(); } $this->game['draw_pile'] = serialize($cards); $this->game['throw_pile'] = serialize(array()); // musime ulozit hru lebo hracom sa zmenili charaktery $this->game = $this->game->save(TRUE); $this->game = GameUtils::changePositions($this->game); foreach ($this->game->getPlayers() as $player) { if ($player['role'] == Role::SHERIFF) { $this->game['turn'] = $player['id']; break; } } $this->game['game_start'] = time(); $this->game['status'] = Game::GAME_STATUS_STARTED; $matrix = GameUtils::countMatrix($this->game); $this->game['distance_matrix'] = serialize($matrix); $this->game = $this->game->save(TRUE); } }