Пример #1
0
 public function fire()
 {
     $client = $this->client;
     if (!$this->gameManager->hasGame($this->channel)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Aucun jeu en cours", $channel);
         });
         return;
     }
     // build list of players
     $playersList = PlayerListFormatter::format($this->game->getLivingPlayers());
     $this->gameManager->sendMessageToChannel($this->game, ":ok: Joueurs encore vivants : " . $playersList);
 }
Пример #2
0
 public function fire()
 {
     $client = $this->client;
     if (!$this->gameManager->hasGame($this->channel)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Что-то пошло не так. Кажется игра не началась.", $channel);
         });
         return;
     }
     // build list of players
     $playersList = PlayerListFormatter::format($this->game->getLivingPlayers());
     $this->gameManager->sendMessageToChannel($this->game, ":ok: Стойкие оловянные солдатики: " . $playersList);
 }
Пример #3
0
 public function fire()
 {
     $client = $this->client;
     if (!$this->gameManager->hasGame($this->channel)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: No game in progress.", $channel);
         });
         return;
     }
     // build list of players
     $playersList = PlayerListFormatter::format($this->game->getLivingPlayers());
     $this->gameManager->sendMessageToChannel($this->game, ":ok: Players still alive: " . $playersList);
 }
Пример #4
0
 public function fire()
 {
     $client = $this->client;
     if ($this->game->getState() != GameState::NIGHT) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Vous pouvez uniquement protéger la nuit", $channel);
         });
         throw new Exception("Impossible de protéger en dehors de la nuit");
     }
     // Voter should be alive
     if (!$this->game->isPlayerAlive($this->userId)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Vous n'êtes pas vivant dans la partie spécifiée.", $channel);
         });
         throw new Exception("Impossible de protéger en étant mort.");
     }
     // Person player is voting for should also be alive
     if (!$this->game->isPlayerAlive($this->args[1])) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Ce joueur n'a pas pu être trouvé", $channel);
         });
         throw new Exception("Le joueur demandé n'a pas été trouvé dans la partie.");
     }
     // Person should be werewolf
     $player = $this->game->getPlayerById($this->userId);
     if ($player->role != Role::BODYGUARD) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Vous devez être Salvateur pour pouvoir protéger", $channel);
         });
         throw new Exception("Uniquement le Salvateur peut protéger.");
     }
     if ($this->game->getGuardedUserId() !== null) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Vous avez déjà protégé.", $channel);
         });
         throw new Exception("Vous avez déjà protégé.");
     }
     if ($this->game->getLastGuardedUserId() == $this->args[1]) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Vous ne pouvez pas protéger le même joueur que la nuit dernière.", $channel);
         });
         throw new Exception(":warning: Vous ne pouvez pas protéger le même joueur que la nuit dernière.");
     }
     $this->game->setGuardedUserId($this->args[1]);
     $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
         $client->send("Joueur protégé avec succès", $channel);
     });
     $this->gameManager->changeGameState($this->game->getId(), GameState::DAY);
 }
Пример #5
0
 public function fire()
 {
     $client = $this->client;
     if ($this->game->getState() != GameState::NIGHT) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Ночь утра мудренее. Дождись заката.", $channel);
         });
         throw new Exception("Ночь утра мудренее. Дождись заката.");
     }
     // Voter should be alive
     if (!$this->game->isPlayerAlive($this->userId)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Кажется тебя уже выпилили, наберись терпения и жди следующей игры.", $channel);
         });
         throw new Exception("Кажется тебя уже выпилили, наберись терпения и жди следующей игры.");
     }
     // Person player is voting for should also be alive
     if (!$this->game->isPlayerAlive($this->args[1])) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Не вижу такого чела, а он с какого района?", $channel);
         });
         throw new Exception("Не вижу такого чела, а он с какого района?");
     }
     // Person should be werewolf
     $player = $this->game->getPlayerById($this->userId);
     if ($player->role != Role::BODYGUARD) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: А справка, что ты телохранитель у тебя есть?", $channel);
         });
         throw new Exception("А справка, что ты телохранитель у тебя есть?");
     }
     if ($this->game->getGuardedUserId() !== null) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Палехче, не больше одного за раз, громила.", $channel);
         });
         throw new Exception("Палехче, не больше одного за раз, громила.");
     }
     if ($this->game->getLastGuardedUserId() == $this->args[1]) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Я понимаю, что он твой любимчик, но два раза подряд не прокатит.", $channel);
         });
         throw new Exception("Я понимаю, что он твой любимчик, но два раза подряд не прокатит.");
     }
     $this->game->setGuardedUserId($this->args[1]);
     $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
         $client->send("Все путем.", $channel);
     });
     $this->gameManager->changeGameState($this->game->getId(), GameState::DAY);
 }
