示例#1
0
 protected function run()
 {
     if ($this->check == self::OK) {
         $this->attackingCards = $this->cards;
         $nextPositionPlayer = $this->findNextPlayerWithHandCards($this->game, $this->actualPlayer, $this->actualPlayer);
         if ($nextPositionPlayer['id'] != $this->actualPlayer['id']) {
             foreach ($this->players as $player) {
                 if ($player->getIsAlive()) {
                     if ($player['id'] == $this->actualPlayer['id']) {
                         $this->actualPlayer['phase'] = Player::PHASE_WAITING;
                         $this->actualPlayer->save();
                     } else {
                         if ($player['id'] == $nextPositionPlayer['id']) {
                             $player['phase'] = Player::PHASE_UNDER_ATTACK;
                         }
                         MySmarty::assign('card', $this->cards[0]);
                         $response = MySmarty::fetch($this->template);
                         $player['command_response'] = $response;
                         $player->save();
                     }
                 }
             }
             $this->game['inter_turn_reason'] = serialize(array('action' => 'poker', 'from' => $this->actualPlayer['id'], 'to' => $nextPositionPlayer['id'], 'thrownCards' => array()));
             $this->game['inter_turn'] = $nextPositionPlayer['id'];
             $this->game->save();
         } else {
             // bola by blbost hrat kartu poker ak nikto iny nema karty na ruke
         }
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
     }
 }
示例#2
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);
     }
 }
示例#3
0
 protected function run()
 {
     if ($this->check == self::OK) {
         $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer);
         foreach ($this->players as $player) {
             if ($player->getIsAlive()) {
                 if ($player['id'] == $this->actualPlayer['id']) {
                     $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();
                 } else {
                     if ($player['id'] == $nextPositionPlayer['id']) {
                         $player['phase'] = Player::PHASE_UNDER_ATTACK;
                     }
                     MySmarty::assign('card', $this->cards[0]);
                     $response = MySmarty::fetch($this->template);
                     $player['command_response'] = $response;
                     $player->save();
                 }
             }
         }
         $this->game['inter_turn_reason'] = serialize(array('action' => 'gatling', 'from' => $this->actualPlayer['id'], 'to' => $nextPositionPlayer['id']));
         $this->game['inter_turn'] = $nextPositionPlayer['id'];
         $this->game->save();
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
     }
 }
