diff Ikariam.pm @ 207:48ea8222782a

automatic build spys
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Mon, 03 Nov 2008 18:40:15 +0800
parents d9f17bcbf1f1
children a5862d3f1c84
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;