diff options
author | Julien Dessaux | 2014-12-04 16:58:18 +0100 |
---|---|---|
committer | Julien Dessaux | 2014-12-04 20:11:20 +0100 |
commit | 23e181f35153f6a5bbe14601ab311b37a9a2e3cc (patch) | |
tree | a651e0cda0e3ff9896d7b96e0bdd77f67fc53937 | |
parent | Implemented timeout handling (diff) | |
download | avalon-arthur-23e181f35153f6a5bbe14601ab311b37a9a2e3cc.tar.gz avalon-arthur-23e181f35153f6a5bbe14601ab311b37a9a2e3cc.tar.bz2 avalon-arthur-23e181f35153f6a5bbe14601ab311b37a9a2e3cc.zip |
Implemented the game state
Diffstat (limited to '')
-rw-r--r-- | Avalon.pm | 47 | ||||
-rw-r--r-- | INSTALL.markdown | 1 |
2 files changed, 47 insertions, 1 deletions
@@ -6,13 +6,54 @@ package Bot::BasicBot::Pluggable::Module::Avalon; use strict; use warnings; use v5.12; -use experimental qw(switch); +use experimental qw(autoderef switch); +use Bot::BasicBot::Pluggable::Store::DBI; +use List::Util qw(shuffle); use POE; use Time::HiRes qw(time); use base qw(Bot::BasicBot::Pluggable::Module); ### Game logic ############################################################### +use enum qw(GAMESTART TEAM TEAMVOTE QUESTVOTE ASSASSINGUESS); +use enum qw(NUMBER_OF_EVIL_PLAYERS FIRST_QUEST SECOND_QUEST THIRD_QUEST FOURTH_QUEST FIFTH_QUEST SPECIAL_QUEST_RULE); +my %gamerules = ( + # number of players => ( number of evil, players on first quest, second, third, fourth, fifth, number of fail for fourth quest success ) + 5 => [ 2, 2, 3, 2, 3, 3, 0], + 6 => [ 2, 2, 3, 4, 3, 4, 0], + 7 => [ 3, 2, 3, 3, 4, 4, 1], + 8 => [ 3, 3, 4, 4, 5, 5, 1], + 9 => [ 3, 3, 4, 4, 5, 5, 1], + 10 => [ 4, 3, 4, 4, 5, 5, 1], +); + +sub load_avalon_db { + my $self = shift; + # This database stores registrations and bans + $self->{avdb} = Bot::BasicBot::Pluggable::Store::DBI->new( + dsn => "dbi:SQLite:dbname=arthur.sqlite", + table => "arthur", + ); +} + +sub reset_game { + my $av = shift->{avalon}; + $av->{gamephase} = GAMESTART; + $av->{gamesplayed} = 0; + $av->{timeout} = 0; + $av->{registered} = {}; + $av->{players} = (); + $av->{roles} = { + 'MERLIN' => [], + 'ASSASSIN' => [], + 'GOOD' => [], + 'EVIL' => [], + }; + $av->{king} = 0; + $av->{votes} = { pass => 0, fail => 0 }; + $av->{quests} = { pass => 0, fail => 0, votes => 0 }; +} + sub set_timeout { my ( $self, $value) = @_; $poe_kernel->alarm( avalon_timeout => time() + $value ); @@ -33,6 +74,8 @@ sub init { my $self = shift; $self->{avalon} = {}; $self->{avalon}->{config} = $self->bot->{store_object}->{store}->{cfg}->{cfg}; + $self->load_avalon_db; + $self->reset_game; } sub help { @@ -44,6 +87,8 @@ sub told { my $who = $mess->{who}; my $body = $mess->{body}; my $ispriv = defined $mess->{address}; + my $av = $self->{avalon}; + my $avdb = $self->{avdb}; my ( $command, @args ) = split /\s+/, $mess->{body}; given ($command) { diff --git a/INSTALL.markdown b/INSTALL.markdown index 1c07e06..18d9919 100644 --- a/INSTALL.markdown +++ b/INSTALL.markdown @@ -6,4 +6,5 @@ Required Perl modules --------------------- Bot::BasicBot::Pluggable Config::Simple +enum POE::Component::SSLify |