diff Ikariam.pm @ 270:6bce423892f4

updated plunderCity and blockadeCity
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 30 Nov 2008 03:39:52 +0800
parents 285d5b39ef2c
children 10f14db31151
line wrap: on
line diff
--- a/Ikariam.pm	Sat Nov 29 02:16:35 2008 +0800
+++ b/Ikariam.pm	Sun Nov 30 03:39:52 2008 +0800
@@ -648,6 +648,7 @@
 sub plunderCity {
     my $self = shift;
     my $cityId = shift;
+    my $fields = 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);
@@ -661,11 +662,40 @@
         } else {
             $self->{mech}->submit_form(
                     form_number => 1,
-                    fields      => {
-                           # cargo_army_302 => '2', # 劍士
-                           cargo_army_303 => '3', # 方陣
-                    }
-                    );
+                    fields      => $fields);
+        }
+    } else {
+        # put the id in the friends.txt file.
+        Ikariam::Cities->has_a(user => 'Ikariam::User');
+        my $city = Ikariam::Cities->retrieve($cityId);
+        my $sheep = $city->user;
+
+        open(OUT, ">>friends.txt") or Carp::carp("can not open friends.txt");
+        print OUT $sheep->name . "\n";
+        close(OUT);
+        Carp::carp($treaty);
+    }
+}
+
+
+sub blockadeCity {
+    my $self = shift;
+    my $cityId = shift;
+    my $fields = shift;
+    my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=blockade&destinationCityId=%d", $self->{server}, $cityId));
+
+    my $extractor = Ikariam::Extractor->new(content => $res->content);
+    # check peace treaty
+    my $treaty = $extractor->find('//div[@class="warning"]');
+    if(!defined($treaty)) {
+        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      => $fields);
         }
     } else {
         # put the id in the friends.txt file.