diff Ikariam.pm @ 171:2efa901871e5

check peace treaty
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 02 Nov 2008 03:01:24 +0800
parents 637314cc57ed
children 0cfc7a19a4d2
line wrap: on
line diff
--- a/Ikariam.pm	Sun Nov 02 02:23:13 2008 +0800
+++ b/Ikariam.pm	Sun Nov 02 03:01:24 2008 +0800
@@ -441,13 +441,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 {