public function __construct($game) { parent::__construct($game); $cardRepository = new CardRepository(TRUE); $drawPile = unserialize($game['draw_pile']); $drawPileCards = array(); if ($drawPile) { foreach ($drawPile as $cardId) { $drawPileCards[] = $cardRepository->getOneById($cardId); } } $this->setAdditionalField('draw_pile', $drawPileCards); $throwPile = unserialize($game['throw_pile']); $throwPileCards = array(); if ($throwPile) { foreach ($throwPile as $cardId) { $throwPileCards[] = $cardRepository->getOneById(intval($cardId)); } } $this->setAdditionalField('throw_pile', $throwPileCards); $playerRepository = new PlayerRepository(); $players = $playerRepository->getByGame($game['id']); $this->setAdditionalField('players', $players); $this->setAdditionalField('matrix', unserialize($game['distance_matrix'])); $gameSets = unserialize($game['game_sets']); if (in_array(3, $gameSets)) { $isHighNoon = TRUE; } else { $isHighNoon = FALSE; } $this->setAdditionalField('isHighNoon', $isHighNoon); if ($isHighNoon) { $highNoonPile = unserialize($game['high_noon_pile']); $highNoonRepository = new HighNoonRepository(TRUE); $highNoonPileCards = array(); if ($highNoonPile) { foreach ($highNoonPile as $cardId) { $highNoonPileCards[] = $highNoonRepository->getOneById(intval($cardId)); } } $this->setAdditionalField('highNoonPile', $highNoonPileCards); if ($game['high_noon']) { $highNoonRepository = new HighNoonRepository(); $highNoon = $highNoonRepository->getOneById(intval($game['high_noon'])); $this->setAdditionalField('highNoon', $highNoon); } } }
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(); } }
protected function createResponse() { if ($this->check == self::OK) { if ($this->params['playCardName'] == 'jail') { } elseif ($this->params['playCardName'] == 'dynamite') { } elseif ($this->params['playCardName'] == 'barrel') { } else { if ($this->actualPlayer['possible_choices']) { $possibleChoices = unserialize($this->actualPlayer['possible_choices']); $cardRepository = new CardRepository(); $possibleCards = array(); foreach ($possibleChoices['drawn_cards'] as $cardId) { $possibleCards[] = $cardRepository->getOneById($cardId); } MySmarty::assign('possiblePickCount', $possibleChoices['possible_pick_count']); MySmarty::assign('possibleCards', $possibleCards); MySmarty::assign('possibleCardsCount', count($possibleCards)); MySmarty::assign('game', $this->game); $response = MySmarty::fetch($this->template); $this->actualPlayer['command_response'] = $response; $this->actualPlayer->save(); return $response; } } } }
public function main() { $gameId = intval(Utils::post('game')); $gameRepository = new GameRepository(); $game = $gameRepository->getOneById($gameId); $commandParams = array(); $commandParams['command'] = addslashes(Utils::post('command')); $commandParams['useCharacter'] = intval(Utils::post('useCharacter')); $commandParams['playCardId'] = intval(Utils::post('playCard')); if ($commandParams['playCardId']) { $cardRepository = new CardRepository(TRUE); $card = $cardRepository->getOneById($commandParams['playCardId']); $commandParams['playCardName'] = str_replace('-', '', $card->getItemAlias()); } // TODO mozno ich niekedy bude viac $commandParams['additionalCardsId'] = intval(Utils::post('additionalCard')); if ($commandParams['additionalCardsId']) { $cardRepository = new CardRepository(TRUE); $card = $cardRepository->getOneById($commandParams['additionalCardsId']); $commandParams['additionalCardsName'] = str_replace('-', '', $card->getItemAlias()); } $commandParams['enemyPlayerId'] = intval(Utils::post('player')); if ($commandParams['enemyPlayerId']) { $playerRepository = new PlayerRepository(); $player = $playerRepository->getOneById($commandParams['enemyPlayerId']); if ($player) { $user = $player->getUser(); if ($user) { $commandParams['enemyPlayerUsername'] = $user['username']; } } } if ($commandParams['command'] == 'fanning') { $commandParams['additionalEnemyPlayerId'] = intval(Utils::post('additionalPlayer')); if ($commandParams['additionalEnemyPlayerId']) { $playerRepository = new PlayerRepository(); $player = $playerRepository->getOneById($commandParams['additionalEnemyPlayerId']); if ($player) { $user = $player->getUser(); if ($user) { $commandParams['additionalEnemyPlayerUsername'] = $user['username']; } } } } // TODO brawl tu dava addslashes if ($commandParams['command'] == 'brawl') { $commandParams['enemyCardsId'] = addslashes(Utils::post('card')); } elseif ($commandParams['command'] == 'choose_cards') { $commandParams['selectedCards'] = addslashes(Utils::post('card')); } else { $commandParams['enemyCardsId'] = intval(Utils::post('card')); if ($commandParams['enemyCardsId']) { $cardRepository = new CardRepository(TRUE); $card = $cardRepository->getOneById($commandParams['enemyCardsId']); $commandParams['enemyCardsName'] = str_replace('-', '', $card->getItemAlias()); } } $commandParams['place'] = addslashes(Utils::post('place')); if (Utils::post('peyoteColor')) { $commandParams['peyoteColor'] = addslashes(Utils::post('peyoteColor')); } if (Utils::post('text')) { $commandParams['text'] = addslashes(Utils::post('text')); } $params = array(); foreach ($commandParams as $key => $value) { $params[] = $key . '=' . $value; } $commandString = implode('&', $params); Log::command($commandString); Command::setup($commandString, $game); }
protected function run() { if ($this->check == self::OK) { $possibleChoices = unserialize($this->actualPlayer['possible_choices']); $possibleCards = $possibleChoices['drawn_cards']; $restAction = $possibleChoices['rest_action']; $handCards = unserialize($this->actualPlayer['hand_cards']); $drawPile = unserialize($this->game['draw_pile']); $throwPile = unserialize($this->game['throw_pile']); $nextPlayerPossibleCards = array(); foreach ($possibleCards as $possibleCard) { if (in_array($possibleCard, $this->params['selectedCards'])) { $handCards[] = $possibleCard; } else { if ($restAction == 'back_to_deck') { $drawPile[] = $possibleCard; } elseif ($restAction == 'general_store') { $nextPlayerPossibleCards[] = $possibleCard; } elseif ($restAction == 'throw') { $throwPile[] = $possibleCard; } } } if ($this->interTurnReason['action'] == 'general_store') { $nextPositionPlayer = GameUtils::getPlayerOnNextPosition($this->game, $this->actualPlayer); if ($nextPositionPlayer['id'] == $this->attackingPlayer['id']) { $this->game['inter_turn_reason'] = ''; $this->game['inter_turn'] = 0; $this->attackingPlayer['phase'] = Player::PHASE_PLAY; $this->attackingPlayer->save(); } else { if ($this->actualPlayer['id'] == $this->attackingPlayer['id']) { $this->actualPlayer['phase'] = Player::PHASE_WAITING; } else { $this->actualPlayer['phase'] = Player::PHASE_NONE; } $this->game['inter_turn'] = $nextPositionPlayer['id']; $cardRepository = new CardRepository(); $possibleCards = array(); foreach ($nextPlayerPossibleCards as $cardId) { $possibleCards[] = $cardRepository->getOneById($cardId); } MySmarty::assign('possiblePickCount', 1); MySmarty::assign('possibleCards', $possibleCards); MySmarty::assign('possibleCardsCount', count($possibleCards)); MySmarty::assign('game', $this->game); $response = MySmarty::fetch($this->template); $playerPossibleChoices = array('drawn_cards' => $nextPlayerPossibleCards, 'possible_pick_count' => 1, 'rest_action' => 'general_store'); $nextPositionPlayer['phase'] = Player::PHASE_UNDER_ATTACK; $nextPositionPlayer['possible_choices'] = serialize($playerPossibleChoices); $nextPositionPlayer['command_response'] = $response; $nextPositionPlayer->save(); } } else { $this->actualPlayer['phase'] = Player::PHASE_PLAY; } $this->actualPlayer['hand_cards'] = serialize($handCards); $this->actualPlayer['command_response'] = ''; $this->actualPlayer['possible_choices'] = ''; $this->actualPlayer = $this->actualPlayer->save(TRUE); $this->game['draw_pile'] = serialize($drawPile); $this->game['throw_pile'] = serialize($throwPile); $this->game = $this->game->save(TRUE); } }
protected function changeInterturn() { $attackingPlayerNotices = $this->attackingPlayer->getNoticeList(); if ($this->attackingPlayer->getIsSlabTheKiller($this->game) && $attackingPlayerNotices['character_used'] && in_array($this->interTurnReason['action'], array('bang')) && $this->commandName != 'life') { // zrusime slab the killerovi prvu ranu, dalsie vedla by uz malo ist do else vetvy if (isset($attackingPlayerNotices['character_used'])) { unset($attackingPlayerNotices['character_used']); } $this->attackingPlayer->setNoticeList($attackingPlayerNotices); $this->attackingPlayer->save(); } else { if (in_array($this->interTurnReason['action'], array('indians', 'gatling', 'howitzer', 'wild_band'))) { $nextPositionPlayer = $this->getNextPositionPlayer($this->game, $this->actualPlayer); // ak je hrac na nasledujucej pozicii ten ktory utocil, ukoncime inter turn if ($nextPositionPlayer['id'] == $this->attackingPlayer['id']) { $this->game['inter_turn_reason'] = ''; $this->game['inter_turn'] = 0; if ($this->attackingPlayer->getIsBelleStar($this->game)) { $attackingPlayerNotices = $this->attackingPlayer->getNoticeList(); if (isset($attackingPlayerNotices['character_used'])) { unset($attackingPlayerNotices['character_used']); } $this->attackingPlayer->setNoticeList($attackingPlayerNotices); } $this->attackingPlayer['phase'] = Player::PHASE_PLAY; $this->attackingPlayer->save(); } else { // inak nastavime pokracovanie interturnu $nextPositionPlayer['phase'] = Player::PHASE_UNDER_ATTACK; $nextPositionPlayer->save(); $this->game['inter_turn_reason'] = serialize(array('action' => $this->interTurnReason['action'], 'from' => $this->attackingPlayer['id'], 'to' => $nextPositionPlayer['id'], 'cards' => $this->interTurnReason['cards'])); $this->game['inter_turn'] = $nextPositionPlayer['id']; } } elseif (in_array($this->interTurnReason['action'], array('fanning'))) { if (isset($this->interTurnReason['additionalTo'])) { $playerRepository = new PlayerRepository(); $nextPlayer = $playerRepository->getOneById($this->interTurnReason['additionalTo']); $nextPlayer['phase'] = Player::PHASE_UNDER_ATTACK; $nextPlayer->save(); $this->game['inter_turn_reason'] = serialize(array('action' => $this->interTurnReason['action'], 'from' => $this->attackingPlayer['id'], 'to' => $this->interTurnReason['additionalTo'], 'cards' => $this->interTurnReason['cards'])); $this->game['inter_turn'] = $this->interTurnReason['additionalTo']; } else { // ukoncime interturn $this->game['inter_turn_reason'] = ''; $this->game['inter_turn'] = 0; if ($this->attackingPlayer->getIsBelleStar($this->game) || $this->attackingPlayer->getIsSlabTheKiller($this->game)) { $attackingPlayerNotices = $this->attackingPlayer->getNoticeList(); if (isset($attackingPlayerNotices['character_used'])) { unset($attackingPlayerNotices['character_used']); } $this->attackingPlayer->setNoticeList($attackingPlayerNotices); } $this->attackingPlayer['phase'] = Player::PHASE_PLAY; $this->attackingPlayer->save(); } } elseif (in_array($this->interTurnReason['action'], array('poker'))) { $nextPositionPlayer = $this->findNextPlayerWithHandCards($this->game, $this->actualPlayer, $this->attackingPlayer); // ak je hrac na nasledujucej pozicii ten ktory utocil, ukoncime inter turn if ($nextPositionPlayer['id'] == $this->attackingPlayer['id']) { $this->game['inter_turn_reason'] = ''; $this->game['inter_turn'] = 0; $cardRepository = new CardRepository(); $possibleCards = array(); $containAce = FALSE; foreach ($this->interTurnReason['thrownCards'] as $cardId) { $possibleCard = $cardRepository->getOneById($cardId); if ($possibleCard['value'] == 'A') { $containAce = TRUE; } $possibleCards[] = $possibleCard; } if ($containAce === TRUE) { // ak je vyhodene aspon jedno eso $this->attackingPlayer['phase'] = Player::PHASE_PLAY; // odhodime vsetky karty, ktore hraci vylozili $throwPile = unserialize($this->game['throw_pile']); foreach ($this->interTurnReason['thrownCards'] as $cardId) { $throwPile[] = $cardId; } $this->game['throw_pile'] = serialize($throwPile); } else { // inak vybera 2 karty z vyhoenych MySmarty::assign('possiblePickCount', 2); MySmarty::assign('possibleCards', $possibleCards); MySmarty::assign('possibleCardsCount', count($possibleCards)); MySmarty::assign('game', $this->game); $response = MySmarty::fetch('cards-choice.tpl'); $playerPossibleChoices = array('drawn_cards' => $this->interTurnReason['thrownCards'], 'possible_pick_count' => 2, 'rest_action' => 'throw'); $this->attackingPlayer['phase'] = Player::PHASE_POKER_SELECT; $this->attackingPlayer['possible_choices'] = serialize($playerPossibleChoices); $this->attackingPlayer['command_response'] = $response; } $this->attackingPlayer->save(); } else { // inak nastavime pokracovanie interturnu $nextPositionPlayer['phase'] = Player::PHASE_UNDER_ATTACK; $nextPositionPlayer->save(); $this->game['inter_turn_reason'] = serialize(array('action' => $this->interTurnReason['action'], 'from' => $this->attackingPlayer['id'], 'to' => $nextPositionPlayer['id'], 'thrownCards' => $this->interTurnReason['thrownCards'])); $this->game['inter_turn'] = $nextPositionPlayer['id']; } } else { // ukoncime interturn $this->game['inter_turn_reason'] = ''; $this->game['inter_turn'] = 0; if ($this->attackingPlayer->getIsBelleStar($this->game) || $this->attackingPlayer->getIsSlabTheKiller($this->game)) { $attackingPlayerNotices = $this->attackingPlayer->getNoticeList(); if (isset($attackingPlayerNotices['character_used'])) { unset($attackingPlayerNotices['character_used']); } $this->attackingPlayer->setNoticeList($attackingPlayerNotices); } $this->attackingPlayer['phase'] = Player::PHASE_PLAY; $this->attackingPlayer->save(); } // premazeme 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']); } $this->actualPlayer->setNoticeList($notices); // aktualnemu hracovi nastavime fazu na none a response na nic vzdy if ($this->actualPlayer['id'] == $this->interTurnReason['to']) { $this->actualPlayer['phase'] = Player::PHASE_NONE; } elseif ($this->actualPlayer['id'] == $this->interTurnReason['from']) { $this->actualPlayer['phase'] = Player::PHASE_PLAY; } else { throw new Exception('Moze byt aktualny hrac niekto iny?', 1353360969); } $this->actualPlayer['command_response'] = ''; } $this->actualPlayer->save(); $this->game->save(); }
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)); }
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 } } }