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 poison at night.", $channel);
});
throw new Exception("Poison occurs only during the night.");
}
// Person should be witch
$player = $this->game->getPlayerById($this->userId);
if (!$player->role->isRole(Role::WITCH)) {
$client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
$client->send(":warning: You have to be a witch to poison.", $channel);
});
throw new Exception("Only witch can poison.");
}
// 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 poison if dead.");
}
// Witch should have poison potion
if ($this->game->getWitchPoisonPotion() <= 0) {
$client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
$client->send(":warning: You have used your poison potion.", $channel);
});
throw new Exception("Witch poison potion is 0.");
}
if ($this->args[1] == 'noone') {
$this->game->setWitchPoisoned(true);
$client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
$client->send(":wine_glass: You have chosen not to poison anyone tonight.", $channel);
});
$this->gameManager->changeGameState($this->game->getId(), GameState::DAY);
return true;
}
// 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.");
}
$this->game->setWitchPoisonPotion(0);
$this->game->setWitchPoisonedUserId($this->args[1]);
$this->game->setWitchPoisoned(true);
$client->getChannelGroupOrDMByID($this->channel)->then(function (ChannelInterface $channel) use($client) {
$client->send("Poisoning successful.", $channel);
});
$this->gameManager->changeGameState($this->game->getId(), GameState::DAY);
}