Example #1
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);
     }
 }
Example #2
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);
     }
 }
Example #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);
     }
 }
Example #4
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);
     }
 }
Example #5
0
 protected function run()
 {
     if ($this->check == DefensiveCommand::OK) {
         GameUtils::throwCards($this->game, $this->actualPlayer, $this->cards);
         $this->runMollyStarkAction();
         $this->changeInterturn();
     }
 }
Example #6
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();
     }
 }
Example #7
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');
     }
 }
Example #8
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);
 }
Example #9
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();
     }
 }
Example #10
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();
     }
 }
Example #11
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();
         }
     }
 }
Example #12
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();
     }
 }
Example #13
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
     }
 }
Example #14
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);
     }
 }
Example #15
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);
     }
 }
Example #16
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();
         }
     }
 }
Example #17
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();
             }
         }
     }
 }
Example #18
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();
             }
         }
     }
 }
Example #19
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();
     }
 }
Example #20
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();
     }
 }
Example #21
0
 protected function run()
 {
     if ($this->check == self::OK) {
         $passTurn = TRUE;
         if ($this->game->getIsHNVendetta() && !$this->actualPlayer->getPlayedVendetta()) {
             // TODO mozno by toto mohla byt metoda
             $count = 1;
             // neviem ci lucky duke pri vendete taha dve karty
             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
                 }
             }
             GameUtils::throwCards($this->game, NULL, $thrownCards);
             if ($isHeart) {
                 $passTurn = FALSE;
             }
         }
         if ($passTurn) {
             $this->actualPlayer['phase'] = Player::PHASE_NONE;
             $this->actualPlayer['bang_used'] = 0;
             $tableCards = unserialize($this->actualPlayer['table_cards']);
             $waitCards = unserialize($this->actualPlayer['wait_cards']);
             $this->actualPlayer['table_cards'] = serialize(array_merge($tableCards, $waitCards));
             $this->actualPlayer['wait_cards'] = serialize(array());
             // znulujeme notices
             $notices = $this->actualPlayer->getNoticeList();
             if (isset($notices['barrel_used'])) {
                 unset($notices['barrel_used']);
             }
             if (isset($notices['character_jourdonnais_used'])) {
                 unset($notices['character_jourdonnais_used']);
             }
             if (isset($notices['character_used'])) {
                 unset($notices['character_used']);
             }
             // spravime zalohu premennej ghost
             $isGhost = $this->actualPlayer->getIsGhost();
             // zrusime ghosta
             if (isset($notices['ghost'])) {
                 unset($notices['ghost']);
             }
             if (isset($notices['vendetta'])) {
                 unset($notices['vendetta']);
             }
             if (isset($notices['blood_brothers'])) {
                 unset($notices['blood_brothers']);
             }
             $this->actualPlayer->setNoticeList($notices);
             $this->actualPlayer = $this->actualPlayer->save(TRUE);
             if ($this->game->getIsHNGhostTown() && $isGhost === TRUE) {
                 // odstranime ghosta
                 $this->removePlayerFromGame();
             }
             $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer, TRUE);
             $this->game['turn'] = $nextPositionPlayer['id'];
             $this->game->save();
             if ($this->game->getIsHNGhostTown() && $nextPositionPlayer['actual_lifes'] == 0) {
                 $notices = $nextPositionPlayer->getNoticeList();
                 $notices['ghost'] = 1;
                 $nextPositionPlayer->setNoticeList($notices);
             }
             $nextPositionPlayer['phase'] = $this->getNextPhase($nextPositionPlayer);
             $nextPositionPlayer->save();
             // preratame maticu
             $matrix = GameUtils::countMatrix($this->game);
             $this->game['distance_matrix'] = serialize($matrix);
             $this->game->save();
         } else {
             $notices = $this->actualPlayer->getNoticeList();
             $notices['vendetta'] = 1;
             $this->actualPlayer->setNoticeList($notices);
             $this->actualPlayer['phase'] = $this->getNextPhase($this->actualPlayer);
             $this->actualPlayer = $this->actualPlayer->save(TRUE);
             // TODO message
         }
     }
 }
Example #22
0
 protected function helenaZontero()
 {
     $drawnCardIds = GameUtils::drawCards($this->game, 1);
     $cardRepository = new CardRepository(TRUE);
     $drawnCard = $cardRepository->getOneById($drawnCardIds);
     if ($drawnCard->getIsRed($this->game)) {
         $roles = array();
         foreach ($this->getPlayers() as $player) {
             if (!$player->getRoleObject()->getIsSheriff() && $player->getIsAlive()) {
                 $role = $player->getRoleObject();
                 $roles[] = $role['id'];
             }
         }
         shuffle($roles);
         foreach ($this->getPlayers() as $newPlayer) {
             if (!$newPlayer->getRoleObject()->getIsSheriff() && $newPlayer->getIsAlive()) {
                 $role = array_pop($roles);
                 $newPlayer['role'] = $role;
                 $newPlayer->save();
             }
         }
     }
     GameUtils::throwCards($this->game, NULL, array($drawnCard));
 }
Example #23
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);
     }
 }
Example #24
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();
             }
         }
     }
 }
Example #25
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);
     }
 }