public function play() { $command = ''; if ($this->game['status'] == Game::GAME_STATUS_INITIALIZED) { $command = $this->selectCharacter(); } elseif ($this->player['phase'] == Player::PHASE_DRAW_HIGH_NOON) { $command = $this->drawOneTurnCard(); } elseif ($this->player['phase'] == Player::PHASE_DYNAMITE) { $command = $this->drawDynamite(); } elseif ($this->player['phase'] == Player::PHASE_JAIL) { $command = $this->drawJail(); } elseif ($this->player['phase'] == Player::PHASE_RATTLESNAKE) { $command = $this->drawRattlesnake(); } elseif ($this->player['phase'] == Player::PHASE_DRAW) { $command = $this->draw(); } elseif ($this->player['phase'] == Player::PHASE_PLAY) { if ($this->player['possible_choices'] != '') { $command = $this->chooseCards(); } else { $command = $this->playCards(); } } elseif ($this->player['phase'] == Player::PHASE_UNDER_ATTACK) { $command = $this->reactToAttack(); } elseif ($this->player['phase'] == Player::PHASE_HIGH_NOON) { $command = $this->takeLifeDown(); } else { $this->whatToDo(); } if ($command) { Log::logAiAction('ai player ' . $this->player['id'] . ': ' . $command); Command::setup($command, $this->game, $this->player); } }
protected function createResponse() { $playerRepository = new PlayerRepository(); $count = $playerRepository->getCountByGameAndCharakter($this->game['id'], 0); if ($count === 0) { return Command::setup('command=start', $this->game); } return ''; }
public function main() { $gameId = intval(Utils::post('game')); $gameRepository = new GameRepository(); $game = $gameRepository->getOneById($gameId); $commandParams = array(); $commandParams['command'] = addslashes(Utils::post('command')); $commandParams['useCharacter'] = intval(Utils::post('useCharacter')); $commandParams['playCardId'] = intval(Utils::post('playCard')); if ($commandParams['playCardId']) { $cardRepository = new CardRepository(TRUE); $card = $cardRepository->getOneById($commandParams['playCardId']); $commandParams['playCardName'] = str_replace('-', '', $card->getItemAlias()); } // TODO mozno ich niekedy bude viac $commandParams['additionalCardsId'] = intval(Utils::post('additionalCard')); if ($commandParams['additionalCardsId']) { $cardRepository = new CardRepository(TRUE); $card = $cardRepository->getOneById($commandParams['additionalCardsId']); $commandParams['additionalCardsName'] = str_replace('-', '', $card->getItemAlias()); } $commandParams['enemyPlayerId'] = intval(Utils::post('player')); if ($commandParams['enemyPlayerId']) { $playerRepository = new PlayerRepository(); $player = $playerRepository->getOneById($commandParams['enemyPlayerId']); if ($player) { $user = $player->getUser(); if ($user) { $commandParams['enemyPlayerUsername'] = $user['username']; } } } if ($commandParams['command'] == 'fanning') { $commandParams['additionalEnemyPlayerId'] = intval(Utils::post('additionalPlayer')); if ($commandParams['additionalEnemyPlayerId']) { $playerRepository = new PlayerRepository(); $player = $playerRepository->getOneById($commandParams['additionalEnemyPlayerId']); if ($player) { $user = $player->getUser(); if ($user) { $commandParams['additionalEnemyPlayerUsername'] = $user['username']; } } } } // TODO brawl tu dava addslashes if ($commandParams['command'] == 'brawl') { $commandParams['enemyCardsId'] = addslashes(Utils::post('card')); } elseif ($commandParams['command'] == 'choose_cards') { $commandParams['selectedCards'] = addslashes(Utils::post('card')); } else { $commandParams['enemyCardsId'] = intval(Utils::post('card')); if ($commandParams['enemyCardsId']) { $cardRepository = new CardRepository(TRUE); $card = $cardRepository->getOneById($commandParams['enemyCardsId']); $commandParams['enemyCardsName'] = str_replace('-', '', $card->getItemAlias()); } } $commandParams['place'] = addslashes(Utils::post('place')); if (Utils::post('peyoteColor')) { $commandParams['peyoteColor'] = addslashes(Utils::post('peyoteColor')); } if (Utils::post('text')) { $commandParams['text'] = addslashes(Utils::post('text')); } $params = array(); foreach ($commandParams as $key => $value) { $params[] = $key . '=' . $value; } $commandString = implode('&', $params); Log::command($commandString); Command::setup($commandString, $game); }
protected function setup() { $roomAlias = Utils::get('identifier'); $roomRepository = new RoomRepository(); $room = $roomRepository->getOneByAlias($roomAlias); $loggedUser = LoggedUser::whoIsLogged(); if ($room) { $gameRepository = new GameRepository(); // $gameRepository->addAdditionalWhere(array('column' => 'status', 'value' => Game::GAME_STATUS_ENDED, 'xxx' => '!=')); $gameRepository->addOrderBy(array('id' => 'DESC')); $game = $gameRepository->getOneByRoom($room['id']); if (Utils::post()) { $message = addslashes(trim(Utils::post('message'))); if ($message != '') { if (strpos($message, '.') === 0) { $response = Command::setup('command=' . substr($message, 1), $game); } else { $response = Command::setup('command=say&text=' . $message . '&room=' . $room['id'] . '&game=' . $game['id'], $game); } Room::updateUserLastActivity($loggedUser['id'], $room['id']); } elseif (Utils::post('create')) { $response = Command::setup('command=create', $game); } elseif (Utils::post('join')) { $response = Command::setup('command=join', $game); } elseif (Utils::post('add_ai_player')) { $response = Command::setup('command=add_ai_player', $game); } elseif (Utils::post('start')) { $response = Command::setup('command=init', $game); } elseif (Utils::post('choose_character')) { $response = Command::setup('command=choose_character&selectedCharacter=' . Utils::post('character'), $game); } elseif (Utils::post('choose_cards')) { $commandParams = array(); $commandParams['command'] = 'choose_cards'; $commandParams['selectedCards'] = array(); if (Utils::post('card')) { $commandParams['selectedCards'] = implode(',', Utils::post('card')); } $params = array(); foreach ($commandParams as $key => $value) { $params[] = $key . '=' . $value; } $commandString = implode('&', $params); $response = Command::setup($commandString, $game); } Utils::redirect(Utils::getActualUrl(), FALSE); // TODO tu by sa mohol spravit redirect asi lebo respons bude v db MySmarty::assign('response', $response); } $gameBox = new GameBox(); $gameBox->setRoom($room); if ($game !== NULL) { $gameBox->setGame($game); } MySmarty::assign('gameBox', $gameBox->render()); $chatBox = new ChatBox(); $chatBox->setRoom($room); if ($game !== NULL) { $chatBox->setGame($game); } MySmarty::assign('chatBox', $chatBox->render()); } else { // TODO 404 room not found } }