From 1ef6814e9b123ec950ef0b1554d4e6d0f341ca7a Mon Sep 17 00:00:00 2001 From: Elijah Perrault Date: Sun, 10 Apr 2011 16:20:52 -0600 Subject: [PATCH] Werewolf: Fixed another round of bugs. --- doc/CHANGELOG | 1 + modules/Werewolf.pm | 33 ++++++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/doc/CHANGELOG b/doc/CHANGELOG index db41d2d..42db556 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev =============================================================================== + * Werewolf: Fixed another round of bugs. * Werewolf: Fixed a grammatical error. Thanks TAD! * Werewolf: Fixed a bug that occasionally caused a person to get wolf twice in the same game. diff --git a/modules/Werewolf.pm b/modules/Werewolf.pm index 5c3f6d1..74b8a3b 100644 --- a/modules/Werewolf.pm +++ b/modules/Werewolf.pm @@ -345,10 +345,8 @@ sub cmd_wolf { $LYNCH{lc $argv[1]}{lc $src->{nick}} = 1; privmsg($src->{svr}, $src->{chan}, "\2$src->{nick}\2 votes for \2$argv[1]\2."); - # If the accused has enough votes for lynching, call judgment. - if (keys %{$LYNCH{lc $argv[1]}} >= $LVOTEN) { _judgment(lc $argv[1]) } - # Perhaps they have no votes at all? - elsif (!keys %{$LYNCH{lc $argv[1]}}) { delete $LYNCH{lc $argv[1]} } + # Pass this thing onto lynch management. + _lynchmng(); } when (/^(RETRACT|R)$/) { # WOLF RETRACT @@ -392,11 +390,12 @@ sub cmd_wolf { # Done. if ($hvi) { privmsg($src->{svr}, $src->{chan}, "\2$src->{nick}\2 retracted his/her vote."); - if (!keys %{$LYNCH{$target}}) { delete $LYNCH{$target} } } else { notice($src->{svr}, $src->{nick}, 'You haven\'t voted yet.'); } + # Call lynch management. + _lynchmng(); } when (/^(VOTES|V)$/) { # WOLF VOTES @@ -1229,7 +1228,7 @@ sub _getrole { elsif ($PLAYERS{$plyr} =~ m/h/xsm) { $role = 'harlot' } elsif ($PLAYERS{$plyr} =~ m/g/xsm) { $role = 'guardian angel' } elsif ($PLAYERS{$plyr} =~ m/d/xsm) { $role = 'detective' } - elsif ($PLAYERS{$plyr} =~ m/v/xsm) { $role = 'villager' } + elsif ($PLAYERS{$plyr} =~ m/(v|t)/xsm) { $role = 'villager' } } elsif ($lev == 2) { if ($PLAYERS{$plyr} =~ m/w/xsm) { $role = 'wolf' } @@ -1271,11 +1270,13 @@ sub _player_del { # Update LVOTEN. if ($LVOTEN) { $LVOTEN-- } + # Call lynch management. + if ($PHASE) { if ($PHASE eq 'd') { _lynchmng() } } # Check for winning conditions. if (!$PGAME) { my $wolves; - while ((undef, $_) = each %PLAYERS) { if ($_ =~ m/(w|t)/xsm) { $wolves++ } } + while ((undef, $_) = each %PLAYERS) { if ($_ =~ m/w/xsm) { $wolves++ } } if (!$wolves) { _gameover('v'); return } my $villagers; while ((undef, $_) = each %PLAYERS) { if ($_ =~ m/(v|s|g|h|d)/xsm) { $villagers++ } } @@ -1289,6 +1290,24 @@ sub _player_del { return 1; } +# Subroutine for managing/cleaning lynch votes. +sub _lynchmng { + # Iterate through all the votes. + foreach my $acc (keys %LYNCH) { + if (!keys %{$LYNCH{$acc}}) { + # Unclean vote. Delete it. + delete $LYNCH{$acc}; + } + } + + # Now check if we have anyone who has enough votes for judgment. + foreach my $acc (keys %LYNCH) { + if (keys %{$LYNCH{$acc}} >= $LVOTEN) { _judgment($acc) } + } + + return 1; +} + # Handling the end of the game. sub _gameover { my ($winner) = @_;