summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2015-01-01 17:29:18 +0100
committerJulien Dessaux2015-01-01 18:11:58 +0100
commit0b940da86e810f846361c847b902329601d31e4e (patch)
tree71a770e84c48e6afea1f8f8bc69aede78e5d8bc7
parentSmall starting game state fixes (diff)
downloadavalon-arthur-0b940da86e810f846361c847b902329601d31e4e.tar.gz
avalon-arthur-0b940da86e810f846361c847b902329601d31e4e.tar.bz2
avalon-arthur-0b940da86e810f846361c847b902329601d31e4e.zip
Factorised king nomination code
-rw-r--r--Avalon.pm16
1 files 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}) {