diff scan.pl @ 18:fd44e3a1f800

fixed the cache. show tradegoodText of sheeps. refined enemy.pl
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 16:10:01 +0800
parents 59f2c435760c
children 5635e75c92d0
line wrap: on
line diff
--- a/scan.pl	Wed Oct 08 15:25:48 2008 +0800
+++ b/scan.pl	Wed Oct 08 16:10:01 2008 +0800
@@ -80,25 +80,28 @@
     die("Usage: $0\nUsage: $0 x y\n");
 }
 
-foreach my $island (@islands)
+foreach my $h_island (@islands)
 {
-    printf("checking island %d\n", $island->{id});
+    printf("checking island %d\n", $h_island->{id});
+
+    my $island;
+    if($island = Ikariam::Island->retrieve($h_island->{id})) {
+        foreach my $i (keys(%$h_island)) {
+            $island->set($i => $h_island->{$i});
+        }
+    } else {
+        $island = Ikariam::Island->insert($h_island);
+    }
 
     # scanning the island
-    if($island->{time} < (time - 60*60*12 ))
+    if($island->time le (time - 60*60*12 ))
     {
-        my @cities = $i->viewIsland($island->{id});
-        saveCities($island->{id}, @cities);
+        my @cities = $i->viewIsland($h_island->{id});
+        saveCities($h_island->{id}, @cities);
+    }
 
-        $island->{'time'} = time;
-        if(my $c = Ikariam::Island->retrieve($island->{id})) {
-            foreach my $i (keys(%$island)) {
-                eval($c->$i($island->{$i}));
-            }
-        } else {
-            Ikariam::Island->insert($island);
-        }
-    }
+    $island->set('time', time);
+    $island->update();
 }
 $i->logout;
 # $i->getCityInfo();