3
list ($command, $user_id, $vote) = $irc_call_args;
5
if ($command !== false && is_null($command))
7
$command = strtolower($command);
10
$channel = irc_lower($to);
12
if (!isset ($this->custom_vars->yandere_games[$channel]))
14
output($to, $from.': There\'s no game here.');
18
$game = $this->custom_vars->yandere_games[$channel];
20
if (!isset ($game->players[$user_id]))
22
output($to, $from.': You aren\'t in this game.');
28
output($to, $from.': The game hasn\'t started yet.');
32
if ($game->turn % 2 == 1)
34
// Trying to write a command to the channel during the night. Not allowed.
36
output($to, $game->s.'Commands in the channel are ignored during the night. Please PM them to me instead. This message does not imply that '.$game->players[$user_id]->nick.' has any special ability.'.$game->e);
40
if ($vote === false || is_null($vote))
53
notice($to, $game->s.'That action isn\'t allowed during the day.'.$game->e);
57
$vote_id = call('yandere/get-user-id', $vote);
59
if (!isset ($game->players[$vote_id]))
61
output($to, $from.': '.$vote.' isn\'t in this game.');
66
if ($vote_id == $user_id)
68
output($to, $game->s.'You can\'t vote for yourself.'.$game->e);
72
if (is_null($vote_id))
74
if (!isset ($game->votes[$user_id]))
76
notice($from, $game->s.'You haven\'t voted yet.'.$game->e);
80
elseif (isset ($game->votes[$user_id]) && $game->votes[$user_id] == $vote_id)
82
notice($from, $game->s.'You already voted that way. The vote will be tallied when the day ends.'.$game->e);
86
if (isset ($game->votes[$user_id]))
88
$old_vote_name = ($game->votes[$user_id] !== false) ? $game->players[$game->votes[$user_id]]->nick : 'abstain';
92
$old_vote_name = null;
95
if ($vote_id === false)
97
$vote_name = 'abstain';
99
elseif (is_null($vote_id))
101
$vote_name = 'undecided';
105
$vote_name = $game->players[$vote_id]->nick;
108
if (is_null($vote_id))
110
unset ($game->votes[$user_id]);
114
$game->votes[$user_id] = $vote_id;
117
// Tally the current vote count, including the new one being cast.
120
$current_votes = array ();
122
foreach ($game->votes as $value)
124
if ($value === false)
128
elseif (!isset ($current_votes[$value]))
130
$current_votes[$value] = 1;
134
$current_votes[$value]++;
138
foreach ($current_votes as $key => $value)
140
$current_votes[$key] = $game->players[$key]->nick.': '.$value;
143
$current_votes[] = 'Abstains: '.$abstains;
144
$current_votes[] = 'Undecided: '.(count($game->players) - count($game->votes));
146
// Output the message.
148
if (is_null($vote_id))
150
output($to, $game->s.$from.' has switched from '.$old_vote_name.' to undecided. '.implode(', ', $current_votes).$game->e);
152
elseif (!is_null($old_vote_name))
154
output($to, $game->s.$from.' has switched from '.$old_vote_name.' to vote '.($vote_id === false ? 'to' : 'for').' '.$vote_name.'. '.implode(', ', $current_votes).$game->e);
158
output($to, $game->s.$from.' has voted '.($vote_id === false ? 'to' : 'for').' '.$vote_name.'. '.implode(', ', $current_votes).$game->e);
161
// Determine whether or not the turn is over.
163
if (count($game->votes) != count($game->players))
165
// There is a player who hasn't cast a vote yet.
170
$vote_pick = call('yandere/solve-day-vote', $channel);
172
if (is_null($vote_pick))
174
// Everyone voted, but there was no resolution.
176
output($to, $game->s.'Everyone has voted, but there is a tie. Someone will need to switch their vote, or you can type "!yandere next" and force the group to abstain.'.$game->e);
180
// All players have voted and there is a resolution. Begin the night (which will kill the voted player).
182
call('yandere/night', $channel, $vote_pick);