Ejemplo n.º 1
0
 protected function run()
 {
     if ($this->check == self::OK) {
         $this->attackedPlayer['phase'] = Player::PHASE_UNDER_ATTACK;
         $this->attackedPlayer->save();
         if ($this->params['additionalEnemyPlayerId']) {
             $playerRepository = new PlayerRepository();
             $additionalAttackedPlayer = $playerRepository->getOneById(intval($this->params['additionalEnemyPlayerId']));
             MySmarty::assign('card', $this->cards[0]);
             $response = MySmarty::fetch($this->template);
             $additionalAttackedPlayer['command_response'] = $response;
             $additionalAttackedPlayer->save();
         }
         $this->actualPlayer['phase'] = Player::PHASE_WAITING;
         if ($this->actualPlayer->getIsBelleStar($this->game)) {
             $notices = $this->actualPlayer->getNoticeList();
             $notices['character_used'] = 1;
             $this->actualPlayer->setNoticeList($notices);
         }
         $this->actualPlayer->save();
         // TODO toto plati len ak je to utok bangom, ale bang sa pouziva na viacerych miestach - premysliet a dorobit aj duel a indianov prip dalsie
         $this->game['inter_turn'] = $this->attackedPlayer['id'];
         $this->game['inter_turn_reason'] = serialize(array('action' => 'fanning', 'from' => $this->actualPlayer['id'], 'to' => $this->attackedPlayer['id'], 'additionalTo' => intval($this->params['additionalEnemyPlayerId'])));
         $this->game->save();
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
     }
 }
Ejemplo n.º 2
0
 protected function createResponse()
 {
     $playerRepository = new PlayerRepository();
     $count = $playerRepository->getCountByGameAndCharakter($this->game['id'], 0);
     if ($count === 0) {
         return Command::setup('command=start', $this->game);
     }
     return '';
 }
Ejemplo n.º 3
0
 protected function setup()
 {
     $loggedUser = LoggedUser::whoIsLogged();
     MySmarty::assign('loggedUser', $loggedUser);
     MySmarty::assign('room', $this->room);
     if ($this->game) {
         MySmarty::assign('game', $this->game);
         MySmarty::assign('gameStartedStatus', Game::GAME_STATUS_STARTED);
         $playerRepository = new PlayerRepository();
         $actualPlayer = $playerRepository->getOneByGameAndUser($this->game['id'], $loggedUser['id']);
         // phases when we want to make autoreload
         $refreshGameBox = FALSE;
         if (in_array($actualPlayer['phase'], array(Player::PHASE_NONE, Player::PHASE_WAITING))) {
             if ($this->game['status'] == Game::GAME_STATUS_INITIALIZED && $actualPlayer['possible_choices'] != '') {
                 $refreshGameBox = FALSE;
             } else {
                 $refreshGameBox = TRUE;
             }
         }
         MySmarty::assign('refreshGameBox', $refreshGameBox);
         // zobrazime len hracovi ktory je na tahu resp. v medzitahu
         $playerOnMove = $this->game->getPlayerOnMove();
         if ($playerOnMove['id'] == $actualPlayer['id'] || $this->game['status'] == Game::GAME_STATUS_INITIALIZED) {
             MySmarty::assign('response', $actualPlayer['command_response']);
         }
         if ($this->game['status'] == Game::GAME_STATUS_CREATED) {
             if (!GameUtils::checkUserInGame($loggedUser, $this->game)) {
                 MySmarty::assign('joinGameAvailable', TRUE);
             } elseif ($loggedUser['id'] == $this->game['creator']) {
                 MySmarty::assign('startGameAvailable', Localize::getMessage('start_game'));
             }
         } elseif ($this->game['status'] == Game::GAME_STATUS_ENDED) {
             MySmarty::assign('createGameAvailable', Localize::getMessage('create_game'));
             MySmarty::assign('refreshGameBox', TRUE);
         }
     } else {
         MySmarty::assign('createGameAvailable', Localize::getMessage('create_game'));
         MySmarty::assign('refreshGameBox', TRUE);
     }
 }
