示例#1
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();
     }
 }
示例#2
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();
         }
     }
 }
示例#3
0
 protected function run()
 {
     if ($this->check == 1) {
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
         GameUtils::moveCards($this->game, $this->enemyPlayersCards[$this->attackedPlayer['id']], $this->attackedPlayer, 'hand', $this->actualPlayer, $this->place);
         if ($this->place == 'table') {
             // kedze je mozne ze berieme nejaku 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();
         }
     }
 }
示例#4
0
 protected function run()
 {
     if ($this->check == self::SAVE_LAST_LIFE) {
         GameUtils::throwCards($this->game, $this->actualPlayer, array($this->beerCard));
         $this->drawBountyCard();
         // za normalnych okolnosti -1 zivot
         $removedLifes = 1;
         if ($this->interTurnReason['action'] == 'aiming') {
             // dvojita rana - 2 zivoty
             $removedLifes += 1;
         }
         if ($this->attackingPlayer->getHasShootgunOnTheTable() && $this->shootgunCards) {
             GameUtils::throwCards($this->game, $this->actualPlayer, $this->shootgunCards);
         }
         // pivo +1 zivot
         $removedLifes -= 1;
         if ($this->actualPlayer->getIsTequilaJoe($this->game)) {
             // tequila joe si posledny zivot zachrani a 1 si este prida
             $removedLifes -= 1;
         }
         $this->actualPlayer['actual_lifes'] - $removedLifes;
         $this->runMollyStarkAction();
         $this->changeInterturn();
     } elseif ($this->check == self::LOST_LIFE_IN_HIGH_NOON) {
         // TODO save last life
         $newLifes = $this->actualPlayer['actual_lifes'] - 1;
         $this->actualPlayer['actual_lifes'] = $newLifes;
         $this->actualPlayer = $this->actualPlayer->save(TRUE);
         if ($newLifes <= 0) {
             $this->removePlayerFromGame();
         } else {
             $this->actualPlayer['phase'] = $this->getNextPhase($this->actualPlayer);
             $this->actualPlayer->save();
         }
     } elseif ($this->check == self::LOST_LIFE_AND_DRAW_CARDS) {
         // Chuck Wengam si moze zobrat zivot a potiahnut dve karty
         $newLifes = $this->actualPlayer['actual_lifes'] - 1;
         $handCards = unserialize($this->actualPlayer['hand_cards']);
         $drawnCards = GameUtils::drawCards($this->game, 2);
         foreach ($drawnCards as $drawnCard) {
             $handCards[] = $drawnCard;
         }
         $this->actualPlayer['actual_lifes'] = $newLifes;
         $this->actualPlayer['hand_cards'] = serialize($handCards);
         $this->actualPlayer->save();
     } elseif ($this->check == self::OK) {
         $this->drawBountyCard();
         $removedLifes = 1;
         if ($this->interTurnReason['action'] == 'aiming') {
             $removedLifes = 2;
         }
         if ($this->attackingPlayer->getHasShootgunOnTheTable() && $this->shootgunCards) {
             GameUtils::throwCards($this->game, $this->actualPlayer, $this->shootgunCards);
         }
         $newLifes = $this->actualPlayer['actual_lifes'] - $removedLifes;
         // ak by mal teren kill zomriet taha kartu
         if ($newLifes < 1 && $this->actualPlayer->getIsTerenKill()) {
             $drawnCards = GameUtils::drawCards($this->game, 1);
             $cardRepository = new CardRepository(TRUE);
             $drawnCard = $cardRepository->getOneById($drawnCards[0]);
             if (!$drawnCard->getIsSpades($this->game)) {
                 $newLifes = 1;
                 // potiahne si este 1 kartu
                 $drawnCards = GameUtils::drawCards($this->game, 1);
                 $handCards = unserialize($this->actualPlayer['hand_cards']);
                 $handCards = array_merge($handCards, $drawnCards);
                 $this->actualPlayer['hand_cards'] = serialize($handCards);
             }
         }
         $notices = $this->actualPlayer->getNoticeList();
         if (isset($notices['barrel_used'])) {
             unset($notices['barrel_used']);
         }
         if (isset($notices['character_jourdonnais_used'])) {
             unset($notices['character_jourdonnais_used']);
         }
         $this->actualPlayer->setNoticeList($notices);
         $this->actualPlayer['actual_lifes'] = $newLifes;
         $this->actualPlayer = $this->actualPlayer->save(TRUE);
         if ($newLifes <= 0) {
             $this->removePlayerFromGame();
         } else {
             //if ($this->useCharacter === TRUE && $newLifes > 0) { // ak bol pouzity charakter a nebol to este posledny zivot
             // el gringo a bart cassidy si tahaju karty
             if ($this->actualPlayer->getIsElGringo($this->game)) {
                 // el gringo
                 $attackingPlayerHandCards = $this->attackingPlayer->getHandCards();
                 if ($attackingPlayerHandCards) {
                     $movedCards = array($attackingPlayerHandCards[array_rand($attackingPlayerHandCards)]);
                     $retVal = GameUtils::moveCards($this->game, $movedCards, $this->attackingPlayer, 'hand', $this->actualPlayer, 'hand');
                     $this->actualPlayer = $retVal['playerTo'];
                     $this->attackingPlayer = $retVal['playerFrom'];
                 }
             } elseif ($this->actualPlayer->getIsBartCassidy($this->game)) {
                 // bart cassidy
                 $drawnCards = GameUtils::drawCards($this->game, 1);
                 $handCards = unserialize($this->actualPlayer['hand_cards']);
                 foreach ($drawnCards as $drawnCard) {
                     $handCards[] = $drawnCard;
                 }
                 $this->actualPlayer['hand_cards'] = serialize($handCards);
                 $this->actualPlayer = $this->actualPlayer->save(TRUE);
             }
         }
         // TODO pocitat skore - pocet zabitych hracov
         $this->changeInterturn();
     }
 }
