changeset 207:48ea8222782a

automatic build spys
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Mon, 03 Nov 2008 18:40:15 +0800
parents b7af307a222d
children a2bb38589172
files Ikariam.pm agent.pl
diffstat 2 files changed, 26 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- 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;