changeset 108:d3bece9b06b2

fixed the couting *again*
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 29 Oct 2008 15:56:04 +0800
parents 554bdd49c703
children 839d8ad81cde 279a000eb3b0
files warfare.pl
diffstat 1 files changed, 8 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/warfare.pl	Wed Oct 29 15:21:15 2008 +0800
+++ b/warfare.pl	Wed Oct 29 15:56:04 2008 +0800
@@ -22,12 +22,12 @@
          ORDER BY cities.citylevel * (cities.citylevel - 1) * user.trader_score_secondary / 10000 DESC LIMIT 30
     }
 );
-Ikariam::Report->set_sql(attack => qq {
+Ikariam::Report->set_sql(victim => qq {
         SELECT report.id
           FROM report
          WHERE report.city = ?
            AND report.date >= ?
-    }
+    } 
 );
 
 sub new {
@@ -53,7 +53,6 @@
     return ($city->{army}->{Swordsman} > 2 ) ? 1 : 0;
 }
 
-
 sub locateVictim {
     my ($self, $city, $x, $y) = @_;
     my @cities = Ikariam::Cities->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6));
@@ -73,22 +72,22 @@
         }
 
         # check if we over-attacked
-        my $c = Ikariam::Report->search_attack($city->cityId, time - 24*60*60 - 7*60*60)->count();
+        my $c = Ikariam::Report->search_victim($city->cityId, time - 24*60*60 - 7*60*60)->count();
         # check the current plunders
-        foreach ($self->{ikariam}->{'military'}->{'homeland'}) {
-            $c++ if($_{to} eq $city->cityId);
-            $c++ if($_{from} eq $city->cityId);
+        foreach (@{$self->{ikariam}->{'military'}->{'homeland'}}) {
+            # 出發跟回家都要計算唷
+            $c++ if($_->{to} == $city->cityId || $_->{from} == $city->cityId);
         }
         next if($c >= 4);
 
         # {
         # if(1) {
             my $capture = $city->citylevel * ($city->citylevel - 1) * $sheep->trader_score_secondary / 10000;
-            my $line = sprintf("%d %s [%d,%d] %s (%d) %s/%s", 
+            my $line = sprintf("%d %s [%d,%d] %s (%d) %s/%s. Attacked %d", 
                 $capture, $city->status, 
                 $island->x, $island->y,
                 $city->cityname, $city->cityId,
-                $sheep->name, $sheep->ally);
+                $sheep->name, $sheep->ally, $c);
             printf("%s\n", $line);
         # }
         return $city->cityId;