示例#4
0
 protected function run()
 {
     if ($this->check == self::OK) {
         // TODO moze sa stat ze hraju uz len dvaja apache kid a utocnik - asi staci ak skontrolujeme ci next pos player != od actual
         $this->attackingCards = $this->cards;
         $nextPositionPlayer = $this->getNextPositionPlayer($this->game, $this->actualPlayer);
         foreach ($this->players as $player) {
             if ($player->getIsAlive()) {
                 if ($player['id'] == $this->actualPlayer['id']) {
                     $this->actualPlayer['phase'] = Player::PHASE_WAITING;
                     $this->actualPlayer->save();
                 } else {
                     if ($player['id'] == $nextPositionPlayer['id']) {
                         $player['phase'] = Player::PHASE_UNDER_ATTACK;
                     }
                     MySmarty::assign('card', $this->cards[0]);
                     $response = MySmarty::fetch($this->template);
                     $player['command_response'] = $response;
                     $player->save();
                 }
             }
         }
         $this->game['inter_turn_reason'] = serialize(array('action' => 'wild_band', 'from' => $this->actualPlayer['id'], 'to' => $nextPositionPlayer['id'], 'cards' => $this->getCardIds()));
         $this->game['inter_turn'] = $nextPositionPlayer['id'];
         $this->game->save();
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
     }
 }
 public static function gameResult(GameUsers $user, GameUsers $opponent, $roomGroupId, $action, $gameId = null, $double = 0, $normal = true, $type = null, $time = null)
 {
     $result = new FunctionResult();
     $result->success = false;
     if (!empty($user) && !empty($action)) {
         if (empty($action) || !empty($action) && $action != GameUtils::$GAME_RESULT_ACTION_WIN && $action != GameUtils::$GAME_RESULT_ACTION_LOST) {
             $result->result = "Unknown Action";
             return $result;
         }
         GameUtils::updateXP($user, $opponent, $roomGroupId, $action, $gameId, $double, $normal, $type, $time);
         GameUtils::updateCoin($user, $opponent, $roomGroupId, $action, $gameId, $double, $normal, $type, $time);
         GameUtils::updateCounts($user, $opponent, $roomGroupId, $action, $gameId, $double, $normal, $type, $time);
         if ($action == GameUtils::$GAME_RESULT_ACTION_WIN && ($type == GameUtils::$GAME_RESULT_ACTION_TYPE_LEFT || $type == GameUtils::$GAME_RESULT_ACTION_TYPE_TIMESUP) && !empty($opponent)) {
             if (empty($time)) {
                 $time = time();
             }
             Queue::userLostConnLost($opponent->userId, $user->userId, $roomGroupId, GameUtils::$GAME_RESULT_ACTION_LOST, $gameId, $double, $normal, $type, $time);
         }
         try {
             $user->updateToDatabase(DBUtils::getConnection());
             $result->success = true;
             $result->result = new stdClass();
             $result->result->user = $user;
         } catch (Exception $exc) {
             $result->success = true;
             $result->result = $exc->getTraceAsString();
         }
         return $result;
     } else {
         $result->result = "User not found";
         return $result;
     }
 }
 public function lost()
 {
     $log = KLogger::instance(KLOGGER_PATH . "processors/", KLogger::DEBUG);
     $log->logInfo("usergameaction > lost > start userId : " . $this->userId . " opponentId : " . $this->opponentId . " action : " . $this->action_ . " time : " . $this->time . " room groupId : " . $this->roomGroupId . " gameId : " . $this->gameId . " normal : " . $this->normal . " type : " . $this->type . " double : " . $this->double);
     if (!empty($this->userId)) {
         $user = GameUsers::getGameUserById($this->userId);
         if (!empty($user)) {
             $userId = $user->getUserId();
             if (!empty($userId)) {
                 $user->getUserLevel();
                 $opponent = GameUsers::getGameUserById($this->opponentId);
                 $opponentId = null;
                 if (!empty($opponent)) {
                     $opponentId = $opponent->getUserId();
                     $opponent->getUserLevel();
                 }
                 $result = GameUtils::gameResult($user, $opponent, $this->roomGroupId, $this->action_, $this->gameId, $this->double, $this->normal, $this->type, $this->time);
                 if (!empty($result) && $result->success) {
                     $log->logInfo("usergameaction > lost > success ");
                 } else {
                     $log->logError("usergameaction > lost > error :  " . $result->result);
                 }
                 unset($userId);
                 unset($user);
             } else {
                 $log->logError("usergameaction > lost > user Id is empty ");
             }
         } else {
             $log->logError("usergameaction > lost > user Id is empty ");
         }
     } else {
         $log->logError("usergameaction > lost > user Id is empty ");
     }
 }
示例#7
0
 protected function run()
 {
     if ($this->check == DefensiveCommand::OK) {
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
         $this->runMollyStarkAction();
         $this->changeInterturn();
     }
 }
示例#8
0
 protected function run()
 {
     if ($this->check == DefensiveCommand::OK) {
         // odhodime ten gallon hat
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards, 'table');
         $this->runMollyStarkAction();
         $this->changeInterturn();
     }
 }
示例#9
0
 protected function run()
 {
     if ($this->check === self::OK) {
         $playersCount = GameUtils::getPosition($this->game);
         $params = array('game' => $this->game['id'], 'user' => $this->loggedUser['id'], 'seat' => GameUtils::getSeatOnPosition($playersCount));
         // TODO use repository
         DB::insert(DB_PREFIX . 'player', $params);
     }
 }
示例#10
0
 protected function run()
 {
     if ($this->check == self::OK) {
         $additionalLifes = 1;
         $newLifes = min($this->actualPlayer['actual_lifes'] + $additionalLifes, $this->actualPlayer['max_lifes']);
         $this->actualPlayer['actual_lifes'] = $newLifes;
         $this->actualPlayer->save();
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards, 'hand');
     }
 }
示例#11
0
 protected function run()
 {
     if ($this->check == self::OK) {
         GameUtils::moveCards($this->game, $this->cards, $this->actualPlayer, 'table', $this->attackedPlayer);
         // preratame maticu kedze sa do hry vracia hrac
         $matrix = GameUtils::countMatrix($this->game);
         $this->game['distance_matrix'] = serialize($matrix);
         $this->game->save();
     }
 }
示例#12
0
 protected function run()
 {
     foreach ($this->players as $player) {
         if ($player->getIsAlive()) {
             $newLifes = min($player['actual_lifes'] + 1, $player['max_lifes']);
             $player['actual_lifes'] = $newLifes;
             $player->save();
         }
     }
     GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
 }