Пример #6
0
 public function fire()
 {
     $client = $this->client;
     if ($this->game->getState() != GameState::NIGHT) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: You can only guard at night.", $channel);
         });
         throw new Exception("Guarding occurs only during the night.");
     }
     // Voter should be alive
     if (!$this->game->hasPlayer($this->userId)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: You aren't alive in the specified channel.", $channel);
         });
         throw new Exception("Can't guard if dead.");
     }
     // Person player is voting for should also be alive
     if (!$this->game->hasPlayer($this->args[1])) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Could not find that player.", $channel);
         });
         throw new Exception("Voted player not found in game.");
     }
     // Person should be werewolf
     $player = $this->game->getPlayerById($this->userId);
     if ($player->role != Role::BODYGUARD) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: You have to be a bodyguard to guard.", $channel);
         });
         throw new Exception("Only bodyguard can guard.");
     }
     if ($this->game->getGuardedUserId() !== null) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: You have already guarded.", $channel);
         });
         throw new Exception("You have already guarded.");
     }
     if ($this->game->getLastGuardedUserId() == $this->args[1]) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: You cant guard the same player as last night.", $channel);
         });
         throw new Exception("You cant guard the same player as last night");
     }
     $this->game->setGuardedUserId($this->args[1]);
     $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
         $client->send("Guarding successful.", $channel);
     });
     $this->gameManager->changeGameState($this->game->getId(), GameState::DAY);
 }
Пример #7
0
 protected function setUp()
 {
     parent::setUp();
     $gameId = "G0H6N0ABH";
     $players = array('Bob', 'Alice', 'Fred', 'George', 'Tim', 'Joe', 'Jim', 'Sally', 'Mary');
     //    $bob = new $this->getMockBuilder("\Slack\User");
     //    $this->getMockWithoutInvokingTheOriginalConstructor('\Slack\User');
     //    $optionsManager = new OptionsManager();
     //
     //    echo $optionsManager->getOptionValue("changevote") . "\n";
     //
     //    echo $optionsManager->getOptionValue("role_seer") . "\n";
     $this->strat = new Classic();
     $theGame = new Game($gameId, $players, $this->strat);
     $theGame->assignRoles();
 }
Пример #8
0
 public function fire()
 {
     $client = $this->client;
     if (!$this->gameManager->hasGame($this->channel)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Aucun jeu en cours", $channel);
         });
         return;
     }
     // build list of players
     $playersList = PlayerListFormatter::format($this->game->getDeadPlayers());
     if (empty($playersList)) {
         $this->gameManager->sendMessageToChannel($this->game, "Personne n'est encore mort.");
     } else {
         $this->gameManager->sendMessageToChannel($this->game, ":angel: Joueurs morts: " . $playersList);
     }
 }
Пример #9
0
 public function fire()
 {
     $client = $this->client;
     if (!$this->gameManager->hasGame($this->channel)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Что-то пошло не так. Кажется игра не началась.", $channel);
         });
         return;
     }
     // build list of players
     $playersList = PlayerListFormatter::format($this->game->getDeadPlayers());
     if (empty($playersList)) {
         $this->gameManager->sendMessageToChannel($this->game, "Пока все живы.");
     } else {
         $this->gameManager->sendMessageToChannel($this->game, ":angel: Они ушли в лучший мир: " . $playersList);
     }
 }
