isPlayerAlive() public method

Whether or not the player is alive.
public isPlayerAlive ( $playerId ) : boolean
$playerId The Slack user ID.
return boolean TRUE if player is alive and in game, otherwise FALSE.
Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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->isPlayerAlive($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->isPlayerAlive($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);
 }
Ejemplo n.º 4
0
 public function init()
 {
     $client = $this->client;
     if ($this->channel[0] != 'D') {
         throw new Exception("You may only !see from a DM.");
     }
     if (count($this->args) < 2) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Not enough arguments. Usage: !see #channel @user", $dmc);
         });
         throw new InvalidArgumentException();
     }
     $channelId = null;
     $channelName = "";
     if (strpos($this->args[0], '#C') !== false) {
         $channelId = ChannelIdFormatter::format($this->args[0]);
     } else {
         if (strpos($this->args[0], '#') !== false) {
             $channelName = substr($this->args[0], 1);
         } else {
             $channelName = $this->args[0];
         }
     }
     if ($channelId != null) {
         $this->client->getChannelById($channelId)->then(function (ChannelInterface $channel) use(&$channelId) {
             $channelId = $channel->getId();
         }, function (Exception $e) {
             // Do nothing
         });
     }
     if ($channelId == null) {
         $this->client->getGroupByName($channelName)->then(function (ChannelInterface $channel) use(&$channelId) {
             $channelId = $channel->getId();
         }, function (Exception $e) {
             // Do nothing
         });
     }
     if ($channelId == null) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Invalid channel specified. Usage: !see #channel @user", $dmc);
         });
         throw new InvalidArgumentException();
     }
     $this->game = $this->gameManager->getGame($channelId);
     $this->gameId = $channelId;
     if (!$this->game) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Could not find a running game on the specified channel.", $dmc);
         });
         throw new InvalidArgumentException();
     }
     $this->args[1] = UserIdFormatter::format($this->args[1], $this->game->getOriginalPlayers());
     $this->chosenUserId = $this->args[1];
     $player = $this->game->getPlayerById($this->userId);
     if (!$player) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Could not find you in the game you specified.", $dmc);
         });
         throw new InvalidArgumentException();
     }
     // Player should be alive
     if (!$this->game->isPlayerAlive($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 See if dead.");
     }
     if ($player->role != Role::SEER) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: You aren't a seer in the specified game.", $dmc);
         });
         throw new Exception("Player is not the seer but is trying to see.");
     }
     if (!in_array($this->game->getState(), [GameState::FIRST_NIGHT, GameState::NIGHT])) {
         throw new Exception("Can only See at night.");
     }
     if ($this->game->seerSeen()) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: You may only see once each night.", $dmc);
         });
         throw new Exception("You may only see once each night.");
     }
 }
Ejemplo n.º 5
0
 public function init()
 {
     $client = $this->client;
     if ($this->channel[0] != 'D') {
         throw new Exception("Псс, пацан, если хочешь видеть (!see) то пиши в личку.");
     }
     if (count($this->args) < 2) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Ты что-то попутал. Смотри как надо: !see #channel @user", $dmc);
         });
         throw new InvalidArgumentException();
     }
     $channelId = null;
     $channelName = "";
     if (strpos($this->args[0], '#C') !== false) {
         $channelId = ChannelIdFormatter::format($this->args[0]);
     } else {
         if (strpos($this->args[0], '#') !== false) {
             $channelName = substr($this->args[0], 1);
         } else {
             $channelName = $this->args[0];
         }
     }
     if ($channelId != null) {
         $this->client->getChannelById($channelId)->then(function (ChannelInterface $channel) use(&$channelId) {
             $channelId = $channel->getId();
         }, function (Exception $e) {
             // Do nothing
         });
     }
     if ($channelId == null) {
         $this->client->getGroupByName($channelName)->then(function (ChannelInterface $channel) use(&$channelId) {
             $channelId = $channel->getId();
         }, function (Exception $e) {
             // Do nothing
         });
     }
     if ($channelId == null) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Не в тот чат, милок. Смотри как надо: !see #channel @user", $dmc);
         });
         throw new InvalidArgumentException();
     }
     $this->game = $this->gameManager->getGame($channelId);
     $this->gameId = $channelId;
     if (!$this->game) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Что-то пошло не так. Кажется игра не началась.", $dmc);
         });
         throw new InvalidArgumentException();
     }
     $this->args[1] = UserIdFormatter::format($this->args[1], $this->game->getOriginalPlayers());
     $this->chosenUserId = $this->args[1];
     $player = $this->game->getPlayerById($this->userId);
     if (!$player) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Не вижу тебя в списке игроков.", $dmc);
         });
         throw new InvalidArgumentException();
     }
     // Player 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("Кажется тебя уже выпилили, наберись терпения и жди следующей игры.");
     }
     if ($player->role != Role::SEER) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: А справка от окулиста у тебя есть?", $dmc);
         });
         throw new Exception("А справка от окулиста у тебя есть?");
     }
     if (!in_array($this->game->getState(), [GameState::FIRST_NIGHT, GameState::NIGHT])) {
         throw new Exception("Ночь утра мудренее. Дождись заката.");
     }
     if ($this->game->seerSeen()) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Глазки устали, иди поспи.", $dmc);
         });
         throw new Exception("Глазки устали, иди поспи.");
     }
 }