Ejemplo n.º 4
0
 protected function check()
 {
     if ($this->game && $this->game['status'] != Game::GAME_STATUS_ENDED) {
         if ($this->game['status'] == Game::GAME_STATUS_INITIALIZED) {
             $playerRepository = new PlayerRepository();
             $count = $playerRepository->getCountByGameAndCharakter($this->game['id'], 0);
             if ($count === 0) {
                 $this->check = self::OK;
             } else {
                 $this->check = self::SOME_PLAYERS_WITHOUT_CHARACTER;
             }
         } elseif ($this->game['status'] == Game::GAME_STATUS_CREATED) {
             $this->check = self::NOT_YET_INITIALIZED;
         } elseif ($this->game['status'] == Game::GAME_STATUS_STARTED) {
             $this->check = self::ALREADY_STARTED;
         } else {
             $this->check = self::SOMETHING_ELSE;
         }
     } else {
         $this->check = self::NO_GAME;
     }
 }
Ejemplo n.º 5
0
 /**
  * gets the player on move if inter_turn is set - this player is under attack or has some other reason for inter_turn
  * if inter_turn is not set, returns player on turn
  * 
  * @return	Player|NULL
  */
 public function getPlayerOnMove()
 {
     $playerRepository = new PlayerRepository();
     if ($this['inter_turn']) {
         return $playerRepository->getOneById($this['inter_turn']);
     } else {
         return $this->getPlayerOnTurn();
     }
 }
Ejemplo n.º 6
0
 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);
 }
Ejemplo n.º 7
0
 protected function run()
 {
     if ($this->check == self::OK) {
         if (in_array($this->interTurnReason['action'], array('indians', 'wild_band'))) {
             $this->runMollyStarkAction();
             $this->changeInterturn();
         } elseif ($this->interTurnReason['action'] == 'duel') {
             $attackedPlayerId = intval($this->interTurnReason['to']);
             $playerRepository = new PlayerRepository();
             $this->attackedPlayer = $playerRepository->getOneById($attackedPlayerId);
             MySmarty::assign('card', $this->cards[0]);
             $response = MySmarty::fetch($this->duelBangTemplate);
             if ($this->attackingPlayer['id'] == $this->actualPlayer['id']) {
                 $this->attackedPlayer['phase'] = Player::PHASE_UNDER_ATTACK;
                 $this->attackedPlayer['command_response'] = $response;
                 $this->attackedPlayer->save();
                 $this->duelAttackedUser = $this->attackedPlayer->getUser();
                 $this->game['inter_turn'] = $this->attackedPlayer['id'];
                 $this->game->save();
             } elseif ($this->attackedPlayer['id'] == $this->actualPlayer['id']) {
                 $this->attackingPlayer['phase'] = Player::PHASE_UNDER_ATTACK;
                 $this->attackingPlayer['command_response'] = $response;
                 $this->attackingPlayer->save();
                 $this->duelAttackedUser = $this->attackingPlayer->getUser();
                 $this->game['inter_turn'] = $this->attackingPlayer['id'];
                 $this->game->save();
             } else {
                 // pcha sa sem niekto kto tu vobec nema co robit
             }
             $this->actualPlayer['command_response'] = '';
             $this->actualPlayer['phase'] = Player::PHASE_NONE;
             $this->actualPlayer->save();
         } else {
             $canAttack = $this->checkCanAttackApacheKid();
             if ($canAttack === TRUE) {
                 $this->attackedPlayer['phase'] = Player::PHASE_UNDER_ATTACK;
                 $this->attackedPlayer->save(TRUE);
                 $this->actualPlayer['phase'] = Player::PHASE_WAITING;
                 if ($this->actualPlayer->getIsBelleStar($this->game) || $this->actualPlayer->getIsSlabTheKiller($this->game)) {
                     $notices = $this->actualPlayer->getNoticeList();
                     $notices['character_used'] = 1;
                     $this->actualPlayer->setNoticeList($notices);
                 }
                 $this->game['inter_turn'] = $this->attackedPlayer['id'];
                 $this->game['inter_turn_reason'] = serialize(array('action' => 'bang', 'from' => $this->actualPlayer['id'], 'to' => $this->attackedPlayer['id']));
                 $this->game->save();
             } else {
                 $this->check = self::CANNOT_ATTACK_APACHE_KID;
             }
             // pouzitie bangu zapiseme aj ked hrac nemohol zautocit na apache kida
             $this->actualPlayer['bang_used'] = $this->actualPlayer['bang_used'] + 1;
             $this->actualPlayer->save();
         }
         // vyhodime kartu bang
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
     }
 }