Пример #10
0
 public function fire()
 {
     $client = $this->client;
     if (!$this->gameManager->hasGame($this->channel)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: No game in progress.", $channel);
         });
         return;
     }
     // build list of players
     $playersList = PlayerListFormatter::format($this->game->getDeadPlayers());
     if (empty($playersList)) {
         $this->gameManager->sendMessageToChannel($this->game, "No one has died yet.");
     } else {
         $this->gameManager->sendMessageToChannel($this->game, ":angel: Players who have died: " . $playersList);
     }
 }
 public static function format(Game $game)
 {
     $msg = ":memo: Votes des Villageois\r\n--------------------------------------------------------------\r\n";
     foreach ($game->getVotes() as $voteForId => $voters) {
         $voteForPlayer = $game->getPlayerById($voteForId);
         $numVoters = count($voters);
         if ($voteForId == 'noone') {
             $msg .= ":peace_symbol: Pas de lynchage\t\t | ({$numVoters}) | ";
         } else {
             $msg .= ":knife: Tuer @{$voteForPlayer->getUsername()}\t\t | ({$numVoters}) | ";
         }
         $voterNames = [];
         foreach ($voters as $voter) {
             $voter = $game->getPlayerById($voter);
             $voterNames[] = '@' . $voter->getUsername();
         }
         $msg .= implode(', ', $voterNames) . "\r\n";
     }
     $msg .= "\r\n--------------------------------------------------------------\r\n:hourglass: Personnes n'ayant pas encore voté: ";
     $playerNames = [];
     foreach ($game->getLivingPlayers() as $player) {
         if (!$game->hasPlayerVoted($player->getId())) {
             $playerNames[] = '@' . $player->getUsername();
         }
     }
     if (count($playerNames) > 0) {
         $msg .= implode(', ', $playerNames);
     } else {
         $msg .= "Aucune";
     }
     $msg .= "\r\n--------------------------------------------------------------\r\n";
     return $msg;
 }
Пример #12
0
 public static function format(Game $game)
 {
     $msg = ":memo: Самые честные в мире итоги голосования Оборотней\r\n-----------------------------------------\r\n";
     foreach ($game->getVotes() as $voteForId => $voters) {
         $voteForPlayer = $game->getPlayerById($voteForId);
         $numVoters = count($voters);
         $msg .= ":knife: Выпилили @{$voteForPlayer->getUsername()}\t\t | ({$numVoters}) | ";
         $voterNames = [];
         foreach ($voters as $voter) {
             $voter = $game->getPlayerById($voter);
             $voterNames[] = '@' . $voter->getUsername();
         }
         $msg .= implode(', ', $voterNames) . "\r\n";
     }
     $msg .= "\r\n--------------------------------------------------------------\r\n:hourglass: Еще не опускали бюллетень в урну: ";
     $playerNames = [];
     foreach ($game->getPlayersOfRole(Role::WEREWOLF) as $player) {
         if (!$game->hasPlayerVoted($player->getId())) {
             $playerNames[] = '@' . $player->getUsername();
         }
     }
     if (count($playerNames) > 0) {
         $msg .= implode(', ', $playerNames);
     } else {
         $msg .= "Нет никого";
     }
     $msg .= "\r\n--------------------------------------------------------------\r\n";
     return $msg;
 }
