diff sheep.pl @ 24:93d4e6ffe330

refined the SQL.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Fri, 10 Oct 2008 03:17:50 +0800
parents 54ab0becd730
children d183277b4d93
line wrap: on
line diff
--- a/sheep.pl	Thu Oct 09 11:33:47 2008 +0800
+++ b/sheep.pl	Fri Oct 10 03:17:50 2008 +0800
@@ -19,22 +19,30 @@
         AND cities.status = 'i'
     }
 );
+#Ikariam::User->set_sql(sheeps => qq {
+#    SELECT user.id 
+#      FROM user, cities, island
+#      WHERE user.id == cities.user
+#        AND cities.island == island.id
+#        AND island.x <= ?
+#        AND island.x >= ?
+#        AND island.y <= ?
+#        AND island.y >= ?
+#        AND user.trader_score_secondary >= 50000
+#        AND user.army_score_main <= 100
+#    }
+#);
 
 Ikariam::User->set_sql(sheeps => qq {
-    SELECT user.id 
-      FROM user, cities, island
-      WHERE user.id == cities.user
-        AND cities.island == island.id
-        AND island.x <= ?
-        AND island.x >= ?
-        AND island.y <= ?
-        AND island.y >= ?
-        AND user.score >= 500 
-        AND user.army_score_main <= 25
+        SELECT user.id 
+          FROM user, cities 
+         WHERE user.id == cities.user 
+           AND user.trader_score_secondary >= 50000 
+           AND user.army_score_main <= 40
+           AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? )
     }
 );
 
-
 if($#ARGV != 1) {
     die("Usage: $0 x y\n");
 }
@@ -46,13 +54,13 @@
 sub listSheeps
 {
     my @sheeps = @_;
+    my %results;
 
     my $s;
     foreach my $sheep (sort (@sheeps)) {
         # avoid duplicate
         next if($sheep->id == $s); $s = $sheep->id;
 
-
         # 查聯盟數量
         my $members = 1;
         unless ($sheep->allyId == '0') {
@@ -60,24 +68,32 @@
         }
 
         foreach my $c ($sheep->cities) {
-
-            # 假期模式
+            my $line = "";
+            # Ignore 假期模式
             next if($c->status eq 'v');
 
             unless($c->status eq 'i') {
                 next if($members > 3);
             }
 
-            printf("%d %s %d,%d,%s of %s (%d),", 
-                $sheep->trader_score_secondary, $c->status, $sheep->score, $sheep->army_score_main, $sheep->name, $sheep->ally, $members);
+            my $island = Ikariam::Island->retrieve($c->island);
+
+            # 所得金錢 = 對方城鎮等級x(對方城鎮等級-1)x對方金錢/10000
+            my $robbery = $c->citylevel * ($c->citylevel - 1) * $sheep->trader_score_secondary / 10000;
 
-            my $island = Ikariam::Island->retrieve($c->island);
-            printf("%s %d [%d,%d] %s http://s2.ikariam.tw/index.php?view=island&id=%d\n", $c->cityname, $c->citylevel, 
+            next if($robbery < 2000);
+            $line = sprintf("%d %s army %d %s/%s(%d),", 
+                $robbery,
+                $c->status, $sheep->army_score_main, $sheep->name, $sheep->ally, $members);
+
+            $line .= sprintf("\"%s\" %d [%d,%d] %s http://s2.ikariam.tw/index.php?view=island&id=%d\n",
+                $c->cityname, $c->citylevel, 
                 $island->x, $island->y,
                 $tradegoodText[$island->tradegood],
                 $island->id);
+
+            printf("%s", $line);
         }
-        printf("\n");
     }
 }
 # find_or_create