From 4d68f76696748887fdcb9843049af7ece5e0656b Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 1 Jan 2015 21:08:34 +0100 Subject: Implemented the good_wins endgame and the ASSASSINGUESS game phase --- Avalon.pm | 37 ++++++++++++++++++++++++++++++++++++- README.markdown | 2 +- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Avalon.pm b/Avalon.pm index 0123ff0..b6a6bb0 100644 --- a/Avalon.pm +++ b/Avalon.pm @@ -69,6 +69,14 @@ sub game_ready { return ( $av->{gamephase} == GAMESTART and scalar keys $av->{registered} >= 5 ); } +sub good_wins { + my ( $self, $who ) = @_; + my $av = $self->{avalon}; + my $evil_msg = "WINNERSIDE GOOD $av->{roles}->{MERLIN}->[0] " . join(' ', @{$av->{roles}->{GOOD}}); + $self->say( channel => $av->{config}->{'game.channel'}, body => $evil_msg ); + $self->reset_game; +} + sub kick { my ( $self, $who ) = @_; my $av = $self->{avalon}; @@ -208,6 +216,15 @@ sub timeout_occurred { $av->{lastcall} = 1; } } + when (ASSASSINGUESS) { + if ($av->{lastcall}) { + $self->kick($av->{roles}->{ASSASSIN}->[0]); + } else { + $self->say( channel => $av->{config}->{'game.channel'}, body => "KILLMERLINNOW" ); + $self->set_timeout(2); + $av->{lastcall} = 1; + } + } default { $self->say( channel => $av->{config}->{'game.channel'}, body => "timeout" ); } @@ -215,6 +232,9 @@ sub timeout_occurred { } ### IRC methods override ###################################################### +sub chanpart { +} + sub connected { my $self = shift; $poe_kernel->state( 'avalon_timeout', $self, 'timeout_occurred' ); @@ -345,7 +365,22 @@ sub told { when ("QUESTRESULT") {} when ("KILLMERLIN") {} when ("KILLMERLINNOW") {} - when ("KILL") {} + when ("KILL") { + return 'ERR_BAD_ARGUMENTS' unless scalar @args == 1 and $args[0] ~~ $av->{players}; + given ($av->{gamephase}) { + when (ASSASSINGUESS) { + if ($who eq $av->{roles}->{ASSASSIN}->[0]) { + if ($args[0] eq $av->{roles}->{MERLIN}->[0]) { + $self->evil_wins; + } else { + $self->good_wins; + } + } else { + $self->kick($who); + } + } + } + } when ("WINNERSIDE") {} when ("INFO") {} when ("GAMEURL") {} diff --git a/README.markdown b/README.markdown index 86e7baf..815e8ba 100644 --- a/README.markdown +++ b/README.markdown @@ -128,7 +128,7 @@ the vote. ### Game ends #### KILLMERLIN -KILLMERLIN message is sent on the #avalon game channel by arthur to ask the ASSASSIN has 60 seconds to guess who MERLIN isi if the GOOD side win three quests. +KILLMERLIN message is sent on the #avalon game channel by arthur to tell the ASSASSIN has 60 seconds to guess who MERLIN is when the GOOD side winis its third quest. #### KILLMERLINNOW KILLMERLINNOW message is sent by arthur to the assassin that didn't designate MERLIN when there are only 2 seconds remaining. -- cgit v1.2.3