changeset 179:8afd380c20ac

do not fight with friends.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Sun, 02 Nov 2008 21:15:51 +0800
parents 0cfc7a19a4d2
children c5e4ef45eaa7
files Ikariam.pm warfare.pl warfare.yaml
diffstat 3 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/Ikariam.pm	Sun Nov 02 04:12:23 2008 +0800
+++ b/Ikariam.pm	Sun Nov 02 21:15:51 2008 +0800
@@ -142,7 +142,7 @@
 
 
     # if debug
-    # LWP::Debug::level('+trace');
+    LWP::Debug::level('+trace');
 
     $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "/tmp/ikariam-cookies.txt", autosave => 1));
     $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate');
@@ -474,11 +474,19 @@
         $self->{mech}->submit_form(
                 form_number => 1,
                 fields      => {
-                cargo_army_302 => '2',
-                }
+                        cargo_army_302 => '2', # 劍士
+                    }
                 );
     } else {
-        warn ($treaty);
+        # 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);
     }
 }
 
--- a/warfare.pl	Sun Nov 02 04:12:23 2008 +0800
+++ b/warfare.pl	Sun Nov 02 21:15:51 2008 +0800
@@ -53,6 +53,14 @@
     return ($city->{transporters}->{avail} > 0) ? 1 : 0;
 }
 
+sub is_port_available {
+    my ($self, $city) = @_;
+    foreach(1..2) {
+        return 1 if($city->{locations}[$_] eq 'port');
+    }
+    return 0;
+}
+
 sub is_army_available {
     my ($self, $city) = @_;
     return ($city->{army}->{Swordsman} >= 2 ) ? 1 : 0;
--- a/warfare.yaml	Sun Nov 02 04:12:23 2008 +0800
+++ b/warfare.yaml	Sun Nov 02 21:15:51 2008 +0800
@@ -5,5 +5,7 @@
           1:
              - is_transporters_available:
                 1:
-                   - is_army_available:
-                      1: engagement
+                   - is_port_available:
+                      1:
+                         - is_army_available:
+                            1: engagement