Slackwolf\Game\Command\VoteCommand::__construct PHP Method

__construct() public method

Constructs a new Vote command.
public __construct ( RealTimeClient $client, GameManager $gameManager, Message $message, array $args = null )
$client Slack\RealTimeClient
$gameManager Slackwolf\Game\GameManager
$message Slackwolf\Message\Message
$args array
    public function __construct(RealTimeClient $client, GameManager $gameManager, Message $message, array $args = null)
    {
        parent::__construct($client, $gameManager, $message, $args);
        if ($this->channel[0] == 'D') {
            throw new Exception("You may not !vote privately.");
        }
        if (count($this->args) < 1) {
            throw new InvalidArgumentException("Must specify a player");
        }
        if (!$this->game) {
            throw new Exception("No game in progress.");
        }
        if ($this->game->getState() != GameState::DAY) {
            throw new Exception("Voting occurs only during the day.");
        }
        // Voter should be alive
        if (!$this->game->isPlayerAlive($this->userId)) {
            throw new Exception("Can't vote if dead.");
        }
        $this->args[0] = UserIdFormatter::format($this->args[0], $this->game->getOriginalPlayers());
        // Person player is voting for should also be alive
        if (!$this->game->isPlayerAlive($this->args[0]) && $this->args[0] != 'noone' && $this->args[0] != 'clear') {
            echo 'not found';
            throw new Exception("Voted player not found in game.");
        }
    }