示例#13
0
 protected function run()
 {
     if ($this->check == self::OK) {
         GameUtils::throwCards($this->game, $this->actualPlayer, array($this->ponyExpressCard), 'table');
         $drawnCards = GameUtils::drawCards($this->game, 3);
         $handCards = unserialize($this->actualPlayer['hand_cards']);
         foreach ($drawnCards as $drawnCard) {
             $handCards[] = $drawnCard;
         }
         $this->actualPlayer['hand_cards'] = serialize($handCards);
         $this->actualPlayer->save();
     }
 }
示例#14
0
 protected function run()
 {
     if ($this->check == self::OK) {
         GameUtils::moveCards($this->game, $this->putCards, $this->actualPlayer, $this->place);
         if ($this->place == 'table') {
             // kedze je mozne ze vykladame nejaku modru kartu, ktora ovplyvnuje vzdialenost, preratame maticu
             // ak to bude velmi pomale, budeme to robit len ak je medzi vylozenymi kartami fakt takato karta
             $matrix = GameUtils::countMatrix($this->game);
             $this->game['distance_matrix'] = serialize($matrix);
             $this->game->save();
         }
     }
 }
 private function handleComputerStep($stepNumber)
 {
     $answer = GameUtils::compAnswer();
     //если компьютер сдался
     if (isset($answer['message'])) {
         Yii::app()->session['loser'] = GameUtils::COMP_LOSER;
         $this->redirect(array('game/delete', 'id' => Yii::app()->session['gameId']));
     }
     //иначе сохраняем ход компьютера
     $compstep = new Gamestep();
     $compstep->saveStep($answer['city'], $stepNumber + 1);
     return;
 }
示例#16
0
 protected function run()
 {
     if ($this->check == self::OK) {
         GameUtils::throwCards($this->game, $this->actualPlayer, array($this->wellsFargoCard));
         $drawnCards = GameUtils::drawCards($this->game, 3);
         // TODO toto je asi miesto kde sa zvysuje pocet kariet - v game utils throw cards sa karta zahodi ale tu este asi je
         $handCards = unserialize($this->actualPlayer['hand_cards']);
         foreach ($drawnCards as $drawnCard) {
             $handCards[] = $drawnCard;
         }
         $this->actualPlayer['hand_cards'] = serialize($handCards);
         $this->actualPlayer->save();
     }
 }
示例#17
0
 protected function run()
 {
     if ($this->check == self::OK) {
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards, 'table');
         GameUtils::throwCards($this->game, $this->attackedPlayer, $this->enemyPlayersCards[$this->attackedPlayer['id']], $this->place);
         if ($this->place == 'table') {
             // kedze je mozne ze rusime nejaku modru kartu ktora ovplyvnuje vzdialenost, preratame maticu
             // ak to bude velmi pomale, budeme to robit len ak je medzi zrusenymi kartami fakt takato karta
             $matrix = GameUtils::countMatrix($this->game);
             $this->game['distance_matrix'] = serialize($matrix);
             $this->game->save();
         }
     }
 }
示例#18
0
 protected function run()
 {
     if ($this->check == DefensiveCommand::OK) {
         // odhodime kartu biblia
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards, 'table');
         $this->runMollyStarkAction();
         // potiahneme kartu
         $drawnCards = GameUtils::drawCards($this->game, 1);
         $handCards = unserialize($this->actualPlayer['hand_cards']);
         $handCards = array_merge($handCards, $drawnCards);
         $this->actualPlayer['hand_cards'] = serialize($handCards);
         $this->changeInterturn();
     }
 }
示例#19
0
 protected function run()
 {
     if ($this->check == DefensiveCommand::OK) {
         // odhodime kartu dodge
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
         $this->runMollyStarkAction();
         $this->actualPlayer['command_response'] = '';
         $this->actualPlayer['phase'] = Player::PHASE_NONE;
         $this->actualPlayer->save();
         $this->attackingPlayer['phase'] = Player::PHASE_UNDER_ATTACK;
         $this->attackingPlayer->save();
         $this->game['inter_turn'] = $this->attackingPlayer['id'];
         $this->game['inter_turn_reason'] = serialize(array('action' => 'backfire', 'from' => $this->attackingPlayer['id'], 'to' => $this->attackingPlayer['id']));
         $this->game->save();
         // TODO vyriesit problem ked po obraneni sa proti backfire hrac nema nastavenu spravnu fazu
     }
 }
