Skip to content

Commit

Permalink
added Tanner
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Gillis committed Dec 23, 2015
1 parent 7213309 commit 76ba33b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
37 changes: 33 additions & 4 deletions src/Game/Game.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ public function getPlayersOfRole($roleType)
return $werewolves;
}

/**
* @return \Slack\User[]
*/
public function getOriginalPlayersOfRole($roleType)
{
$werewolves = [];

foreach ($this->originalPlayers as $player) {
if ($player->role == $roleType) {
$werewolves[] = $player;
}
}

return $werewolves;
}

public function hasPlayer($playerId) {
return isset($this->players[$playerId]);
}
Expand All @@ -99,6 +115,14 @@ public function getNumRole($roleType)
return count($this->getPlayersOfRole($roleType));
}

/**
* @return int
*/
public function getOriginalNumRole($roleType)
{
return count($this->getOriginalPlayersOfRole($roleType));
}

public function getState()
{
return $this->state;
Expand Down Expand Up @@ -151,12 +175,17 @@ public function clearVotes()

public function isOver()
{
$numSeers = $this->getNumRole(Role::SEER);
$numVillagers = $this->getNumRole(Role::VILLAGER);
$numBodyguard = $this->getNumRole(Role::BODYGUARD);
$numWerewolves = $this->getNumRole(Role::WEREWOLF);
$numTanner = $this->getNumRole(Role::TANNER);

$numGood = count($this->getPlayers()) - $numWerewolves;

$numGood = $numVillagers + $numSeers + $numBodyguard;
if ($numTanner == 0) {
if ($this->getOriginalNumRole(Role::TANNER) > 0) {
$this->winningTeam = Role::TANNER;
return true;
}
}

if ($numWerewolves == 0) {
$this->winningTeam = Role::VILLAGER;
Expand Down
11 changes: 7 additions & 4 deletions src/Game/GameManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,18 @@ public function endGame($id, $enderUserId = null)
if($winningTeam !== null) {
$winMsg = ":clipboard: Role Summary\r\n--------------------------------------------------------------\r\n{$playerList}\r\n\r\n:tada: The game is over. The ";
if ($winningTeam == Role::VILLAGER) {
$winMsg .= "Townsfolk ";
$winMsg .= "Townsfolk are victorious!";
}
elseif ($winningTeam == Role::WEREWOLF) {
$winMsg .= "Werewolves ";
$winMsg .= "Werewolves are victorious!";
}
elseif ($winningTeam == Role::TANNER) {
$winMsg .= "Tanner is victorious!";
}
else {
$winMsg .= "UnknownTeam ";
$winMsg .= "UnknownTeam is victorious!";
}
$winMsg .= "are victorious!";

$client->getChannelGroupOrDMByID($id)
->then(function (ChannelInterface $channel) use ($client, $playerList, $winMsg) {
$client->send($winMsg, $channel);
Expand Down
1 change: 1 addition & 0 deletions src/Game/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ class Role
const SEER = "Seer";
const WEREWOLF = "Werewolf";
const BODYGUARD = "Bodyguard";
const TANNER = "Tanner";
}
4 changes: 4 additions & 0 deletions src/Game/RoleStrategy/Classic.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public function assign(array $players)
$roles[Role::BODYGUARD] = 1;
}

if ($num_players >= 6) {
$roles[Role::TANNER] = 1;
}

$roles += [
Role::VILLAGER => max($num_good - count($roles), 0),
Role::WEREWOLF => $num_evil
Expand Down

0 comments on commit 76ba33b

Please sign in to comment.