Ejemplo n.º 6
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);
 }
Ejemplo n.º 7
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("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);
 }
Ejemplo n.º 8
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);
 }
Ejemplo n.º 9
0
 public function fire()
 {
     $client = $this->client;
     if ($this->game->getWolvesVoted()) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
             $client->send(":warning: Wolves have already voted.", $channel);
         });
         throw new Exception("Wolves can't vote after voting ends.");
     }
     if ($this->game->getState() != GameState::NIGHT) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $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->isPlayerAlive($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 kill if dead.");
     }
     // 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: 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 (ChannelInterface $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)) {
         //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("Vote change not allowed.");
         }
         $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: 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);
 }
Ejemplo n.º 10
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);
 }
Ejemplo n.º 11
0
 public function init()
 {
     $client = $this->client;
     if ($this->channel[0] != 'D') {
         throw new Exception("Vous pouvez uniquement !see par message privé.");
     }
     if (count($this->args) < 2) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Pas assez d'arguments. Utilisation : !see #channel @joueur", $dmc);
         });
         throw new InvalidArgumentException();
     }
     $channelId = null;
     $channelName = "";
     if (strpos($this->args[0], '#C') !== false) {
         $channelId = ChannelIdFormatter::format($this->args[0]);
     } else {
         if (strpos($this->args[0], '#') !== false) {
             $channelName = substr($this->args[0], 1);
         } else {
             $channelName = $this->args[0];
         }
     }
     if ($channelId != null) {
         $this->client->getChannelById($channelId)->then(function (ChannelInterface $channel) use(&$channelId) {
             $channelId = $channel->getId();
         }, function (Exception $e) {
             // Do nothing
         });
     }
     if ($channelId == null) {
         $this->client->getGroupByName($channelName)->then(function (ChannelInterface $channel) use(&$channelId) {
             $channelId = $channel->getId();
         }, function (Exception $e) {
             // Do nothing
         });
     }
     if ($channelId == null) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Channel invalide. Utilisation : !see #channel @joueur", $dmc);
         });
         throw new InvalidArgumentException();
     }
     $this->game = $this->gameManager->getGame($channelId);
     $this->gameId = $channelId;
     if (!$this->game) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Impossible de trouver une partie en cours sur le channel spécifié", $dmc);
         });
         throw new InvalidArgumentException();
     }
     $this->args[1] = UserIdFormatter::format($this->args[1], $this->game->getOriginalPlayers());
     $this->chosenUserId = $this->args[1];
     $player = $this->game->getPlayerById($this->userId);
     if (!$player) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Vous n'êtes pas dans la partie spécifiée.", $dmc);
         });
         throw new InvalidArgumentException();
     }
     // Player 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 sonder en étant mort.");
     }
     if ($player->role != Role::SEER) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Vous n'êtes pas la Voyante dans la partie spécifiée.", $dmc);
         });
         throw new Exception("Le joueur n'est pas la Voyante mais essaie de sonder.");
     }
     if (!in_array($this->game->getState(), [GameState::FIRST_NIGHT, GameState::NIGHT])) {
         throw new Exception("Can only See at night.");
     }
     if ($this->game->seerSeen()) {
         $this->client->getDMById($this->channel)->then(function (DirectMessageChannel $dmc) use($client) {
             $this->client->send(":warning: Vous ne pouvez sonder un joueur qu'une seule fois par nuit.", $dmc);
         });
         throw new Exception("Vous ne pouvez sonder un joueur qu'une seule fois par nuit.");
     }
 }
Ejemplo n.º 12
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);
 }