Slackwolf\Game\Formatter\KillFormatter::format PHP Method

format() public static method

public static format ( Game $game ) : string
$game Slackwolf\Game\Game
return string
    public static function format(Game $game)
    {
        $msg = ":memo: Werewolf Kill Vote\r\n- - - - - - - - - - - - - - - - - - - - - - - -\r\n";
        foreach ($game->getVotes() as $voteForId => $voters) {
            $voteForPlayer = $game->getPlayerById($voteForId);
            $numVoters = count($voters);
            $msg .= ":knife: Kill @{$voteForPlayer->getUsername()}\t\t | ({$numVoters}) | ";
            $voterNames = [];
            foreach ($voters as $voter) {
                $voter = $game->getPlayerById($voter);
                $voterNames[] = '@' . $voter->getUsername();
            }
            $msg .= implode(', ', $voterNames) . "\r\n";
        }
        $msg .= "\r\n- - - - - - - - - - - - - - - - - - - - - - - -\r\n:hourglass: Remaining Voters: ";
        $playerNames = [];
        foreach ($game->getWerewolves() as $player) {
            if (!$game->hasPlayerVoted($player->getId())) {
                $playerNames[] = '@' . $player->getUsername();
            }
        }
        if (count($playerNames) > 0) {
            $msg .= implode(', ', $playerNames);
        } else {
            $msg .= "None";
        }
        $msg .= "\r\n- - - - - - - - - - - - - - - - - - - - - - - -\r\n";
        return $msg;
    }

Usage Example

コード例 #1
0
ファイル: KillCommand.php プロジェクト: b-lawrence/slackwolf
 public function fire()
 {
     $client = $this->client;
     if ($this->game->getState() != GameState::NIGHT) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (Channel $channel) use($client) {
             $client->send(":warning: You can only kill at night.", $channel);
         });
         throw new Exception("Killing occurs only during the night.");
     }
     // Voter should be alive
     if (!$this->game->hasPlayer($this->userId)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (Channel $channel) use($client) {
             $client->send(":warning: You aren't alive in the specified channel.", $channel);
         });
         throw new Exception("Can't kill if dead.");
     }
     // Person player is voting for should also be alive
     if (!$this->game->hasPlayer($this->args[0])) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (Channel $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::WEREWOLF) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (Channel $channel) use($client) {
             $client->send(":warning: YOu have to be a werewolf to kill.", $channel);
         });
         throw new Exception("Only werewolves can kill.");
     }
     if ($this->game->hasPlayerVoted($this->userId)) {
         $client->getChannelGroupOrDMByID($this->channel)->then(function (Channel $channel) use($client) {
             $client->send(":warning: You have already voted.", $channel);
         });
         throw new Exception("You have already voted.");
     }
     $this->game->vote($this->userId, $this->args[1]);
     $msg = KillFormatter::format($this->game);
     foreach ($this->game->getPlayersOfRole(Role::WEREWOLF) as $player) {
         $client->getDMByUserID($player->getId())->then(function (DirectMessageChannel $channel) use($client, $msg) {
             $client->send($msg, $channel);
         });
     }
     foreach ($this->game->getPlayersOfRole(Role::WEREWOLF) as $player) {
         if (!$this->game->hasPlayerVoted($player->getId())) {
             return;
         }
     }
     $votes = $this->game->getVotes();
     if (count($votes) > 1) {
         $this->game->clearVotes();
         foreach ($this->game->getPlayersOfRole(Role::WEREWOLF) as $player) {
             $client->getDMByUserID($player->getId())->then(function (DirectMessageChannel $channel) use($client) {
                 $client->send(":warning: The werewolves did not unanimously vote on a member of the town. Vote again.", $channel);
             });
         }
         return;
     }
     $this->game->setWolvesVoted(true);
     $this->gameManager->changeGameState($this->game->getId(), GameState::DAY);
 }
All Usage Examples Of Slackwolf\Game\Formatter\KillFormatter::format
KillFormatter