Ejemplo n.º 8
0
 protected static function pass()
 {
     if (GameUtils::checkTurn(self::$game, self::$player)) {
         if (self::$game['inter_turn_reason'] == '') {
             if (self::$player['phase'] == 2) {
                 if (self::$player->getCanPass()) {
                     $next = GameUtils::getNextPosition(self::$game, self::$player['position']);
                     GameUtils::setTurn(self::$game, $next);
                     GameUtils::setInterTurn(self::$game, 0);
                     $playerRepository = new PlayerRepository();
                     $nextPlayer = $playerRepository->getPlayerByGameAndPosition(self::$game['id'], $next);
                     $nextPlayer->setPhase(1);
                     self::$player->setPhase(0);
                     self::$player->setUseBang(0);
                     Chat::addMessage('Posunul si ťah.', self::$room, User::SYSTEM, self::$loggedUser['id']);
                     Chat::addMessage('Si na ťahu, použi príkaz ".tahaj"', self::$room, User::SYSTEM, $nextPlayer['user']['id']);
                 } else {
                     Chat::addMessage('Nemôžeš posunúť ťah, pretože máš na ruke priveľa kariet', self::$room, User::SYSTEM, self::$loggedUser['id']);
                 }
             } else {
                 Chat::addMessage('Nemôžeš posunúť ťah, pretože si ešte neťahal karty.', self::$room, User::SYSTEM, self::$loggedUser['id']);
             }
         } else {
             Chat::addMessage('musis reagovat na ' . self::$game['inter_turn_reason'], self::$room, User::SYSTEM, self::$loggedUser['id']);
         }
     } else {
         Chat::addMessage('Nemôžeš posunúť ťah, pretože nie si na rade.', self::$room, User::SYSTEM, self::$loggedUser['id']);
     }
 }
Ejemplo n.º 9
0
 protected function endGame($roles)
 {
     $playerRepository = new PlayerRepository();
     $players = $playerRepository->getByGameAndRole($this->game['id'], $roles);
     $playersNames = array();
     foreach ($players as $player) {
         $player['winner'] = 1;
         $player->save();
         $user = $player->getUser();
         $playersNames[] = $user['username'];
     }
     // znovu nacitame actual a attacking playera lebo to robi nejake halusky
     if ($this->actualPlayer) {
         $this->actualPlayer = $playerRepository->getOneById($this->actualPlayer['id']);
     }
     if ($this->attackingPlayer) {
         $this->attackingPlayer = $playerRepository->getOneById($this->attackingPlayer['id']);
     }
     // vytvorit nejaku tabulku hall of fame kde budu vyhry a prehry
     // vyhry a prehry za nejaku konkretnu rolu  - typ roly - cize je jedno ci si bandita1 alebo bandita2
     $message = array('text' => 'vyhrali hraci: ' . implode(', ', $playersNames), 'user' => User::SYSTEM);
     $this->addMessage($message);
     $this->game['status'] = Game::GAME_STATUS_ENDED;
     $this->game->save();
 }
Ejemplo n.º 10
0
 protected function takeLifeDown()
 {
     $command = 'command=life';
     $beer = NULL;
     if ($this->player['actual_lifes'] == 1) {
         $beer = $this->player->getHasBeerOnHand();
         if ($beer) {
             $command .= '&playCardId=' . $beer['id'] . '&playCardName=' . $beer->getCardName();
         }
     }
     $interTurnReason = unserialize($this->game['inter_turn_reason']);
     if (isset($interTurnReason['from'])) {
         $attackingPlayerId = $interTurnReason['from'];
         $playerRepository = new PlayerRepository();
         $attackingPlayer = $playerRepository->getOneById($attackingPlayerId);
         if ($attackingPlayer && $attackingPlayer->getHasShootgunOnTheTable()) {
             $handCards = $this->player->getHandCards();
             if ($handCards) {
                 $thrownCard = $handCards[array_rand($handCards)];
                 if ($beer) {
                     $command .= '&additionalCardsId=' . $thrownCard['id'] . '&additionalCardsName=' . $thrownCard->getCardName();
                 } else {
                     $command .= '&playCardId=' . $thrownCard['id'] . '&playCardName=' . $thrownCard->getCardName();
                 }
             }
         }
     }
     return $command;
 }
Ejemplo n.º 11
0
 public static function getNextPosition($game, $actualPosition = 0)
 {
     echo 'GameUtils::getNextPosition';
     exit;
     $playerRepository = new PlayerRepository();
     $players = $playerRepository->getLivePlayersByGame($game['id']);
     $playersCount = count($players);
     if ($actualPosition) {
         $next = $actualPosition + 1;
     } else {
         $next = $game['turn'] + 1;
     }
     return $next <= $playersCount ? $next : $next - $playersCount;
 }