Mercurial > eagle-eye
diff sheep.pl @ 10:f590b5ea5e55
fixed bug of sheep.pl
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Wed, 08 Oct 2008 09:55:43 +0800 |
parents | e4b3168d0319 |
children | e21b8f303c6a |
line wrap: on
line diff
--- a/sheep.pl Wed Oct 08 04:30:32 2008 +0800 +++ b/sheep.pl Wed Oct 08 09:55:43 2008 +0800 @@ -6,6 +6,18 @@ package main; Ikariam::User->has_many(cities => 'Ikariam::Cities'); +Ikariam::User->set_sql(inactivity => 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.status = 'i' + } +); Ikariam::User->set_sql(sheeps => qq { SELECT user.id FROM user, cities, island @@ -16,7 +28,7 @@ AND island.y <= ? AND island.y >= ? AND user.score >= 500 - AND user.army_score_main <= 20 + AND user.army_score_main <= 25 } ); @@ -25,25 +37,43 @@ } my ($x, $y) = @ARGV; -my @sheeps = Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6)); -my $s; -foreach my $sheep (sort (@sheeps)) { - # avoid duplicate - next if($sheep->id == $s); $s = $sheep->id; +listSheeps(Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6))); +listSheeps(Ikariam::User->search_inactivity(($x + 6), ($x - 6), ($y + 6), ($y - 6))); + + +sub listSheeps +{ + my @sheeps = @_; - # 查聯盟數量 - next if(Ikariam::User->search(allyId => $sheep->allyId)->count() > 3); + my $s; + foreach my $sheep (sort (@sheeps)) { + # avoid duplicate + next if($sheep->id == $s); $s = $sheep->id; + + # 假期模式 + next if($sheep->status eq 'v'); - printf("%s (%s),%d,%d\n", $sheep->name, $sheep->ally, $sheep->score, $sheep->army_score_main); - # print Dumper($sheep->_data_hash); - foreach my $c ($sheep->cities) { - # print Dumper($c->_data_hash); - my $island = Ikariam::Island->retrieve($c->island); - printf("%s,%d,(%d,%d),http://s2.ikariam.tw/index.php?view=island&id=%d\n", $c->cityname, $c->citylevel, - $island->x, $island->y, - $island->id); + # 查聯盟數量 + my $members = 1; + unless ($sheep->status eq 'i') { + $members = Ikariam::User->search(allyId => $sheep->allyId)->count(); + next if($members > 3); + } + + # print Dumper($sheep->_data_hash); + foreach my $c ($sheep->cities) { + # print Dumper($c->_data_hash); + + print("!") if ($c->status eq 'i'); + + printf("%d,%d,%d,%s of %s (%d),", $sheep->trader_score_secondary, $sheep->score, $sheep->army_score_main, $sheep->name, $sheep->ally, $members); + + my $island = Ikariam::Island->retrieve($c->island); + printf("%s,%d,[%d,%d],http://s2.ikariam.tw/index.php?view=island&id=%d\n", $c->cityname, $c->citylevel, + $island->x, $island->y, + $island->id); + } + printf("\n"); } - printf("\n"); } - # find_or_create