summaryrefslogtreecommitdiff
path: root/Avalon.pm
diff options
context:
space:
mode:
authorJulien Dessaux2014-12-04 16:58:18 +0100
committerJulien Dessaux2014-12-04 20:11:20 +0100
commit23e181f35153f6a5bbe14601ab311b37a9a2e3cc (patch)
treea651e0cda0e3ff9896d7b96e0bdd77f67fc53937 /Avalon.pm
parentImplemented timeout handling (diff)
downloadavalon-arthur-23e181f35153f6a5bbe14601ab311b37a9a2e3cc.tar.gz
avalon-arthur-23e181f35153f6a5bbe14601ab311b37a9a2e3cc.tar.bz2
avalon-arthur-23e181f35153f6a5bbe14601ab311b37a9a2e3cc.zip
Implemented the game state
Diffstat (limited to 'Avalon.pm')
-rw-r--r--Avalon.pm47
1 files changed, 46 insertions, 1 deletions
diff --git a/Avalon.pm b/Avalon.pm
index cd6d874..ba73ae3 100644
--- a/Avalon.pm
+++ b/Avalon.pm
@@ -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) {