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);
}