示例#20
0
 protected function run()
 {
     if ($this->check == self::OK) {
         $canAttack = $this->checkCanAttackApacheKid();
         if ($canAttack === TRUE) {
             $this->attackedPlayer['phase'] = Player::PHASE_UNDER_ATTACK;
             $this->attackedPlayer->save();
             $this->actualPlayer['phase'] = Player::PHASE_WAITING;
             $this->actualPlayer->save();
             $this->game['inter_turn'] = $this->attackedPlayer['id'];
             $this->game['inter_turn_reason'] = serialize(array('action' => 'duel', 'from' => $this->actualPlayer['id'], 'to' => $this->attackedPlayer['id']));
             $this->game->save();
         } else {
             $this->check = self::CANNOT_ATTACK_APACHE_KID;
         }
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
     }
 }
示例#21
0
 protected function run()
 {
     if ($this->check == self::OK) {
         $this->attackedPlayer['phase'] = Player::PHASE_UNDER_ATTACK;
         $this->attackedPlayer->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' => 'springfield', 'from' => $this->actualPlayer['id'], 'to' => $this->attackedPlayer['id']));
         $this->game->save();
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
     }
 }
示例#22
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);
     }
 }
示例#23
0
 protected function run()
 {
     if ($this->check == 1) {
         // vyhodime brawl a pridavnu kartu
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
         $place = 'hand';
         // vyhodime vsetky karty hracov
         foreach ($this->playersAndCards as $playerAndCards) {
             GameUtils::throwCards($this->game, $playerAndCards['player'], $playerAndCards['cards'], $playerAndCards['place']);
             if ($playerAndCards['place'] == 'table') {
                 $place = 'table';
             }
         }
         if ($place == 'table') {
             // kedze je mozne ze berieme aspon jednu modru kartu ktora ovplyvnuje vzdialenost, preratame maticu
             // ak to bude velmi pomale, budeme to robit len ak je medzi zobratymi kartami fakt takato karta
             $matrix = GameUtils::countMatrix($this->game);
             $this->game['distance_matrix'] = serialize($matrix);
             $this->game->save();
         }
     }
 }
示例#24
0
 protected function run()
 {
     if ($this->check == self::OK) {
         $additionalLifes = 1;
         if ($this->useCharacter === TRUE && $this->actualPlayer->getIsTequilaJoe()) {
             $additionalLifes = 2;
         }
         $newLifes = min($this->actualPlayer['actual_lifes'] + $additionalLifes, $this->actualPlayer['max_lifes']);
         $this->actualPlayer['actual_lifes'] = $newLifes;
         $this->actualPlayer->save();
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
         foreach ($this->game->getPlayers() as $player) {
             if ($player->getIsMadamYto()) {
                 $drawnCards = GameUtils::drawCards($this->game, 1);
                 $handCards = unserialize($player['hand_cards']);
                 $handCards = array_merge($handCards, $drawnCards);
                 $player['hand_cards'] = serialize($handCards);
                 $player->save();
             }
         }
     }
 }
示例#25
0
 protected function run()
 {
     if ($this->check == self::OK) {
         $colorRepository = new ColorRepository();
         $count = $colorRepository->getCountAll();
         $randomColor = mt_rand(1, $count);
         $userParams = array('username' => 'AI-' . str_pad(mt_rand(0, 999), 3, 0, STR_PAD_LEFT), 'color' => $randomColor);
         $userRepository = new UserRepository();
         $newUser = $userRepository->getOneByUsername($userParams['username']);
         if (!$newUser) {
             $newUser = new User($userParams);
             $newUser = $newUser->save(TRUE);
         }
         $playersCount = GameUtils::getPosition($this->game);
         $strategyRepository = new AiStrategyRepository();
         $strategyRepository->addOrderBy(array('RAND()' => ''));
         $strategy = $strategyRepository->getOneBy();
         $params = array('game' => $this->game['id'], 'user' => $newUser['id'], 'seat' => GameUtils::getSeatOnPosition($playersCount), 'ai_strategy' => $strategy['id']);
         $player = new Player($params);
         $player->save();
     }
 }
