Mercurial > eagle-eye
comparison 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 |
comparison
equal
deleted
inserted
replaced
9:ae412d1f7761 | 10:f590b5ea5e55 |
---|---|
4 use Data::Dumper; | 4 use Data::Dumper; |
5 | 5 |
6 package main; | 6 package main; |
7 | 7 |
8 Ikariam::User->has_many(cities => 'Ikariam::Cities'); | 8 Ikariam::User->has_many(cities => 'Ikariam::Cities'); |
9 Ikariam::User->set_sql(inactivity => qq { | |
10 SELECT user.id | |
11 FROM user, cities, island | |
12 WHERE user.id == cities.user | |
13 AND cities.island == island.id | |
14 AND island.x <= ? | |
15 AND island.x >= ? | |
16 AND island.y <= ? | |
17 AND island.y >= ? | |
18 AND user.status = 'i' | |
19 } | |
20 ); | |
9 Ikariam::User->set_sql(sheeps => qq { | 21 Ikariam::User->set_sql(sheeps => qq { |
10 SELECT user.id | 22 SELECT user.id |
11 FROM user, cities, island | 23 FROM user, cities, island |
12 WHERE user.id == cities.user | 24 WHERE user.id == cities.user |
13 AND cities.island == island.id | 25 AND cities.island == island.id |
14 AND island.x <= ? | 26 AND island.x <= ? |
15 AND island.x >= ? | 27 AND island.x >= ? |
16 AND island.y <= ? | 28 AND island.y <= ? |
17 AND island.y >= ? | 29 AND island.y >= ? |
18 AND user.score >= 500 | 30 AND user.score >= 500 |
19 AND user.army_score_main <= 20 | 31 AND user.army_score_main <= 25 |
20 } | 32 } |
21 ); | 33 ); |
22 | 34 |
23 if($#ARGV != 1) { | 35 if($#ARGV != 1) { |
24 die("Usage: $0 x y\n"); | 36 die("Usage: $0 x y\n"); |
25 } | 37 } |
26 my ($x, $y) = @ARGV; | 38 my ($x, $y) = @ARGV; |
27 | 39 |
28 my @sheeps = Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6)); | 40 listSheeps(Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6))); |
29 my $s; | 41 listSheeps(Ikariam::User->search_inactivity(($x + 6), ($x - 6), ($y + 6), ($y - 6))); |
30 foreach my $sheep (sort (@sheeps)) { | |
31 # avoid duplicate | |
32 next if($sheep->id == $s); $s = $sheep->id; | |
33 | 42 |
34 # 查聯盟數量 | |
35 next if(Ikariam::User->search(allyId => $sheep->allyId)->count() > 3); | |
36 | 43 |
37 printf("%s (%s),%d,%d\n", $sheep->name, $sheep->ally, $sheep->score, $sheep->army_score_main); | 44 sub listSheeps |
38 # print Dumper($sheep->_data_hash); | 45 { |
39 foreach my $c ($sheep->cities) { | 46 my @sheeps = @_; |
40 # print Dumper($c->_data_hash); | 47 |
41 my $island = Ikariam::Island->retrieve($c->island); | 48 my $s; |
42 printf("%s,%d,(%d,%d),http://s2.ikariam.tw/index.php?view=island&id=%d\n", $c->cityname, $c->citylevel, | 49 foreach my $sheep (sort (@sheeps)) { |
43 $island->x, $island->y, | 50 # avoid duplicate |
44 $island->id); | 51 next if($sheep->id == $s); $s = $sheep->id; |
52 | |
53 # 假期模式 | |
54 next if($sheep->status eq 'v'); | |
55 | |
56 # 查聯盟數量 | |
57 my $members = 1; | |
58 unless ($sheep->status eq 'i') { | |
59 $members = Ikariam::User->search(allyId => $sheep->allyId)->count(); | |
60 next if($members > 3); | |
61 } | |
62 | |
63 # print Dumper($sheep->_data_hash); | |
64 foreach my $c ($sheep->cities) { | |
65 # print Dumper($c->_data_hash); | |
66 | |
67 print("!") if ($c->status eq 'i'); | |
68 | |
69 printf("%d,%d,%d,%s of %s (%d),", $sheep->trader_score_secondary, $sheep->score, $sheep->army_score_main, $sheep->name, $sheep->ally, $members); | |
70 | |
71 my $island = Ikariam::Island->retrieve($c->island); | |
72 printf("%s,%d,[%d,%d],http://s2.ikariam.tw/index.php?view=island&id=%d\n", $c->cityname, $c->citylevel, | |
73 $island->x, $island->y, | |
74 $island->id); | |
75 } | |
76 printf("\n"); | |
45 } | 77 } |
46 printf("\n"); | |
47 } | 78 } |
48 | |
49 # find_or_create | 79 # find_or_create |