# HG changeset patch # User "Rex Tsai " # Date 1225708815 -28800 # Node ID 48ea8222782ac02cd594907d24a94e0ae010952a # Parent b7af307a222d21bef07b51d4bc2b5b5c6c703e0b automatic build spys diff -r b7af307a222d -r 48ea8222782a Ikariam.pm --- a/Ikariam.pm Mon Nov 03 17:52:28 2008 +0800 +++ b/Ikariam.pm Mon Nov 03 18:40:15 2008 +0800 @@ -510,6 +510,26 @@ } } +sub buildSpy { + my $self = shift; + my $unitType = shift; + my $cityId = shift; + my $type = 'safehouse'; + + my $position = -1; + my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; + foreach (2..$#locations) { + $position = $_ if($locations[$_] eq $type); + } + + if($position != -1) { + my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); + my $url = + Ikariam::Extractor->new(content => $res->content)->find(sprintf('//div[@class="forminput"]/a/@href')); + $self->{mech}->get($url) if(defined($url)); + } +} + sub build { my $self = shift; my $type = shift; diff -r b7af307a222d -r 48ea8222782a agent.pl --- a/agent.pl Mon Nov 03 17:52:28 2008 +0800 +++ b/agent.pl Mon Nov 03 18:40:15 2008 +0800 @@ -211,18 +211,6 @@ } } -sub rule_engagement -{ - my ($self, $city) = @_; - # TODO - # 計算距離, 可搶劫比例, 是否有聯盟, 軍事分數 (win rate) -} - -sub rule_resource -{ - # TODO -} - sub is_shipyard_upgrading { my ($self, $city) = @_; return $self->{'ikariam'}->is_shipyard_upgrading($city->{id}); @@ -259,7 +247,6 @@ my ($self, $city) = @_; return $self->{ikariam}->is_army_trainning($city->{id}); } - sub train_army { my ($self, $city) = @_; my $cityId = $city->{id}; @@ -332,6 +319,7 @@ } return 0; } + 1; @@ -368,7 +356,11 @@ # maybe this should be moved to Rules. $i->blanceHurmanResource($cityId); - + + # build spy + $i->buildSpy('spy', $cityId); + + # build military! $tree = LoadFile('military.yaml'); $cities->{$cityId}->{parse_path} = []; $cities->{$cityId}->{parse_answer} = undef;