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); } } } }
public function __construct($game) { parent::__construct($game); $cardRepository = new CardRepository(TRUE); $drawPile = unserialize($game['draw_pile']); $drawPileCards = array(); if ($drawPile) { foreach ($drawPile as $cardId) { $drawPileCards[] = $cardRepository->getOneById($cardId); } } $this->setAdditionalField('draw_pile', $drawPileCards); $throwPile = unserialize($game['throw_pile']); $throwPileCards = array(); if ($throwPile) { foreach ($throwPile as $cardId) { $throwPileCards[] = $cardRepository->getOneById(intval($cardId)); } } $this->setAdditionalField('throw_pile', $throwPileCards); $playerRepository = new PlayerRepository(); $players = $playerRepository->getByGame($game['id']); $this->setAdditionalField('players', $players); $this->setAdditionalField('matrix', unserialize($game['distance_matrix'])); $gameSets = unserialize($game['game_sets']); if (in_array(3, $gameSets)) { $isHighNoon = TRUE; } else { $isHighNoon = FALSE; } $this->setAdditionalField('isHighNoon', $isHighNoon); if ($isHighNoon) { $highNoonPile = unserialize($game['high_noon_pile']); $highNoonRepository = new HighNoonRepository(TRUE); $highNoonPileCards = array(); if ($highNoonPile) { foreach ($highNoonPile as $cardId) { $highNoonPileCards[] = $highNoonRepository->getOneById(intval($cardId)); } } $this->setAdditionalField('highNoonPile', $highNoonPileCards); if ($game['high_noon']) { $highNoonRepository = new HighNoonRepository(); $highNoon = $highNoonRepository->getOneById(intval($game['high_noon'])); $this->setAdditionalField('highNoon', $highNoon); } } }