changeset 270:6bce423892f4

updated plunderCity and blockadeCity
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 30 Nov 2008 03:39:52 +0800
parents c7f4a6f0fbde
children 0ed1b3e72e65
files Ikariam.pm warfare.pl
diffstat 2 files changed, 42 insertions(+), 6 deletions(-) [+]
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.
--- a/warfare.pl	Sat Nov 29 02:16:35 2008 +0800
+++ b/warfare.pl	Sun Nov 30 03:39:52 2008 +0800
@@ -100,6 +100,7 @@
                 my $ally = Ikariam::Ally->retrieve($user->allyId);
                 my $targetAlly = Ikariam::Ally->retrieve($sheep->allyId);
                 # We don't want to piss off the big team.
+                next CITY if(!defined($ally));
                 next CITY if($ally->score == 0);
                 next CITY if($targetAlly->score > $ally->score);
                 next CITY if(defined($ally) && $ally->members > 12);
@@ -145,7 +146,12 @@
     my $victim = $self->locateVictim($cityId, $x, $y, $tradegood);
     if(defined($victim)) {
         $self->{ikariam}->changeCity($cityId);
-        $self->{ikariam}->plunderCity($victim);
+        $self->{ikariam}->plunderCity($victim,
+                {
+                    # cargo_army_302 => '2', # 劍士
+                    cargo_army_303 => '3', # 方陣
+                }
+                );
     }
 }