示例#26
0
 protected function run()
 {
     if ($this->check == self::OK) {
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
         $tornadoCards = array();
         foreach ($this->game->getAlivePlayers() as $player) {
             // najprv od kazdeho hraca vezme dve random karty
             $randomCards = array();
             $handCards = unserialize($player['hand_cards']);
             if (count($handCards) <= 2) {
                 $randomCards = $handCards;
                 $player['hand_cards'] = serialize(array());
             } else {
                 shuffle($handCards);
                 for ($i = 0; $i < 2; ++$i) {
                     $randomCards[] = array_pop($handCards);
                 }
                 $player['hand_cards'] = serialize($handCards);
             }
             $player->save();
             // najdeme hraca na nasledujucej pozicii
             $nextPositionPlayer = $this->getNextPositionPlayer($this->game, $player);
             $tornadoCards[$nextPositionPlayer['id']] = $randomCards;
         }
         // kedze sa hraci zmenili musime znovu nacitat hru s novymi hracskymi detailami
         $this->game = $this->game->save(TRUE);
         foreach ($this->game->getAlivePlayers() as $player) {
             $handCards = unserialize($player['hand_cards']);
             if (isset($tornadoCards[$player['id']])) {
                 $newHandCards = array_merge($handCards, $tornadoCards[$player['id']]);
                 $player['hand_cards'] = serialize($newHandCards);
                 $player->save();
             }
         }
     }
 }
示例#27
0
    exit(1);
}
if (!empty($userId)) {
    $user = GameUsers::getGameUserById($userId);
    if (!empty($user)) {
        $userId = $user->getUserId();
        if (!empty($userId)) {
            $user->getUserLevel();
            $opponent = GameUsers::getGameUserById($opponentId);
            $opponentId = null;
            if (!empty($opponent)) {
                $opponentId = $opponent->getUserId();
                $opponent->getUserLevel();
            }
            $log->logInfo("gameResult : userId > " . $userId . " opponentId > " . $opponentId . " roomgroupId > " . $roomGroupId . " gameId > " . $gameId . " double > " . $double . " normal > " . $normal . " type > " . $type);
            $result = GameUtils::gameResult($user, $opponent, $roomGroupId, $action, $gameId, $double, $normal, $type);
            unset($userId);
            unset($user);
        } else {
            $log->logError("User not found");
            $result->result = "User not found";
        }
    } else {
        $log->logError("User not found");
        $result->result = "User not found";
    }
} else {
    $log->logError("User not found");
    $result->result = "User not found";
}
echo json_encode($result);
示例#28
0
 protected function drawBountyCard()
 {
     if ($this->actualPlayer->getHasBountyOnTheTable()) {
         $drawnCards = GameUtils::drawCards($this->game, 1);
         $handCards = unserialize($this->attackingPlayer['hand_cards']);
         $handCards = array_merge($handCards, $drawnCards);
         $this->attackingPlayer['hand_cards'] = serialize($handCards);
     }
 }
