~yandere-dev/yandere/0.1

« back to all changes in this revision

Viewing changes to functions/action-channel.php

  • Committer: dhammond
  • Date: 2008-12-14 05:29:49 UTC
  • Revision ID: svn-v3-single1-dHJ1bmsvcGhhcm8tbW9kdWxlcy9pcmMteWFuZGVyZQ..:3f858fc8-aa8f-444a-bb42-203473f3994f:trunk%2Fpharo-modules%2Firc-yandere:18
UploadedĀ forgottenĀ files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
        
 
3
        list ($command, $user_id, $vote) = $irc_call_args;
 
4
        
 
5
        if ($command !== false && is_null($command))
 
6
        {
 
7
                $command = strtolower($command);
 
8
        }
 
9
        
 
10
        $channel = irc_lower($to);
 
11
        
 
12
        if (!isset ($this->custom_vars->yandere_games[$channel]))
 
13
        {
 
14
                output($to, $from.': There\'s no game here.');
 
15
                return;
 
16
        }
 
17
        
 
18
        $game = $this->custom_vars->yandere_games[$channel];
 
19
        
 
20
        if (!isset ($game->players[$user_id]))
 
21
        {
 
22
                output($to, $from.': You aren\'t in this game.');
 
23
                return;
 
24
        }
 
25
        
 
26
        if (!$game->active)
 
27
        {
 
28
                output($to, $from.': The game hasn\'t started yet.');
 
29
                return;
 
30
        }
 
31
        
 
32
        if ($game->turn % 2 == 1)
 
33
        {
 
34
                // Trying to write a command to the channel during the night. Not allowed.
 
35
                
 
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);
 
37
                return;
 
38
        }
 
39
        
 
40
        if ($vote === false || is_null($vote))
 
41
        {
 
42
                $vote_id = $vote;
 
43
        }
 
44
        else
 
45
        {
 
46
                switch ($command)
 
47
                {
 
48
                case 'vote':
 
49
                case 'kill':
 
50
                        break;
 
51
                
 
52
                default:
 
53
                        notice($to, $game->s.'That action isn\'t allowed during the day.'.$game->e);
 
54
                        return;
 
55
                }
 
56
                
 
57
                $vote_id = call('yandere/get-user-id', $vote);
 
58
                
 
59
                if (!isset ($game->players[$vote_id]))
 
60
                {
 
61
                        output($to, $from.': '.$vote.' isn\'t in this game.');
 
62
                        return;
 
63
                }
 
64
        }
 
65
        
 
66
        if ($vote_id == $user_id)
 
67
        {
 
68
                output($to, $game->s.'You can\'t vote for yourself.'.$game->e);
 
69
                return;
 
70
        }
 
71
        
 
72
        if (is_null($vote_id))
 
73
        {
 
74
                if (!isset ($game->votes[$user_id]))
 
75
                {
 
76
                        notice($from, $game->s.'You haven\'t voted yet.'.$game->e);
 
77
                        return;
 
78
                }
 
79
        }
 
80
        elseif (isset ($game->votes[$user_id]) && $game->votes[$user_id] == $vote_id)
 
81
        {
 
82
                notice($from, $game->s.'You already voted that way. The vote will be tallied when the day ends.'.$game->e);
 
83
                return;
 
84
        }
 
85
        
 
86
        if (isset ($game->votes[$user_id]))
 
87
        {
 
88
                $old_vote_name = ($game->votes[$user_id] !== false) ? $game->players[$game->votes[$user_id]]->nick : 'abstain';
 
89
        }
 
90
        else
 
91
        {
 
92
                $old_vote_name = null;
 
93
        }
 
94
        
 
95
        if ($vote_id === false)
 
96
        {
 
97
                $vote_name = 'abstain';
 
98
        }
 
99
        elseif (is_null($vote_id))
 
100
        {
 
101
                $vote_name = 'undecided';
 
102
        }
 
103
        else
 
104
        {
 
105
                $vote_name = $game->players[$vote_id]->nick;
 
106
        }
 
107
        
 
108
        if (is_null($vote_id))
 
109
        {
 
110
                unset ($game->votes[$user_id]);
 
111
        }
 
112
        else
 
113
        {
 
114
                $game->votes[$user_id] = $vote_id;
 
115
        }
 
116
        
 
117
        // Tally the current vote count, including the new one being cast.
 
118
        
 
119
        $abstains = 0;
 
120
        $current_votes = array ();
 
121
        
 
122
        foreach ($game->votes as $value)
 
123
        {
 
124
                if ($value === false)
 
125
                {
 
126
                        $abstains++;
 
127
                }
 
128
                elseif (!isset ($current_votes[$value]))
 
129
                {
 
130
                        $current_votes[$value] = 1;
 
131
                }
 
132
                else
 
133
                {
 
134
                        $current_votes[$value]++;
 
135
                }
 
136
        }
 
137
        
 
138
        foreach ($current_votes as $key => $value)
 
139
        {
 
140
                $current_votes[$key] = $game->players[$key]->nick.': '.$value;
 
141
        }
 
142
        
 
143
        $current_votes[] = 'Abstains: '.$abstains;
 
144
        $current_votes[] = 'Undecided: '.(count($game->players) - count($game->votes));
 
145
        
 
146
        // Output the message.
 
147
        
 
148
        if (is_null($vote_id))
 
149
        {
 
150
                output($to, $game->s.$from.' has switched from '.$old_vote_name.' to undecided. '.implode(', ', $current_votes).$game->e);
 
151
        }
 
152
        elseif (!is_null($old_vote_name))
 
153
        {
 
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);
 
155
        }
 
156
        else
 
157
        {
 
158
                output($to, $game->s.$from.' has voted '.($vote_id === false ? 'to' : 'for').' '.$vote_name.'. '.implode(', ', $current_votes).$game->e);
 
159
        }
 
160
        
 
161
        // Determine whether or not the turn is over.
 
162
        
 
163
        if (count($game->votes) != count($game->players))
 
164
        {
 
165
                // There is a player who hasn't cast a vote yet.
 
166
                
 
167
                return;
 
168
        }
 
169
        
 
170
        $vote_pick = call('yandere/solve-day-vote', $channel);
 
171
        
 
172
        if (is_null($vote_pick))
 
173
        {
 
174
                // Everyone voted, but there was no resolution.
 
175
                
 
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);
 
177
        }
 
178
        else
 
179
        {
 
180
                // All players have voted and there is a resolution. Begin the night (which will kill the voted player).
 
181
                
 
182
                call('yandere/night', $channel, $vote_pick);
 
183
        }
 
184
        
 
185
?>