diff options
author | Julien Dessaux | 2015-01-01 17:29:18 +0100 |
---|---|---|
committer | Julien Dessaux | 2015-01-01 18:11:58 +0100 |
commit | 0b940da86e810f846361c847b902329601d31e4e (patch) | |
tree | 71a770e84c48e6afea1f8f8bc69aede78e5d8bc7 | |
parent | Small starting game state fixes (diff) | |
download | avalon-arthur-0b940da86e810f846361c847b902329601d31e4e.tar.gz avalon-arthur-0b940da86e810f846361c847b902329601d31e4e.tar.bz2 avalon-arthur-0b940da86e810f846361c847b902329601d31e4e.zip |
Factorised king nomination code
-rw-r--r-- | Avalon.pm | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -55,6 +55,17 @@ sub load_avalon_db { ); } +sub new_king { + my $self = shift; + my $av = $self->{avalon}; + my ($players, $rules) = $self->rules; + $av->{king} = ($av->{king} +1) % $players; + $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; + $self->set_timeout(58); +} + sub reset_game { my $self = shift; my $av = $self->{avalon}; @@ -122,10 +133,7 @@ sub timeout_occurred { $self->say( channel => 'msg', who => $_, body => $evil_msg ) foreach (@{$av->{roles}->{EVIL}}); # Finally we designate the first king $av->{king} = rand($players); - $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; - $self->set_timeout(58); + $self->new_king; } when (TEAM) { if ($av->{lastcall}) { |