示例#5
0
 protected function run()
 {
     if ($this->check == self::OK) {
         if ($this->params['playCardName'] == 'jail') {
             // TODO tieto karty treba najprv ukazat hracom cez log a aby sa dali vyhodit, musia byt najprv v ruke aktualneho hraca a potom ich vyhodi
             $count = 1;
             if ($this->actualPlayer->getIsLuckyDuke($this->game)) {
                 $count = 2;
             }
             $drawnCards = GameUtils::drawCards($this->game, $count);
             // TODO pocet zavisi aj od charakteru
             $isHeart = FALSE;
             $cardRepository = new CardRepository();
             $thrownCards = array();
             foreach ($drawnCards as $drawnCardId) {
                 $drawnCard = $cardRepository->getOneById($drawnCardId);
                 $thrownCards[] = $drawnCard;
                 if ($drawnCard->getIsHearts($this->game)) {
                     $isHeart = TRUE;
                     // break tu nie je lebo musime prejst cez vsetky karty
                     // aby sme vyrobili pole kariet ktore treba vyhodit
                 }
             }
             $this->moveDrawnCards($thrownCards);
             if ($isHeart) {
                 $this->drawResult = self::OK;
                 $this->actualPlayer['phase'] = Player::PHASE_DRAW;
                 $this->actualPlayer->save();
                 GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards, 'table');
             } else {
                 $this->drawResult = self::KO;
                 $this->actualPlayer['phase'] = Player::PHASE_NONE;
                 $this->actualPlayer->save();
                 GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards, 'table');
                 $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer);
                 $this->game['turn'] = $nextPositionPlayer['id'];
                 $this->game->save();
                 $nextPositionPlayer['phase'] = $this->getNextPhase($nextPositionPlayer);
                 $nextPositionPlayer->save();
             }
         } elseif ($this->params['playCardName'] == 'dynamite') {
             $count = 1;
             if ($this->actualPlayer->getIsLuckyDuke($this->game)) {
                 $count = 2;
             }
             $drawnCards = GameUtils::drawCards($this->game, $count);
             $isSafe = FALSE;
             $cardRepository = new CardRepository();
             $thrownCards = array();
             foreach ($drawnCards as $drawnCardId) {
                 $drawnCard = $cardRepository->getOneById($drawnCardId);
                 $thrownCards[] = $drawnCard;
                 if (!$drawnCard->getIsSpades($this->game) || in_array($drawnCard['value'], array('10', 'J', 'Q', 'K', 'A'))) {
                     $isSafe = TRUE;
                     // break tu nie je lebo musime prejst cez vsetky karty
                     // aby sme vyrobili pole kariet ktore treba vyhodit
                 }
             }
             $dynamite = $this->actualPlayer->getHasDynamiteOnTheTable($this->game);
             if ($isSafe === TRUE) {
                 $this->moveDrawnCards($thrownCards);
                 $this->drawResult = self::OK;
                 // posunieme dynamit dalsiemu hracovi
                 $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer);
                 if ($nextPositionPlayer->getHasDynamiteOnTheTable($this->game)) {
                     // ak dalsi hrac uz ma na stole dynamit, musim sa pozriet na hraca za nim
                     $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $nextPositionPlayer);
                 }
                 if ($nextPositionPlayer['id'] != $this->actualPlayer['id']) {
                     // v pripade dvoch hracov a dvoch dynamitov sa dynamity neposuvaju
                     $retVal = GameUtils::moveCards($this->game, array($dynamite), $this->actualPlayer, 'table', $nextPositionPlayer, 'table');
                     $this->actualPlayer = $retVal['playerFrom'];
                 }
                 $this->actualPlayer['phase'] = $this->getNextPhase($this->actualPlayer);
                 $this->actualPlayer = $this->actualPlayer->save(TRUE);
             } else {
                 $this->drawResult = self::KO;
                 // zahodime dynamit
                 $retVal = GameUtils::throwCards($this->game, $this->actualPlayer, array($dynamite), 'table');
                 $this->actualPlayer = $retVal['player'];
                 $this->game = $retVal['game'];
                 // stiahneme hracovi tri zivoty
                 $newLifes = $this->actualPlayer['actual_lifes'] - 3;
                 $this->actualPlayer['actual_lifes'] = $newLifes;
                 $this->actualPlayer['phase'] = $this->getNextPhase($this->actualPlayer);
                 $this->actualPlayer = $this->actualPlayer->save(TRUE);
                 $this->moveDrawnCards($thrownCards);
                 if ($newLifes <= 0) {
                     // TODO check ci nema na ruke pivo / piva a ak ano automaticky ich pouzit na zachranu
                     // aspon dokym nebude na 1 zivote
                     // nezabudnut na tequilla joe
                     $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer);
                     $this->game['turn'] = $nextPositionPlayer['id'];
                     $this->game->save();
                     $nextPositionPlayer['phase'] = $this->getNextPhase($nextPositionPlayer);
                     $nextPositionPlayer->save();
                     $this->removePlayerFromGame();
                 }
             }
         } elseif ($this->params['playCardName'] == 'rattlesnake') {
             $count = 1;
             if ($this->actualPlayer->getIsLuckyDuke($this->game)) {
                 $count = 2;
             }
             $drawnCards = GameUtils::drawCards($this->game, $count);
             $isSafe = FALSE;
             $cardRepository = new CardRepository();
             $thrownCards = array();
             foreach ($drawnCards as $drawnCardId) {
                 $drawnCard = $cardRepository->getOneById($drawnCardId);
                 $thrownCards[] = $drawnCard;
                 if (!$drawnCard->getIsSpades($this->game)) {
                     $isSafe = TRUE;
                     // break tu nie je lebo musime prejst cez vsetky karty
                     // aby sme vyrobili pole kariet ktore treba vyhodit
                 }
             }
             if ($isSafe === TRUE) {
                 $this->moveDrawnCards($thrownCards);
                 $this->drawResult = self::OK;
                 $this->actualPlayer['phase'] = $this->getNextPhase($this->actualPlayer, TRUE);
                 $this->actualPlayer = $this->actualPlayer->save(TRUE);
             } else {
                 $this->drawResult = self::KO;
                 // stiahneme hracovi jeden zivot
                 $newLifes = $this->actualPlayer['actual_lifes'] - 1;
                 $this->actualPlayer['actual_lifes'] = $newLifes;
                 $this->actualPlayer['phase'] = $this->getNextPhase($this->actualPlayer, TRUE);
                 $this->actualPlayer = $this->actualPlayer->save(TRUE);
                 $this->moveDrawnCards($thrownCards);
                 if ($newLifes <= 0) {
                     // TODO check ci nema na ruke pivo / piva a ak ano automaticky ich pouzit na zachranu
                     // aspon dokym nebude na 1 zivote
                     // nezabudnut na tequilla joe
                     $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer);
                     $this->game['turn'] = $nextPositionPlayer['id'];
                     $this->game->save();
                     $nextPositionPlayer['phase'] = $this->getNextPhase($nextPositionPlayer);
                     $nextPositionPlayer->save();
                     $this->removePlayerFromGame();
                 }
             }
         } elseif ($this->params['playCardName'] == 'barrel') {
             $count = 1;
             if ($this->actualPlayer->getIsLuckyDuke($this->game)) {
                 $count = 2;
             }
             $drawnCards = GameUtils::drawCards($this->game, $count);
             $isHeart = FALSE;
             $cardRepository = new CardRepository();
             $thrownCards = array();
             foreach ($drawnCards as $drawnCardId) {
                 $drawnCard = $cardRepository->getOneById($drawnCardId);
                 $thrownCards[] = $drawnCard;
                 if ($drawnCard->getIsHearts($this->game)) {
                     $isHeart = TRUE;
                     // break tu nie je lebo musime prejst cez vsetky karty
                     // aby sme vyrobili pole kariet ktore treba vyhodit
                 }
             }
             $notices = $this->actualPlayer->getNoticeList();
             if ($this->drawType == 'barrel') {
                 $notices['barrel_used'] = 1;
             } elseif ($this->drawType == 'character') {
                 $notices['character_jourdonnais_used'] = 1;
             }
             $this->actualPlayer->setNoticeList($notices);
             $this->actualPlayer = $this->actualPlayer->save(TRUE);
             if ($isHeart) {
                 $this->drawResult = self::OK;
                 $this->changeInterturn();
             } else {
                 $this->drawResult = self::KO;
             }
             $this->moveDrawnCards($thrownCards);
         } else {
             if ($this->useCharacter === TRUE && $this->actualPlayer->getIsVeraCuster($this->game)) {
                 $notices = $this->actualPlayer->getNoticeList();
                 $selectedCharacter = $this->enemyPlayer->getCharacter();
                 $notices['selected_character'] = $selectedCharacter['id'];
                 $this->actualPlayer->setNoticeList($notices);
                 $this->actualPlayer = $this->actualPlayer->save(TRUE);
                 // kedze je mozne ze si vyberieme nejaky charakter, ktory ovplyvnuje vzdialenost, preratame maticu
                 $matrix = GameUtils::countMatrix($this->game);
                 $this->game['distance_matrix'] = serialize($matrix);
                 $this->game = $this->game->save(TRUE);
             }
             $counts = $this->getCountCards();
             if ($this->actualPlayer->getIsYoulGrinner($this->game)) {
                 $youlHandCardsCount = count($this->actualPlayer->getHandCards());
                 foreach ($this->getPlayers() as $player) {
                     if ($player->getIsAlive() && $player['id'] != $this->actualPlayer['id']) {
                         $playersHandCardsCount = count($player->getHandCards());
                         if ($playersHandCardsCount > $youlHandCardsCount) {
                             $movedCard = $player->getCardWithId();
                             GameUtils::moveCards($this->game, array($movedCard), $player, 'hand', $this->actualPlayer, 'hand');
                         }
                     }
                 }
             } elseif ($this->useCharacter === TRUE) {
                 if ($this->actualPlayer->getIsJesseJones($this->game)) {
                     $retVal = GameUtils::moveCards($this->game, $this->enemyPlayersCards[$this->enemyPlayer['id']], $this->enemyPlayer, 'hand', $this->actualPlayer, $this->place);
                     $this->actualPlayer = $retVal['playerTo'];
                     $this->game = $retVal['game'];
                 } elseif ($this->actualPlayer->getIsPatBrennan($this->game)) {
                     $retVal = GameUtils::moveCards($this->game, $this->enemyPlayersCards[$this->enemyPlayer['id']], $this->enemyPlayer, 'hand', $this->actualPlayer, $this->place);
                     $this->actualPlayer = $retVal['playerTo'];
                     $this->game = $retVal['game'];
                     // 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();
                 } elseif ($this->actualPlayer->getIsPedroRamirez($this->game)) {
                     $throwPile = unserialize($this->game['throw_pile']);
                     $card = array_pop($throwPile);
                     $this->game['throw_pile'] = serialize($throwPile);
                     $handCards = unserialize($this->actualPlayer['hand_cards']);
                     $handCards[] = $card;
                     $this->actualPlayer['hand_cards'] = serialize($handCards);
                 } elseif ($this->actualPlayer->getIsEvelynTheBang($this->game)) {
                     MySmarty::assign('card', NULL);
                     // TODO select random bang card or evelyn character card
                     $response = MySmarty::fetch('you-are-attacked.tpl');
                     $this->enemyPlayer['phase'] = Player::PHASE_UNDER_ATTACK;
                     $this->enemyPlayer['command_response'] = $response;
                     $this->enemyPlayer->save();
                     $this->game['inter_turn'] = $this->enemyPlayer['id'];
                     $this->game['inter_turn_reason'] = serialize(array('action' => 'bang', 'from' => $this->actualPlayer['id'], 'to' => $this->enemyPlayer['id']));
                     $this->game->save();
                 }
             }
             $drawnCards = GameUtils::drawCards($this->game, $counts['draw']);
             // len hrac ktory musi vratit kartu nazad bude vyberat karty
             if ($counts['rest_action'] == 'back_to_deck') {
                 $possibleChoices = array('drawn_cards' => $drawnCards, 'possible_pick_count' => $counts['pick'], 'rest_action' => $counts['rest_action']);
                 $this->actualPlayer['possible_choices'] = serialize($possibleChoices);
             } else {
                 // ostatnym sa rovno pridaju do ruky
                 $handCards = unserialize($this->actualPlayer['hand_cards']);
                 foreach ($drawnCards as $drawnCard) {
                     $handCards[] = $drawnCard;
                 }
                 $this->actualPlayer['hand_cards'] = serialize($handCards);
             }
             if ($this->useCharacter === TRUE && $this->actualPlayer->getIsEvelynTheBang($this->game)) {
                 $this->actualPlayer['phase'] = Player::PHASE_WAITING;
             } else {
                 $this->actualPlayer['phase'] = Player::PHASE_PLAY;
             }
             $this->actualPlayer->save();
         }
     } elseif ($this->check == self::PEYOTE_OK) {
         $color = $this->params['peyoteColor'];
         $method = 'getIs' . ucfirst($color);
         $drawnCards = GameUtils::drawCards($this->game, 1);
         // TODO messages, ukazat kartu ktora bola potiahnuta
         $cardRepository = new CardRepository(TRUE);
         $drawnCardId = $drawnCards[0];
         $drawnCard = $cardRepository->getOneById($drawnCardId);
         if ($drawnCard->{$method}($this->game)) {
             $handCards = unserialize($this->actualPlayer['hand_cards']);
             $handCards[] = $drawnCardId;
             $this->actualPlayer['hand_cards'] = serialize($handCards);
         } else {
             GameUtils::throwCards($this->game, NULL, array($drawnCard));
             $this->actualPlayer['phase'] = Player::PHASE_PLAY;
         }
         $this->actualPlayer->save();
     }
 }
