diff options
author | Julien Dessaux | 2015-01-01 19:08:07 +0100 |
---|---|---|
committer | Julien Dessaux | 2015-01-01 19:08:07 +0100 |
commit | 2f998f0d1f9d7e56f8a73660a5873764b0537b26 (patch) | |
tree | 7a56420de91673a0f16bfcbeda9cda1c1f4e82dc | |
parent | Factorised king nomination code (diff) | |
download | avalon-arthur-2f998f0d1f9d7e56f8a73660a5873764b0537b26.tar.gz avalon-arthur-2f998f0d1f9d7e56f8a73660a5873764b0537b26.tar.bz2 avalon-arthur-2f998f0d1f9d7e56f8a73660a5873764b0537b26.zip |
Implemented TEAMVOTE game phase
-rw-r--r-- | Avalon.pm | 59 |
1 files changed, 58 insertions, 1 deletions
@@ -28,6 +28,20 @@ my %gamerules = ( 10 => [ 4, 3, 4, 4, 5, 5, 1], ); +sub check_endgame_and_proceed { + my $self = shift; + my $av = $self->{avalon}; + + if ($av->{round}->{failed_votes} >= 5) { + # TODO $self->evil_wins + } + given ($av->{gamephase}) { + when (TEAMVOTE) { + $self->new_king; + } + } +} + sub game_ready { my $av = shift->{avalon}; return ( $av->{gamephase} == GAMESTART and scalar keys $av->{registered} >= 5 ); @@ -60,6 +74,7 @@ sub new_king { my $av = $self->{avalon}; my ($players, $rules) = $self->rules; $av->{king} = ($av->{king} +1) % $players; + $av->{team} = []; $self->say( channel => $av->{config}->{'game.channel'}, body => "KING $av->{players}->[$av->{king}] $rules->[$av->{round}->{id}] $av->{round}->{failed_votes}" ); $av->{gamephase} = TEAM; $av->{lastcall} = 0; @@ -144,6 +159,20 @@ sub timeout_occurred { $av->{lastcall} = 1; } } + when (TEAMVOTE) { + foreach (@{$av->{players}}) { + next if (exists $av->{votes}->{$_}); + if ($av->{lastcall}) { + $self->kick($_); + } else { + $self->say( channel => 'msg', who => $_, body => "VOTENOW" ); + } + } + unless ($av->{lastcall}) { + $self->set_timeout(2); + $av->{lastcall} = 1; + } + } default { $self->say( channel => $av->{config}->{'game.channel'}, body => "timeout" ); } @@ -227,7 +256,35 @@ sub told { $av->{lastcall} = 0; $self->set_timeout(58); } - when ("VOTE") {} + when ("VOTE") { + return 'ERR_BAD_ARGUMENTS' unless scalar @args == 1 and $args[0] ~~ [ "yes", "no" ]; + my ($players, $rules) = $self->rules; + given ($av->{gamephase}) { + when (TEAMVOTE) { + $self->kick($who) unless $who ~~ $av->{players}; + $av->{votes}->{$who} = $args[0] unless exists $av->{votes}->{$who}; + if (scalar keys $av->{votes} == $players) { + my $score = 0; + foreach (keys $av->{votes}) { + $score++ if $av->{votes}->{$_} eq "yes"; + } + $av->{votes} = {}; + if ($score > $players / 2) { + $av->{round}->{failed_votes} = 0; + $av->{votes} = {}; + $av->{gamephase} = QUESTVOTE; + $av->{lastcall} = 0; + $self->set_timeout(58); + $self->say( channel => $av->{config}->{'game.channel'}, body => "VOTERESULT PASS $score" ); + } else { + $self->say( channel => $av->{config}->{'game.channel'}, body => "VOTERESULT FAIL $score" ); + $av->{round}->{failed_votes}++; + $self->check_endgame_and_proceed; + } + } + } + } + } when ("VOTENOW") {} when ("VOTERESULT") {} when ("QUESTRESULT") {} |