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(); } }
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(); } } }
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(); } } }
protected function run() { if ($this->check == self::OK) { $this->actualPlayer['phase'] = $this->getNextPhase($this->actualPlayer); $this->actualPlayer->save(); $highNoonPile = unserialize($this->game['high_noon_pile']); $drawnCard = array_pop($highNoonPile); $this->game['high_noon'] = $drawnCard; $this->game['high_noon_pile'] = serialize($highNoonPile); $this->game = $this->game->save(TRUE); $this->executeSpecialAction(); // TODO ked prichadza High noon, treba nastavovat fazy inak $matrix = GameUtils::countMatrix($this->game); $this->game['distance_matrix'] = serialize($matrix); $this->game->save(); } }
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(); } } }
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(); } }
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(); } }
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(); } } } }
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 } } }
protected function run() { if ($this->check == self::OK) { $cardBaseTypeRepository = new CardBaseTypeRepository(); $validCardBaseTypes = $cardBaseTypeRepository->getByValid(1); $validCardBaseTypesIdList = array(); foreach ($validCardBaseTypes as $cardBaseType) { $validCardBaseTypesIdList[] = $cardBaseType['id']; } $cardRepository = new CardRepository(); $where = array('column' => 'card_base_type', 'value' => $validCardBaseTypesIdList); $cardRepository->addAdditionalWhere($where); $gameSets = unserialize($this->room['game_sets']); if ($gameSets) { $where = array('column' => 'game_set', 'value' => $gameSets); $cardRepository->addAdditionalWhere($where); } $cards = $cardRepository->getCardIds(); shuffle($cards); // TODO prepare High noon draw pile // TODO - other extensions $players = $this->players; foreach ($players as $player) { $playerCards = array(); $character = $player->getAdditionalField('character'); $role = $player->getAdditionalField('role'); $player['actual_lifes'] = $character['lifes']; $cardsCount = $player->getIsBigSpencer() ? 5 : $player['actual_lifes']; for ($i = 0; $i < $cardsCount; $i++) { $playerCards[] = array_pop($cards); } if ($role['type'] == Role::SHERIFF) { $player['phase'] = Player::PHASE_DRAW; $player['actual_lifes'] = $player['actual_lifes'] + 1; } $player['max_lifes'] = $player['actual_lifes']; $player['hand_cards'] = serialize($playerCards); $player['table_cards'] = serialize(array()); $player['wait_cards'] = serialize(array()); $player->save(); } $this->game['draw_pile'] = serialize($cards); $this->game['throw_pile'] = serialize(array()); // musime ulozit hru lebo hracom sa zmenili charaktery $this->game = $this->game->save(TRUE); $this->game = GameUtils::changePositions($this->game); foreach ($this->game->getPlayers() as $player) { if ($player['role'] == Role::SHERIFF) { $this->game['turn'] = $player['id']; break; } } $this->game['game_start'] = time(); $this->game['status'] = Game::GAME_STATUS_STARTED; $matrix = GameUtils::countMatrix($this->game); $this->game['distance_matrix'] = serialize($matrix); $this->game = $this->game->save(TRUE); } }