diff Ikariam.pm @ 232:978a949602e5

Auto-update Scientists numbers for Academy. Refined the rules for safehouse, the safe house must be same or higher level then Town Hall. Make people very happy, when the townHall is less then 16. Build museum first then tavern THG: changed warfare.pl
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 06 Nov 2008 20:31:05 +0800
parents a5862d3f1c84
children 937fc672df56
line wrap: on
line diff
--- a/Ikariam.pm	Wed Nov 05 03:08:16 2008 +0800
+++ b/Ikariam.pm	Thu Nov 06 20:31:05 2008 +0800
@@ -360,15 +360,28 @@
         $position = $_ if($locations[$_] eq $type);
     }
 
-     if($position != -1) {
-         $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position));
-         $self->{mech}->submit_form(
-                 form_number => 1,
-                 fields      => {
-                         amount => $self->{'cities'}->{$cityId}->{$type}->{maxValue},
-                     }
-                 );
- 
+# Academy - inputScientists
+    if($position != -1 && $type eq 'academy') {
+        $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position));
+        $self->{mech}->submit_form(
+                form_number => 1,
+                fields      => {
+                    s => $self->{'cities'}->{$cityId}->{$type}->{maxValue},
+                }
+                );
+
+    }
+
+# Tavern
+    if($position != -1 && $type eq 'tavern') {
+        $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position));
+        $self->{mech}->submit_form(
+                form_number => 1,
+                fields      => {
+                    amount => $self->{'cities'}->{$cityId}->{$type}->{maxValue},
+                }
+                );
+
     }
 }
 
@@ -711,6 +724,28 @@
     $self->{'cities'}->{$cityId}->{maxActionPoints} = $extractor->find('//span[@id="value_maxActionPoints"]');;
 }
 
+sub checkAcademy {
+    my $self = shift;
+    my $cityId = shift;
+    my $building = "academy";
+
+    my @locations = @{$self->{'cities'}->{$cityId}->{locations}};
+    # init
+    $self->{'cities'}->{$cityId}->{$building}->{'maxValue'} = 0;
+    $self->{'cities'}->{$cityId}->{$building}->{'iniValue'} = 0;
+    foreach (0..$#locations) {
+        if($locations[$_] eq $building) {
+            my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=%s&id=%d&position=%d', $self->{server}, $building, $cityId, $_ ));
+            my $extractor = Ikariam::Extractor->new(content => $res->content);
+            if($extractor->{doc}->toString(0) =~ /maxValue : (\d+),\s+overcharge : \d+,\s+iniValue : (\d+),/) {
+                $self->{'cities'}->{$cityId}->{$building}->{'maxValue'} = $1;
+                $self->{'cities'}->{$cityId}->{$building}->{'iniValue'} = $2;
+            }
+            last;
+        }
+    }
+}
+
 sub checkTavern {
     my $self = shift;
     my $cityId = shift;
@@ -995,6 +1030,7 @@
         $self->checkTownHall($cityId);
         $self->checkArmies($cityId);
         $self->checkTavern($cityId);
+        $self->checkAcademy($cityId);
     }
     # $self->checkFriends();
     return $self->{'cities'};