From 0b940da86e810f846361c847b902329601d31e4e Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 1 Jan 2015 17:29:18 +0100 Subject: Factorised king nomination code --- Avalon.pm | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Avalon.pm b/Avalon.pm index d1bc23b..438257a 100644 --- a/Avalon.pm +++ b/Avalon.pm @@ -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}) { -- cgit v1.2.3