示例#6
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();
     }
 }
示例#7
0
 protected function run()
 {
     if ($this->check == self::OK) {
         GameUtils::moveCards($this->game, $this->cards, $this->actualPlayer, 'table', $this->attackedPlayer);
     }
 }
示例#8
0
 protected function removePlayerFromGame()
 {
     $this->actualPlayer['actual_lifes'] = 0;
     $this->actualPlayer['position'] = 0;
     $this->actualPlayer['phase'] = 0;
     $this->actualPlayer = $this->actualPlayer->save(TRUE);
     // TODO message ze hrac zomrel
     // ak je v hre Vera Custer tak moze mat jeden z tychto charakterov
     // preto su vsetky premenne array a nie len Player
     $vultureSams = array();
     $gregDiggers = array();
     $herbHunters = array();
     foreach ($this->getPlayers() as $player) {
         // pozrieme sa na vsetkych hracov ktori este nie su mrtvi a ani nie su aktualny hrac (bohvie ako je on ulozeny v $this->players :)
         if ($player['actual_lifes'] > 0 && $this->actualPlayer['id'] != $player['id']) {
             // najprv pozrieme ci hrac nie je vera custer s charakterom zabiteho hraca, ak ano, vera uz nemoze mat jeho vlastnost
             if ($player->getIsVeraCuster($this->game)) {
                 $notices = $player->getNoticeList();
                 $actualPlayerCharacter = $this->actualPlayer->getCharacter();
                 if (isset($notices['selected_character']) && $notices['selected_character'] == $actualPlayerCharacter['id']) {
                     unset($notices['selected_character']);
                 }
                 $player->setNoticeList($notices);
                 $player->save();
             }
             if ($player->getIsVultureSam($this->game)) {
                 $vultureSams[] = $player;
             } elseif ($player->getIsGregDigger($this->game)) {
                 $gregDiggers[] = $player;
             } elseif ($player->getIsHerbHunter($this->game)) {
                 $herbHunters[] = $player;
             }
         }
     }
     // pridame vsetkym gregom diggerom 2 zivoty (resp. tolko kolko potrebuju)
     if ($gregDiggers) {
         foreach ($gregDiggers as $gregDigger) {
             $newLifes = min($gregDigger['actual_lifes'] + 2, $gregDigger['max_lifes']);
             $gregDigger['actual_lifes'] = $newLifes;
             $gregDigger->save();
         }
     }
     // potiahneme pre kazdeho herba huntera 2 karty
     if ($herbHunters) {
         foreach ($herbHunters as $herbHunter) {
             $drawnCards = GameUtils::drawCards($this->game, 2);
             $handCards = unserialize($herbHunter['hand_cards']);
             foreach ($drawnCards as $card) {
                 $handCards[] = $card;
             }
             $herbHunter['hand_cards'] = serialize($handCards);
             $herbHunter->save();
         }
     }
     if ($vultureSams) {
         if (count($vultureSams) == 1) {
             $vultureSamPlayer = $vultureSams[0];
             $retVal = GameUtils::moveCards($this->game, $this->actualPlayer->getHandCards(), $this->actualPlayer, 'hand', $vultureSamPlayer, 'hand');
             $vultureSamPlayer = $retVal['playerTo'];
             $this->actualPlayer = $retVal['playerFrom'];
             $retVal = GameUtils::moveCards($this->game, $this->actualPlayer->getTableCards(), $this->actualPlayer, 'hand', $vultureSamPlayer, 'table');
             $vultureSamPlayer = $retVal['playerTo'];
             $this->actualPlayer = $retVal['playerFrom'];
             $retVal = GameUtils::moveCards($this->game, $this->actualPlayer->getWaitCards(), $this->actualPlayer, 'hand', $vultureSamPlayer, 'wait');
             $vultureSamPlayer = $retVal['playerTo'];
             $this->actualPlayer = $retVal['playerFrom'];
         } else {
             throw new Exception("More than one Vulture Sam in a game", 1352146582);
         }
     } else {
         $retVal = GameUtils::throwCards($this->game, $this->actualPlayer, $this->actualPlayer->getHandCards(), 'hand');
         $this->game = $retVal['game'];
         $this->actualPlayer = $retVal['player'];
         $retVal = GameUtils::throwCards($this->game, $this->actualPlayer, $this->actualPlayer->getTableCards(), 'table');
         $this->game = $retVal['game'];
         $this->actualPlayer = $retVal['player'];
         $retVal = GameUtils::throwCards($this->game, $this->actualPlayer, $this->actualPlayer->getWaitCards(), 'wait');
         $this->game = $retVal['game'];
         $this->actualPlayer = $retVal['player'];
     }
     // znovunacitame game z databazy, lebo sa par veci zmenilo medzitym
     $gameRepository = new GameRepository();
     $this->game = $gameRepository->getOneById($this->game['id']);
     // TODO po zmene positions sa pravdepodobne zmeni aj pozicia hraca ktory
     // je na tahu, treba to tu na tomto mieste znovu preratat a nastavit game[position]
     // na poziciu hraca s ideckom ktore ma attacking player a rovnako aj inter_turn bude treba preratat
     $this->game = GameUtils::changePositions($this->game);
     $matrix = GameUtils::countMatrix($this->game);
     $this->game['distance_matrix'] = serialize($matrix);
     $this->game = $this->game->save(TRUE);
     // najst hraca ktory ma fazu != 0 a nastavit ho v hre ako hraca ktory je na tahu
     // znovu nacitame z databazy utociaceho hraca ( pre istotu )
     $attackingPlayerId = $this->interTurnReason['from'];
     $playerRepository = new PlayerRepository();
     $this->attackingPlayer = $playerRepository->getOneById($attackingPlayerId);
     $playerRepository = new PlayerRepository();
     $role = $this->actualPlayer->getRoleObject();
     if ($role['type'] == Role::BANDIT) {
         if ($playerRepository->getCountLivePlayersWithRoles($this->game['id'], array(Role::ROLE_BANDIT_1, Role::ROLE_BANDIT_2, Role::ROLE_BANDIT_3, Role::ROLE_RENEGARD_1, Role::ROLE_RENEGARD_2)) == 0) {
             $this->endGame(array(Role::ROLE_SHERIFF, Role::ROLE_VICE_1, Role::ROLE_VICE_2));
         } else {
             // TODO doplnit pocty kariet ak su ine pre rozne charaktery utociacich hracov
             // TODO doplnit podmienky pre typy utokov ktorych sa tieto tahania tykaju - indiani tam myslim nepatria
             // TODO message o tom ze si tento hrac potiahol 3 karty za banditu
             // za banditu dostane utocnik 3 karty - ale len ak slo o priamy utok
             if ($this->attackingPlayer) {
                 $drawnCards = GameUtils::drawCards($this->game, 3);
                 $handCards = unserialize($this->attackingPlayer['hand_cards']);
                 foreach ($drawnCards as $card) {
                     $handCards[] = $card;
                 }
                 $this->attackingPlayer['hand_cards'] = serialize($handCards);
                 $this->attackingPlayer = $this->attackingPlayer->save(TRUE);
             }
         }
     } elseif ($role['type'] == Role::SHERIFF) {
         if ($playerRepository->getCountLivePlayersWithRoles($this->game['id']) == 1) {
             if ($playerRepository->getCountLivePlayersWithRoles($this->game['id'], array(Role::ROLE_RENEGARD_1)) == 1) {
                 $this->endGame(array(Role::ROLE_RENEGARD_1));
             } elseif ($playerRepository->getCountLivePlayersWithRoles($this->game['id'], array(Role::ROLE_RENEGARD_1)) == 1) {
                 $this->endGame(array(Role::ROLE_RENEGARD_2));
             } else {
                 $this->endGame(array(Role::ROLE_BANDIT_1, Role::ROLE_BANDIT_2, Role::ROLE_BANDIT_3));
             }
         } else {
             $this->endGame(array(Role::ROLE_BANDIT_1, Role::ROLE_BANDIT_2, Role::ROLE_BANDIT_3));
         }
     } elseif ($role['type'] == Role::RENEGARD) {
         if ($playerRepository->getCountLivePlayersWithRoles($this->game['id'], array(Role::ROLE_BANDIT_1, Role::ROLE_BANDIT_2, Role::ROLE_BANDIT_3, Role::ROLE_RENEGARD_1, Role::ROLE_RENEGARD_2)) == 0) {
             $this->endGame(array(Role::ROLE_SHERIFF, Role::ROLE_VICE_1, Role::ROLE_VICE_2));
         }
     } elseif ($role['type'] == Role::VICE) {
         if ($this->attackingPlayer) {
             $attackingRole = $this->attackingPlayer->getRoleObject();
             if ($attackingRole['type'] == Role::SHERIFF) {
                 $retVal = GameUtils::throwCards($this->game, $this->attackingPlayer, $this->attackingPlayer->getHandCards(), 'hand');
                 $this->game = $retVal['game'];
                 $this->attackingPlayer = $retVal['player'];
                 $retVal = GameUtils::throwCards($this->game, $this->attackingPlayer, $this->attackingPlayer->getTableCards(), 'table');
                 $this->game = $retVal['game'];
                 $this->attackingPlayer = $retVal['player'];
                 $retVal = GameUtils::throwCards($this->game, $this->attackingPlayer, $this->attackingPlayer->getWaitCards(), 'wait');
                 $this->game = $retVal['game'];
                 $this->attackingPlayer = $retVal['player'];
                 // 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();
             }
         }
     }
 }