Пример #13
0
 public static function format(Game $game)
 {
     $msg = ":memo: Votes des Loups-Garous\r\n-----------------------------------------\r\n";
     foreach ($game->getVotes() as $voteForId => $voters) {
         $voteForPlayer = $game->getPlayerById($voteForId);
         $numVoters = count($voters);
         $msg .= ":knife: Tuer @{$voteForPlayer->getUsername()}\t\t | ({$numVoters}) | ";
         $voterNames = [];
         foreach ($voters as $voter) {
             $voter = $game->getPlayerById($voter);
             $voterNames[] = '@' . $voter->getUsername();
         }
         $msg .= implode(', ', $voterNames) . "\r\n";
     }
     $msg .= "\r\n--------------------------------------------------------------\r\n:hourglass: Votes restants: ";
     $playerNames = [];
     foreach ($game->getPlayersOfRole(Role::WEREWOLF) as $player) {
         if (!$game->hasPlayerVoted($player->getId())) {
             $playerNames[] = '@' . $player->getUsername();
         }
     }
     if (count($playerNames) > 0) {
         $msg .= implode(', ', $playerNames);
     } else {
         $msg .= "Aucun";
     }
     $msg .= "\r\n--------------------------------------------------------------\r\n";
     return $msg;
 }
Пример #14
0
 public static function format(Game $game)
 {
     $msg = ":memo: Вече\r\n--------------------------------------------------------------\r\n";
     foreach ($game->getVotes() as $voteForId => $voters) {
         $voteForPlayer = $game->getPlayerById($voteForId);
         $numVoters = count($voters);
         if ($voteForId == 'noone') {
             $msg .= ":peace_symbol: Пожалуй сегодня обойдемся без расчлененки и сжигания на костре\t\t | ({$numVoters}) | ";
         } else {
             $msg .= ":knife: Сжечь ведьму @{$voteForPlayer->getUsername()}\t\t | ({$numVoters}) | ";
         }
         $voterNames = [];
         foreach ($voters as $voter) {
             $voter = $game->getPlayerById($voter);
             $voterNames[] = '@' . $voter->getUsername();
         }
         $msg .= implode(', ', $voterNames) . "\r\n";
     }
     $msg .= "\r\n--------------------------------------------------------------\r\n:hourglass: Еще не опускали бюллетень в урну: ";
     $playerNames = [];
     foreach ($game->getLivingPlayers() as $player) {
         if (!$game->hasPlayerVoted($player->getId())) {
             $playerNames[] = '@' . $player->getUsername();
         }
     }
     if (count($playerNames) > 0) {
         $msg .= implode(', ', $playerNames);
     } else {
         $msg .= "Нет никого";
     }
     $msg .= "\r\n--------------------------------------------------------------\r\n";
     return $msg;
 }
Пример #15
0
 public static function format(Game $game)
 {
     $msg = ":memo: Werewolf Kill Vote\r\n-----------------------------------------\r\n";
     foreach ($game->getVotes() as $voteForId => $voters) {
         $voteForPlayer = $game->getPlayerById($voteForId);
         $numVoters = count($voters);
         $msg .= ":knife: Kill @{$voteForPlayer->getUsername()}\t\t | ({$numVoters}) | ";
         $voterNames = [];
         foreach ($voters as $voter) {
             $voter = $game->getPlayerById($voter);
             $voterNames[] = '@' . $voter->getUsername();
         }
         $msg .= implode(', ', $voterNames) . "\r\n";
     }
     $msg .= "\r\n--------------------------------------------------------------\r\n:hourglass: Remaining Voters: ";
     $playerNames = [];
     foreach ($game->getPlayersOfRole(Role::WEREWOLF) as $player) {
         if (!$game->hasPlayerVoted($player->getId())) {
             $playerNames[] = '@' . $player->getUsername();
         }
     }
     if (count($playerNames) > 0) {
         $msg .= implode(', ', $playerNames);
     } else {
         $msg .= "None";
     }
     $msg .= "\r\n--------------------------------------------------------------\r\n";
     return $msg;
 }
