Slackwolf\Game\Game::setGuardedUserId PHP Method

setGuardedUserId() public method

public setGuardedUserId ( $id )
$id
    public function setGuardedUserId($id)
    {
        $this->guardedUserId = $id;
    }

Usage Example

Example #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: You can only guard at night.", $channel);
         });
         throw new Exception("Guarding occurs only during the night.");
     }
     // Voter should be alive
     if (!$this->game->hasPlayer($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->hasPlayer($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);
 }
All Usage Examples Of Slackwolf\Game\Game::setGuardedUserId