diff Ikariam.pm @ 174:0cfc7a19a4d2

branch merged
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 02 Nov 2008 04:12:23 +0800
parents e8a244ce5a1d 2efa901871e5
children 8afd380c20ac 2362c8c8909e
line wrap: on
line diff
--- a/Ikariam.pm	Sun Nov 02 04:12:00 2008 +0800
+++ b/Ikariam.pm	Sun Nov 02 04:12:23 2008 +0800
@@ -466,13 +466,20 @@
 sub plunderCity {
     my $self = shift;
     my $cityId = shift;
-    $self->{mech}->get(sprintf("http://%s/index.php?view=plunder&destinationCityId=%d", $self->{server}, $cityId));
-    $self->{mech}->submit_form(
-        form_number => 1,
-        fields      => {
-            cargo_army_302 => '2',
-        }
-    );
+    my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=plunder&destinationCityId=%d", $self->{server}, $cityId));
+
+    # check peace treaty
+    my $treaty = Ikariam::Extractor->new(content => $res->content)->find('//div[@class="warning"]');
+    if(!defined($treaty)) {
+        $self->{mech}->submit_form(
+                form_number => 1,
+                fields      => {
+                cargo_army_302 => '2',
+                }
+                );
+    } else {
+        warn ($treaty);
+    }
 }
 
 sub changeCity {