Пример #16
0
 public static function format(Game $game)
 {
     $msg = ":memo: Town Ballot\r\n--------------------------------------------------------------\r\n";
     foreach ($game->getVotes() as $voteForId => $voters) {
         $voteForPlayer = $game->getPlayerById($voteForId);
         $numVoters = count($voters);
         if ($voteForId == 'noone') {
             $msg .= ":peace_symbol: No lynch\t\t | ({$numVoters}) | ";
         } else {
             $msg .= ":knife: Kill @{$voteForPlayer->getUsername()}\t\t | ({$numVoters}) | ";
         }
         $voterNames = [];
         foreach ($voters as $voter) {
             $voter = $game->getPlayerById($voter);
             $voterNames[] = '@' . $voter->getUsername();
         }
         $msg .= implode(', ', $voterNames) . "\r\n";
     }
     $msg .= "\r\n--------------------------------------------------------------\r\n:hourglass: Remaining Voters: ";
     $playerNames = [];
     foreach ($game->getLivingPlayers() as $player) {
         if (!$game->hasPlayerVoted($player->getId())) {
             $playerNames[] = '@' . $player->getUsername();
         }
     }
     if (count($playerNames) > 0) {
         $msg .= implode(', ', $playerNames);
     } else {
         $msg .= "None";
     }
     $msg .= "\r\n--------------------------------------------------------------\r\n";
     return $msg;
 }
Пример #17
0
 public function fire()
 {
     $client = $this->client;
     foreach ($this->game->getLivingPlayers() as $player) {
         if (!strstr($this->chosenUserId, $player->getId())) {
             continue;
         }
         if ($player->role == Role::WEREWOLF || $player->role == Role::LYCAN) {
             $msg = "@{$player->getUsername()} is on the side of the Werewolves.";
         } else {
             $msg = "@{$player->getUsername()} is on the side of the Villagers.";
         }
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client, $msg) {
             $this->client->send($msg, $dmc);
         });
         $this->game->setSeerSeen(true);
         $this->gameManager->changeGameState($this->game->getId(), GameState::DAY);
         return;
     }
     $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
         $this->client->send("Could not find the user you asked for.", $dmc);
     });
 }
Пример #18
0
 public function fire()
 {
     $client = $this->client;
     foreach ($this->game->getLivingPlayers() as $player) {
         if (!strstr($this->chosenUserId, $player->getId())) {
             continue;
         }
         if ($player->role == Role::WEREWOLF || $player->role == Role::LYCAN) {
             $msg = "@{$player->getUsername()} est dans le camp des Loups-Garous.";
         } else {
             $msg = "@{$player->getUsername()} est dans le camp des Villageois.";
         }
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client, $msg) {
             $this->client->send($msg, $dmc);
         });
         $this->game->setSeerSeen(true);
         $this->gameManager->changeGameState($this->game->getId(), GameState::DAY);
         return;
     }
     $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
         $this->client->send("Impossible de trouver le joueur que vous avez demandé.", $dmc);
     });
 }
Пример #19
0
 public function fire()
 {
     $client = $this->client;
     foreach ($this->game->getLivingPlayers() as $player) {
         if (!strstr($this->chosenUserId, $player->getId())) {
             continue;
         }
         if ($player->role == Role::WEREWOLF || $player->role == Role::LYCAN) {
             $msg = "@{$player->getUsername()} на стороне Оборотней.";
         } else {
             $msg = "@{$player->getUsername()} на стороне Крестьян.";
         }
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client, $msg) {
             $this->client->send($msg, $dmc);
         });
         $this->game->setSeerSeen(true);
         $this->gameManager->changeGameState($this->game->getId(), GameState::DAY);
         return;
     }
     $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
         $this->client->send("Не вижу такого чела, а он с какого района?", $dmc);
     });
 }
