/**
  * @param Game $game
  *
  * @return string
  */
 public static function format(Game $game)
 {
     $msg = ":memo: Game Status\r\n- - - - - - - - - - - - - - - - - - - - - - - -\r\n";
     if ($game->hunterNeedsToShoot) {
         $msg .= "_...waiting on the_ :bow_and_arrow: Hunter";
         $msg .= "\r\n- - - - - - - - - - - - - - - - - - - - - - - -\r\n";
         return $msg;
     }
     switch ($game->state) {
         case GameState::DAY:
             $voteMsg = VoteSummaryFormatter::format($game);
             $msg .= ":sun_small_cloud:  It is now Day.  Please vote!\r\n";
             $msg .= $voteMsg . "\r\n";
             break;
         case GameState::FIRST_NIGHT:
         case GameState::NIGHT:
             $msg .= ":moon:  The night lingers on ... \r\n \r\n";
             $numSeer = $game->getNumRole(Role::SEER);
             $numBodyguard = $game->getNumRole(Role::BODYGUARD);
             $numWitch = $game->getNumRole(Role::WITCH);
             if ($numSeer > 0 && !$game->seerSeen) {
                 $msg .= "_...waiting on the_ :crystal_ball: *Seer*\r\n";
             }
             if ($game->state == GameState::NIGHT) {
                 if (!$game->wolvesVoted) {
                     $msg .= "_...waiting on the_ :wolf:  *Wolves*\r\n";
                 }
                 if ($numWitch > 0 && (!$game->witchPoisoned || !$game->witchHealed)) {
                     $msg .= "_...waiting on the_ :older_woman::skin-tone-3: *Witch*\r\n";
                 }
                 if ($numBodyguard > 0 && !$game->getGuardedUserId()) {
                     $msg .= "_...waiting on the_ :shield: *Bodyguard*\r\n";
                 }
             }
             break;
         default:
             $msg .= "No Game Running\n";
     }
     return $msg;
 }