示例#29
0
 protected function run()
 {
     if ($this->check == self::OK) {
         $place = $this->params['place'];
         if (!$place) {
             $place = 'hand';
         }
         // aj Vera Custer moze hrat za Garyho Lootera
         $garyLooters = array();
         foreach ($this->getPlayers() as $player) {
             // pozrieme sa na vsetkych hracov ktori este nie su mrtvi a ani nie su aktualny hrac
             if ($player['actual_lifes'] > 0 && $this->actualPlayer['id'] != $player['id']) {
                 if ($player->getIsGaryLooter($this->game)) {
                     $garyLooters[] = $player;
                 }
             }
         }
         if ($place == 'hand' && $garyLooters) {
             // vymysliet ako davat Garymu a Vere karty na striedacku - zatial spravene len pre nahodne vybraneho Garyho
             $garyLooter = $garyLooters[array_rand($garyLooters)];
             GameUtils::moveCards($this->game, $this->cards, $this->actualPlayer, 'hand', $garyLooter, 'hand');
         } else {
             GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards, $place);
         }
         if ($place == 'table') {
             // kedze je mozne ze rusime nejaku modru kartu ktora ovplyvnuje vzdialenost, preratame maticu
             // ak to bude velmi pomale, budeme to robit len ak je medzi vyhodenymi kartami fakt takato karta
             $matrix = GameUtils::countMatrix($this->game);
             $this->game['distance_matrix'] = serialize($matrix);
             $this->game->save();
         }
         if (in_array($this->interTurnReason['action'], array('wild_band'))) {
             $this->runMollyStarkAction();
             $this->changeInterturn();
         }
     } elseif ($this->check == self::OK_JOSE_DELGADO) {
         $place = 'hand';
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards, $place);
         $drawnCards = GameUtils::drawCards($this->game, 2);
         $handCards = unserialize($this->actualPlayer['hand_cards']);
         $handCards = array_merge($handCards, $drawnCards);
         $this->actualPlayer['hand_cards'] = serialize($handCards);
         $notices = $this->actualPlayer->getNoticeList();
         if (isset($notices['character_used'])) {
             $notices['character_used'] = $notices['character_used'] + 1;
         } else {
             $notices['character_used'] = 1;
         }
         $this->actualPlayer->setNoticeList($notices);
         // zistit ci sa tu nahodou nestane to ze hracovi ostanu karty v ruke a este mu pribudnu dalsie
         $this->actualPlayer->save();
     } elseif ($this->check == self::OK_DOC_HOLYDAY) {
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
         MySmarty::assign('card', $this->cards[0]);
         // TODO mozno sem poslat nejake veci ze zautocil doc holyday svojim charakterom
         $response = MySmarty::fetch($this->template);
         $this->attackedPlayer['command_response'] = $response;
         $this->attackedPlayer['phase'] = Player::PHASE_UNDER_ATTACK;
         $this->attackedPlayer->save();
         $notices = $this->actualPlayer->getNoticeList();
         $notices['character_used'] = 1;
         $this->actualPlayer->setNoticeList($notices);
         $this->actualPlayer['phase'] = Player::PHASE_WAITING;
         $this->actualPlayer->save();
         $this->game['inter_turn'] = $this->attackedPlayer['id'];
         $this->game['inter_turn_reason'] = serialize(array('action' => 'doc_holyday', 'from' => $this->actualPlayer['id'], 'to' => $this->attackedPlayer['id']));
         $this->game->save();
     } elseif ($this->check == self::OK_SID_KETCHUM) {
         $additionalLifes = 1;
         $newLifes = min($this->actualPlayer['actual_lifes'] + $additionalLifes, $this->actualPlayer['max_lifes']);
         $this->actualPlayer['actual_lifes'] = $newLifes;
         $this->actualPlayer->save();
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
     } elseif ($this->check == self::OK_POKER) {
         // odlozime karty
         $handCards = unserialize($this->actualPlayer['hand_cards']);
         $newHandCards = array();
         $selectedCard = $this->cards[0];
         foreach ($handCards as $handCard) {
             if ($handCard != $selectedCard['id']) {
                 $newHandCards[] = $handCard;
             }
         }
         $this->actualPlayer['hand_cards'] = serialize($newHandCards);
         $this->actualPlayer->save();
         $this->interTurnReason['thrownCards'][] = $selectedCard['id'];
         $this->changeInterturn();
     }
 }
示例#30
0
 /**
  * moves drawn cards to throw pile or to john pains hand
  */
 protected function moveDrawnCards($thrownCards)
 {
     // aj Vera Custer moze hrat za Johna Paina
     $johnPains = array();
     foreach ($this->getPlayers() as $player) {
         // pozrieme sa na vsetkych hracov ktori este nie su mrtvi a ani nie su aktualny hrac
         if ($player['actual_lifes'] > 0 && $this->actualPlayer['id'] != $player['id']) {
             if ($player->getIsJohnPain($this->game)) {
                 $johnPains[] = $player;
             }
         }
     }
     // ked hraca zachrani barrel a karta ide johnovi, nastava problem s fazami, zrejme len ked je john utociaci hrac
     if ($johnPains) {
         // vymysliet ako davat Johnovi a Vere karty na striedacku - zatial spravene len pre nahodne vybraneho Johna
         $johnPain = $johnPains[array_rand($johnPains)];
         $johnPainHandCards = unserialize($johnPain['hand_cards']);
         if (count($johnPainHandCards) < 6) {
             foreach ($thrownCards as $thrownCard) {
                 $johnPainHandCards[] = $thrownCard['id'];
             }
             if ($this->attackingPlayer && $johnPain['id'] == $this->attackingPlayer['id']) {
                 $this->attackingPlayer['hand_cards'] = serialize($johnPainHandCards);
                 $this->attackingPlayer = $this->attackingPlayer->save(TRUE);
             } else {
                 $johnPain['hand_cards'] = serialize($johnPainHandCards);
                 $johnPain = $johnPain->save(TRUE);
             }
         } else {
             GameUtils::throwCards($this->game, NULL, $thrownCards);
         }
     } else {
         GameUtils::throwCards($this->game, NULL, $thrownCards);
     }
 }