Пример #20
0
 public function fire()
 {
     $client = $this->client;
     if ($this->game->getWolvesVoted()) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Les Loups-Garous ont déjà voté.", $channel);
         });
         throw new Exception("Les Loups-Garous ne peuvent pas voter après la fin du vote.");
     }
     if ($this->game->getState() != GameState::NIGHT) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Vous pouvez tuer uniquement pendant la nuit.", $channel);
         });
         throw new Exception("Impossible de tuer en dehors de la nuit.");
     }
     // Voter should be alive
     if (!$this->game->isPlayerAlive($this->userId)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Vous n'êtes pas vivant dans le channel spécifié.", $channel);
         });
         throw new Exception("Impossible de tuer en étant mort.");
     }
     // Person player is voting for should also be alive
     if (!$this->game->isPlayerAlive($this->args[1])) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Impossible de trouver ce joueur.", $channel);
         });
         throw new Exception("Joueur voté pas dans la partie.");
     }
     // Person should be werewolf
     $player = $this->game->getPlayerById($this->userId);
     if ($player->role != Role::WEREWOLF) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Vous devez être un Loup-Garou pour tuer.", $channel);
         });
         throw new Exception("Seulement les Loups-Garous peuvent tuer");
     }
     if ($this->game->hasPlayerVoted($this->userId)) {
         //If changeVote is not enabled and player has already voted, do not allow another vote
         if (!$this->gameManager->optionsManager->getOptionValue(OptionName::changevote)) {
             throw new Exception("Changement de vote non autorisé.");
         }
         $this->game->clearPlayerVote($this->userId);
     }
     $this->game->vote($this->userId, $this->args[1]);
     $msg = KillFormatter::format($this->game);
     foreach ($this->game->getPlayersOfRole(Role::WEREWOLF) as $player) {
         $client->getDMByUserID($player->getId())->then(function (DirectMessageChannel $channel) use($client, $msg) {
             $client->send($msg, $channel);
         });
     }
     foreach ($this->game->getPlayersOfRole(Role::WEREWOLF) as $player) {
         if (!$this->game->hasPlayerVoted($player->getId())) {
             return;
         }
     }
     $votes = $this->game->getVotes();
     if (count($votes) > 1) {
         $this->game->clearVotes();
         foreach ($this->game->getPlayersOfRole(Role::WEREWOLF) as $player) {
             $client->getDMByUserID($player->getId())->then(function (DirectMessageChannel $channel) use($client) {
                 $client->send(":warning: Les Loups-Garous n'ont pas voté à l'unanimité sur un Villageois. Merci de voter à nouveau.", $channel);
             });
         }
         return;
     }
     $this->game->setWolvesVoted(true);
     $this->gameManager->changeGameState($this->game->getId(), GameState::DAY);
 }
Пример #21
0
 public function fire()
 {
     $client = $this->client;
     if ($this->game->getWolvesVoted()) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Волки уже свое отвыли.", $channel);
         });
         throw new Exception("Волки уже свое отвыли.");
     }
     if ($this->game->getState() != GameState::NIGHT) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Ночь утра мудренее. Дождись заката.", $channel);
         });
         throw new Exception("Ночь утра мудренее. Дождись заката.");
     }
     // Voter should be alive
     if (!$this->game->isPlayerAlive($this->userId)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Кажется тебя уже выпилили, наберись терпения и жди следующей игры.", $channel);
         });
         throw new Exception("Кажется тебя уже выпилили, наберись терпения и жди следующей игры.");
     }
     // Person player is voting for should also be alive
     if (!$this->game->isPlayerAlive($this->args[1])) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Не вижу такого чела, а он с какого района?", $channel);
         });
         throw new Exception("Не вижу такого чела, а он с какого района?");
     }
     // Person should be werewolf
     $player = $this->game->getPlayerById($this->userId);
     if ($player->role != Role::WEREWOLF) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: А справка, что ты оборотень у тебя есть?", $channel);
         });
         throw new Exception("А справка, что ты оборотень у тебя есть?");
     }
     if ($this->game->hasPlayerVoted($this->userId)) {
         //If changeVote is not enabled and player has already voted, do not allow another vote
         if (!$this->gameManager->optionsManager->getOptionValue(OptionName::changevote)) {
             throw new Exception("Ой, все! Нельзя быть таким непостоянным.");
         }
         $this->game->clearPlayerVote($this->userId);
     }
     $this->game->vote($this->userId, $this->args[1]);
     $msg = KillFormatter::format($this->game);
     foreach ($this->game->getPlayersOfRole(Role::WEREWOLF) as $player) {
         $client->getDMByUserID($player->getId())->then(function (DirectMessageChannel $channel) use($client, $msg) {
             $client->send($msg, $channel);
         });
     }
     foreach ($this->game->getPlayersOfRole(Role::WEREWOLF) as $player) {
         if (!$this->game->hasPlayerVoted($player->getId())) {
             return;
         }
     }
     $votes = $this->game->getVotes();
     if (count($votes) > 1) {
         $this->game->clearVotes();
         foreach ($this->game->getPlayersOfRole(Role::WEREWOLF) as $player) {
             $client->getDMByUserID($player->getId())->then(function (DirectMessageChannel $channel) use($client) {
                 $client->send(":warning: Никого не убили. Вы уж там между собой разберитесь и проголосуйте снова.", $channel);
             });
         }
         return;
     }
     $this->game->setWolvesVoted(true);
     $this->gameManager->changeGameState($this->game->getId(), GameState::DAY);
 }
