diff Ikariam.pm @ 286:2ddd2bd21ef2

list spydata when check enemies
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 04 Dec 2008 21:54:00 +0800
parents 10f14db31151
children 24de33db8284
line wrap: on
line diff
--- a/Ikariam.pm	Thu Dec 04 03:22:24 2008 +0800
+++ b/Ikariam.pm	Thu Dec 04 21:54:00 2008 +0800
@@ -723,10 +723,10 @@
     );
 }
 
-sub checkCity {
+sub readCity {
     my $self = shift;
     my $cityId = shift;
-
+    my $data;
 
     my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=city&id=%d", $self->{server}, $cityId));
     my $extractor = new Ikariam::Extractor(content => $res->content);
@@ -735,7 +735,7 @@
         my @buildings = $extractor->find(sprintf('//li[@id="position%s"]/@class', $i));
         foreach my $building (@buildings) {
             if (!($building =~ /buildingGround/) && !($building =~ /townhall/)) {
-                $self->{'cities'}->{$cityId}->{locations}[$i] = $building;
+                $data->{locations}[$i] = $building;
 
                 my $span;
                 my @spans = $extractor->find(sprintf('//li[@id="position%s"]//span[@class="textLabel"]/text()', $i));
@@ -745,23 +745,33 @@
                     $span = $spans[0];
                 }
                 my (undef, undef, $level) = split(/ /, $span);
-                $self->{'cities'}->{$cityId}->{buildings}->{$building} = $level;
+                $data->{buildings}->{$building} = $level;
             }
         }
     }
 
-    $self->{'cities'}->{$cityId}->{name} = $extractor->find('//span[@class="city"]/text()');
+    $data->{name} = $extractor->find('//span[@class="city"]/text()');
 
     my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]');
     if($island =~ /(\w+)\[(\d+):(\d+)\]/) {
-        $self->{'cities'}->{$cityId}->{island}->{name} = $1;
-        $self->{'cities'}->{$cityId}->{island}->{x} = $2;
-        $self->{'cities'}->{$cityId}->{island}->{y} = $3;
-        $self->{'cities'}->{$cityId}->{island}->{id} = my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]/@href');
-        $self->{'cities'}->{$cityId}->{island}->{id} =~ s/\?view=island&id=(\d+)/$1/;
+        $data->{island}->{name} = $1;
+        $data->{island}->{x} = $2;
+        $data->{island}->{y} = $3;
+        $data->{island}->{id} = my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]/@href');
+        $data->{island}->{id} =~ s/\?view=island&id=(\d+)/$1/;
     }
 
-    return  $self->{'cities'}->{$cityId} if(wantarray());
+    return $data;
+}
+
+sub checkCity {
+    my $self = shift;
+    my $cityId = shift;
+
+    $self->{'cities'}->{$cityId} = $self->readCity($cityId);
+
+    my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=city&id=%d", $self->{server}, $cityId));
+    my $extractor = new Ikariam::Extractor(content => $res->content);
 
     $self->{'cities'}->{$cityId}->{resources}->{gold} = $extractor->find('//span[@id="value_gold"]/text()');
     $self->{'cities'}->{$cityId}->{resources}->{gold} =~ s/,//g;
@@ -846,7 +856,7 @@
                 my @links = $extractor->find(sprintf('//div[@class="spyinfo" and position() = %d]//a/@href', $_));
                 last if($#links < 0);
                 if ($links[0] =~ /id=(\d+)/) {
-                    @{$data->{$1}->{city}} = $self->checkCity($1);
+                    $data->{$1}->{city} = $self->readCity($1);
                     @{$data->{$1}->{risks}} = Ikariam::Extractor->new(content => $self->{mech}->get($links[1])->content)->find('//div[@class="missionRisk"]');
                 }
             }