diff Ikariam.pm @ 242:5f6f845bbb1d

check if the city still exist.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Mon, 10 Nov 2008 14:19:43 +0800
parents 937fc672df56
children a654d43731f0
line wrap: on
line diff
--- a/Ikariam.pm	Fri Nov 07 15:18:23 2008 +0800
+++ b/Ikariam.pm	Mon Nov 10 14:19:43 2008 +0800
@@ -628,15 +628,22 @@
     my $cityId = shift;
     my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=plunder&destinationCityId=%d", $self->{server}, $cityId));
 
+    my $extractor = Ikariam::Extractor->new(content => $res->content);
     # check peace treaty
-    my $treaty = Ikariam::Extractor->new(content => $res->content)->find('//div[@class="warning"]');
+    my $treaty = $extractor->find('//div[@class="warning"]');
     if(!defined($treaty)) {
-        $self->{mech}->submit_form(
-                form_number => 1,
-                fields      => {
-                        cargo_army_302 => '3', # 劍士
+        my @forms = $self->{mech}->forms();
+        if($#forms < 1) {
+            my $city = Ikariam::Cities->retrieve($cityId);
+            $city->delete;
+        } else {
+            $self->{mech}->submit_form(
+                    form_number => 1,
+                    fields      => {
+                           cargo_army_302 => '3', # 劍士
                     }
-                );
+                    );
+        }
     } else {
         # put the id in the friends.txt file.
         Ikariam::Cities->has_a(user => 'Ikariam::User');