Пример #22
0
 public function fire()
 {
     $client = $this->client;
     if ($this->game->getState() != GameState::NIGHT) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (Channel $channel) use($client) {
             $client->send(":warning: You can only kill at night.", $channel);
         });
         throw new Exception("Killing occurs only during the night.");
     }
     // Voter should be alive
     if (!$this->game->hasPlayer($this->userId)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (Channel $channel) use($client) {
             $client->send(":warning: You aren't alive in the specified channel.", $channel);
         });
         throw new Exception("Can't kill if dead.");
     }
     // Person player is voting for should also be alive
     if (!$this->game->hasPlayer($this->args[0])) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (Channel $channel) use($client) {
             $client->send(":warning: Could not find that player.", $channel);
         });
         throw new Exception("Voted player not found in game.");
     }
     // Person should be werewolf
     $player = $this->game->getPlayerById($this->userId);
     if ($player->role != Role::WEREWOLF) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (Channel $channel) use($client) {
             $client->send(":warning: YOu have to be a werewolf to kill.", $channel);
         });
         throw new Exception("Only werewolves can kill.");
     }
     if ($this->game->hasPlayerVoted($this->userId)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (Channel $channel) use($client) {
             $client->send(":warning: You have already voted.", $channel);
         });
         throw new Exception("You have already voted.");
     }
     $this->game->vote($this->userId, $this->args[1]);
     $msg = KillFormatter::format($this->game);
     foreach ($this->game->getPlayersOfRole(Role::WEREWOLF) as $player) {
         $client->getDMByUserID($player->getId())->then(function (DirectMessageChannel $channel) use($client, $msg) {
             $client->send($msg, $channel);
         });
     }
     foreach ($this->game->getPlayersOfRole(Role::WEREWOLF) as $player) {
         if (!$this->game->hasPlayerVoted($player->getId())) {
             return;
         }
     }
     $votes = $this->game->getVotes();
     if (count($votes) > 1) {
         $this->game->clearVotes();
         foreach ($this->game->getPlayersOfRole(Role::WEREWOLF) as $player) {
             $client->getDMByUserID($player->getId())->then(function (DirectMessageChannel $channel) use($client) {
                 $client->send(":warning: The werewolves did not unanimously vote on a member of the town. Vote again.", $channel);
             });
         }
         return;
     }
     $this->game->setWolvesVoted(true);
     $this->gameManager->changeGameState($this->game->getId(), GameState::DAY);
 }
Пример #23
0
 private function onGameOver(Game $game)
 {
     $game->changeState(GameState::OVER);
     $this->endGame($game->getId());
 }