Exemple #2
0
 public function vote(Game $game, $voterId, $voteForId)
 {
     if (!$game->hasPlayer($voterId)) {
         return;
     }
     if (!$game->hasPlayer($voteForId)) {
         return;
     }
     if ($game->hasPlayerVoted($voterId)) {
         return;
     }
     $game->vote($voterId, $voteForId);
     $voteMsg = VoteSummaryFormatter::format($game);
     $client = $this->client;
     $client->getChannelGroupOrDMByID($game->getId())->then(function (Channel $channel) use($client, $voteMsg) {
         $client->send($voteMsg, $channel);
     });
     if (!$game->votingFinished()) {
         return;
     }
     $votes = $game->getVotes();
     $vote_count = [];
     foreach ($votes as $lynch_player_id => $voters) {
         if (!isset($vote_count[$lynch_player_id])) {
             $vote_count[$lynch_player_id] = 0;
         }
         $vote_count[$lynch_player_id] += count($voters);
     }
     $players_to_be_lynched = [];
     $max = 0;
     foreach ($vote_count as $lynch_player_id => $num_votes) {
         if ($num_votes > $max) {
             $max = $num_votes;
         }
     }
     foreach ($vote_count as $lynch_player_id => $num_votes) {
         if ($num_votes == $max) {
             $players_to_be_lynched[] = $lynch_player_id;
         }
     }
     $lynchMsg = "\r\n:newspaper: With pitchforks in hand, the townsfolk killed: ";
     $lynchedNames = [];
     foreach ($players_to_be_lynched as $player_id) {
         $player = $game->getPlayerById($player_id);
         $lynchedNames[] = "@{$player->getUsername()} ({$player->role})";
         $game->removePlayer($player_id);
     }
     $lynchMsg .= implode(', ', $lynchedNames) . "\r\n";
     $client->getChannelGroupOrDMByID($game->getId())->then(function (Channel $channel) use($client, $lynchMsg) {
         $client->send($lynchMsg, $channel);
     });
     $this->changeGameState($game->getId(), GameState::NIGHT);
 }
 public function vote(Game $game, $voterId, $voteForId)
 {
     if (!$game->isPlayerAlive($voterId)) {
         return;
     }
     if (!$game->isPlayerAlive($voteForId) && ($voteForId != 'noone' || !$this->optionsManager->getOptionValue(OptionName::no_lynch)) && $voteForId != 'clear') {
         return;
     }
     if ($game->hasPlayerVoted($voterId)) {
         //If changeVote is not enabled and player has already voted, do not allow another vote
         if (!$this->optionsManager->getOptionValue(OptionName::changevote)) {
             throw new Exception("Le changement de vote n'est pas autorisé.");
         }
         $game->clearPlayerVote($voterId);
     }
     if ($voteForId != 'clear') {
         //if voting for 'clear' just clear vote
         $game->vote($voterId, $voteForId);
     }
     $voteMsg = VoteSummaryFormatter::format($game);
     $this->sendMessageToChannel($game, $voteMsg);
     if (!$game->votingFinished()) {
         return;
     }
     $votes = $game->getVotes();
     $vote_count = [];
     foreach ($votes as $lynch_player_id => $voters) {
         if (!isset($vote_count[$lynch_player_id])) {
             $vote_count[$lynch_player_id] = 0;
         }
         $vote_count[$lynch_player_id] += count($voters);
     }
     $players_to_be_lynched = [];
     $max = 0;
     foreach ($vote_count as $lynch_player_id => $num_votes) {
         if ($num_votes > $max) {
             $max = $num_votes;
         }
     }
     foreach ($vote_count as $lynch_player_id => $num_votes) {
         if ($num_votes == $max && $lynch_player_id != 'noone') {
             $players_to_be_lynched[] = $lynch_player_id;
         }
     }
     $lynchMsg = "\r\n";
     if (count($players_to_be_lynched) == 0) {
         $lynchMsg .= ":peace_symbol: Les Villageois ont choisi de ne tuer personne aujourd'hui.";
     } else {
         $lynchMsg .= ":newspaper: Avec leurs fourches, les Villageois ont tué : ";
         $lynchedNames = [];
         foreach ($players_to_be_lynched as $player_id) {
             $player = $game->getPlayerById($player_id);
             $lynchedNames[] = "@{$player->getUsername()} ({$player->role})";
             $game->killPlayer($player_id);
         }
         $lynchMsg .= implode(', ', $lynchedNames) . "\r\n";
     }
     $this->sendMessageToChannel($game, $lynchMsg);
     $this->changeGameState($game->getId(), GameState::NIGHT);
 }
