# HG changeset patch # User "Rex Tsai " # Date 1225570343 -28800 # Node ID 0cfc7a19a4d241325793766e17b0b738b1fc0964 # Parent e8a244ce5a1d7dbd3ed7f70e361a963756f94533# Parent 2efa901871e539a21d8ae5d72175134256a9aa08 branch merged diff -r 2efa901871e5 -r 0cfc7a19a4d2 Ikariam.pm --- a/Ikariam.pm Sun Nov 02 03:01:24 2008 +0800 +++ b/Ikariam.pm Sun Nov 02 04:12:23 2008 +0800 @@ -1,4 +1,3 @@ -#!/usr/bin/env perl BEGIN { foreach (((getpwuid($<))[7], $ENV{HOME}, $ENV{LOGDIR}, ".")) { require "$_/.eagleeye.pm" if (-f "$_/.eagleeye.pm"); @@ -373,6 +372,32 @@ } } +# for tavern only +sub set { + my $self = shift; + my $type = shift; + my $cityId = shift; + + die ("we don't know about this city") unless(defined($self->{'cities'}->{$cityId})); + + my $position = -1; + my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; + foreach (0..$#locations) { + $position = $_ if($locations[$_] eq $type); + } + + if($position != -1) { + $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); + $self->{mech}->submit_form( + form_number => 1, + fields => { + amount => $self->{'cities'}->{$cityId}->{$type}->{maxValue}, + } + ); + + } +} + sub build { my $self = shift; my $type = shift; @@ -535,10 +560,29 @@ $self->{'cities'}->{$cityId}->{maxActionPoints} = $extractor->find('//span[@id="value_maxActionPoints"]');; } +sub checkTavern { + my $self = shift; + my $cityId = shift; + + my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; + # init + $self->{'cities'}->{$cityId}->{'tavern'}->{'maxValue'} = 0; + $self->{'cities'}->{$cityId}->{'tavern'}->{'iniValue'} = 0; + foreach (0..$#locations) { + if($locations[$_] eq 'tavern') { + my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=tavern&id=%d&position=%d', $self->{server}, $cityId, $_ )); + my $extractor = Ikariam::Extractor->new(content => $res->content); + if($extractor->{doc}->toString(0) =~ /maxValue : (\d+),\s+overcharge : \d+,\s+iniValue : (\d+),/) { + $self->{'cities'}->{$cityId}->{'tavern'}->{'maxValue'} = $1; + $self->{'cities'}->{$cityId}->{'tavern'}->{'iniValue'} = $2; + } + last; + } + } +} sub checkMilitaryAdvisorMilitaryMovements { my $self = shift; - # TODO my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $self->{server})); my $extractor = new Ikariam::Extractor(content => $res->content); @@ -800,6 +844,7 @@ $self->checkCity($cityId); $self->checkTownHall($cityId); $self->checkArmies($cityId); + $self->checkTavern($cityId); } return $self->{'cities'}; } diff -r 2efa901871e5 -r 0cfc7a19a4d2 agent.pl --- a/agent.pl Sun Nov 02 03:01:24 2008 +0800 +++ b/agent.pl Sun Nov 02 04:12:23 2008 +0800 @@ -52,10 +52,7 @@ sub is_happiness { my ($self, $city) = @_; - # FIXME. - # we should update the tavern setting. - # we should update the travl return ($city->{growth} >= 5 ? 1 : 0) if($city->{buildings}->{townHall} <= 10); @@ -64,6 +61,16 @@ return ($city->{happiness} >= 2 ? 1 : 0); } +sub is_tavern_available { + my ($self, $city) = @_; + return (defined($city->{buildings}->{tavern}) ? 1 : 0); +} + +sub is_bacchanal { + my ($self, $city) = @_; + return ($city->{tavern}->{maxValue} == $city->{tavern}->{iniValue} ? 1 : 0); +} + sub is_warehouse_enough { my ($self, $city) = @_; # TODO 以速率計算容納率 @@ -162,7 +169,6 @@ return (defined($self->{'ikariam'}->{research}->{4010}) ? 1 : 0); } - sub is_barracks_level_enough { my ($self, $city) = @_; return 0 if(!defined($city->{buildings}->{barracks})); @@ -246,7 +252,6 @@ our $i = new Ikariam($::server, $::user, $::pass); $i->login; -$i->checkMilitaryAdvisorCombatReports(); my $cities = $i->check; # Genereic rules for both overall and city level arranagement. diff -r 2efa901871e5 -r 0cfc7a19a4d2 city.yaml --- a/city.yaml Sun Nov 02 03:01:24 2008 +0800 +++ b/city.yaml Sun Nov 02 04:12:23 2008 +0800 @@ -23,10 +23,15 @@ - is_warehouse_enough: 0: build_warehouse - is_happiness: - 0: + 0: - is_winepress_researched: - # FIXME: we should update the tavern setting. - 1: build_tavern + 1: + - is_tavern_available: + 0: build_tavern + 1: + - is_bacchanal: + 0: set_tavern + 1: build_tavern # TODO # http://ikariam.wikia.com/wiki/List_of_buildings # http://ikariam.wikia.com/wiki/Technology_Tree