protected function run() { if ($this->check == self::OK) { $roleRepository = new RoleRepository(); $characterRepository = new CharacterRepository(); $characterCardsCount = is_numeric($this->params[0]) ? intval($this->params[0]) : 2; $players = $this->players; $roleRepository->setLimit(count($players)); $roles = $roleRepository->getAll(); shuffle($roles); $gameSets = unserialize($this->game['game_sets']); if ($gameSets) { $characters = $characterRepository->getByValidAndGameSet(1, $gameSets); } else { $characters = $characterRepository->getByValid(1); } shuffle($characters); $highNoonRepository = new HighNoonRepository(); $highNoonCard = $highNoonRepository->getOneByIdAndValidAndGameSet(HighNoon::getSpecialCards(), 1, $gameSets); $highNoonRepository = new HighNoonRepository(); $highNoonRepository->addAdditionalWhere(array('column' => 'id', 'value' => HighNoon::getSpecialCards(), 'xxx' => 'NOT IN')); $highNoonCards = $highNoonRepository->getByValidAndGameSet(1, $gameSets); if ($highNoonCards) { shuffle($highNoonCards); $highNoonCardIds = array(); foreach ($highNoonCards as $card) { $highNoonCardIds[] = $card['id']; if (count($highNoonCardIds) == 14) { break; } } if ($highNoonCard) { $highNoonCardIds[] = $highNoonCard['id']; } $this->game['high_noon_pile'] = serialize(array_reverse($highNoonCardIds)); } $j = 0; foreach ($players as $player) { $playerPossibleCharacters = array(); $player['role'] = $roles[$j]['id']; $index = $characterCardsCount * $j; for ($c = $index; $c < $index + $characterCardsCount; $c++) { $playerPossibleCharacters[] = $characters[$c]['id']; } $player['possible_choices'] = serialize(array('possible_characters' => $playerPossibleCharacters)); $player->save(); $j++; } $this->game['status'] = Game::GAME_STATUS_INITIALIZED; $this->game = $this->game->save(TRUE); foreach ($this->game->getPlayers() as $player) { if ($player->getIsAi()) { $player->play($this->game); } } } }