Exemple #4
0
 public function vote(Game $game, $voterId, $voteForId)
 {
     if (!$game->isPlayerAlive($voterId)) {
         return;
     }
     if (!$game->isPlayerAlive($voteForId) && ($voteForId != 'noone' || !$this->optionsManager->getOptionValue(OptionName::no_lynch)) && $voteForId != 'clear') {
         return;
     }
     if ($game->hasPlayerVoted($voterId)) {
         //If changeVote is not enabled and player has already voted, do not allow another vote
         if (!$this->optionsManager->getOptionValue(OptionName::changevote)) {
             throw new Exception("Vote change not allowed.");
         }
         $game->clearPlayerVote($voterId);
     }
     if ($voteForId != 'clear') {
         //if voting for 'clear' just clear vote
         $game->vote($voterId, $voteForId);
     }
     $voteMsg = VoteSummaryFormatter::format($game);
     $this->sendMessageToChannel($game, $voteMsg);
     if (!$game->votingFinished()) {
         return;
     }
     $votes = $game->getVotes();
     $vote_count = [];
     foreach ($votes as $lynch_player_id => $voters) {
         if (!isset($vote_count[$lynch_player_id])) {
             $vote_count[$lynch_player_id] = 0;
         }
         $vote_count[$lynch_player_id] += count($voters);
     }
     $players_to_be_lynched = [];
     $max = 0;
     foreach ($vote_count as $lynch_player_id => $num_votes) {
         if ($num_votes > $max) {
             $max = $num_votes;
         }
     }
     foreach ($vote_count as $lynch_player_id => $num_votes) {
         if ($num_votes == $max && $lynch_player_id != 'noone') {
             $players_to_be_lynched[] = $lynch_player_id;
         }
     }
     $lynchMsg = "\r\n";
     if (count($players_to_be_lynched) == 0) {
         $lynchMsg .= ":peace_symbol: The townsfolk decided not to lynch anybody today.";
     } else {
         $lynchMsg .= ":newspaper: With pitchforks in hand, the townsfolk killed: ";
         $lynchedNames = [];
         foreach ($players_to_be_lynched as $player_id) {
             $player = $game->getPlayerById($player_id);
             $lynchedNames[] = "@{$player->getUsername()} ({$player->role})";
             $game->killPlayer($player_id);
         }
         $lynchMsg .= implode(', ', $lynchedNames) . "\r\n";
     }
     $this->sendMessageToChannel($game, $lynchMsg);
     $this->changeGameState($game->getId(), GameState::NIGHT);
 }
Exemple #5
0
 public function vote(Game $game, $voterId, $voteForId)
 {
     if (!$game->isPlayerAlive($voterId)) {
         return;
     }
     if (!$game->isPlayerAlive($voteForId) && ($voteForId != 'noone' || !$this->optionsManager->getOptionValue(OptionName::no_lynch)) && $voteForId != 'clear') {
         return;
     }
     if ($game->hasPlayerVoted($voterId)) {
         //If changeVote is not enabled and player has already voted, do not allow another vote
         if (!$this->optionsManager->getOptionValue(OptionName::changevote)) {
             throw new Exception("Ой, все! Нельзя быть таким непостоянным.");
         }
         $game->clearPlayerVote($voterId);
     }
     if ($voteForId != 'clear') {
         //if voting for 'clear' just clear vote
         $game->vote($voterId, $voteForId);
     }
     $voteMsg = VoteSummaryFormatter::format($game);
     $this->sendMessageToChannel($game, $voteMsg);
     if (!$game->votingFinished()) {
         return;
     }
     $votes = $game->getVotes();
     $vote_count = [];
     foreach ($votes as $lynch_player_id => $voters) {
         if (!isset($vote_count[$lynch_player_id])) {
             $vote_count[$lynch_player_id] = 0;
         }
         $vote_count[$lynch_player_id] += count($voters);
     }
     $players_to_be_lynched = [];
     $max = 0;
     foreach ($vote_count as $lynch_player_id => $num_votes) {
         if ($num_votes > $max) {
             $max = $num_votes;
         }
     }
     foreach ($vote_count as $lynch_player_id => $num_votes) {
         if ($num_votes == $max && $lynch_player_id != 'noone') {
             $players_to_be_lynched[] = $lynch_player_id;
         }
     }
     $lynchMsg = "\r\n";
     if (count($players_to_be_lynched) == 0) {
         $lynchMsg .= ":peace_symbol: На вече решили никого не убивать.";
     } else {
         $lynchMsg .= ":newspaper: Сегодня на вилы посадили: ";
         $lynchedNames = [];
         foreach ($players_to_be_lynched as $player_id) {
             $player = $game->getPlayerById($player_id);
             $lynchedNames[] = "@{$player->getUsername()} ({$player->role})";
             $game->killPlayer($player_id);
         }
         $lynchMsg .= implode(', ', $lynchedNames) . "\r\n";
     }
     $this->sendMessageToChannel($game, $lynchMsg);
     $this->changeGameState($game->getId(), GameState::NIGHT);
 }