public function fire()
{
$client = $this->client;
// Person should be hunter
$player = $this->game->getPlayerById($this->userId);
if (!$player->role || !$player->role->isRole(Role::HUNTER)) {
$this->gameManager->sendMessageToChannel($this->game, ":warning: Invalid !shoot command.");
throw new Exception("Only hunter can shoot.");
}
// Hunter should be dead to shoot
if ($this->game->isPlayerAlive($this->userId)) {
$this->gameManager->sendMessageToChannel($this->game, ":warning: Invalid !shoot command.");
throw new Exception("Can't shoot if alive.");
}
if ($this->args[0] == 'noone') {
$this->game->setHunterNeedsToShoot(false);
$this->gameManager->sendMessageToChannel($this->game, ":bow_and_arrow: " . $player->getUsername() . " (Hunter) decided not to shoot anyone, and died.");
} else {
$targeted_player_id = $this->args[0];
// Person player is shooting should be alive
if (!$this->game->isPlayerAlive($targeted_player_id)) {
$this->gameManager->sendMessageToChannel($this->game, ":warning: Targetted player is not in game or dead.");
throw new Exception("Voted player not found in game.");
}
$targeted_player = $this->game->getPlayerById($targeted_player_id);
$this->game->killPlayer($targeted_player_id);
$this->game->setHunterNeedsToShoot(false);
$this->gameManager->sendMessageToChannel($this->game, ":bow_and_arrow: " . $player->getUsername() . " (Hunter) shot dead " . $targeted_player->getUsername() . " (" . $targeted_player->role->getName() . "), and then died.");
}
if ($this->game->getState() == GameState::DAY) {
$this->gameManager->changeGameState($this->game->getId(), GameState::NIGHT);
} else {
$this->gameManager->changeGameState($this->game->getId(), GameState::DAY);
}
}