Mercurial > eagle-eye
comparison 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 |
comparison
equal
deleted
inserted
replaced
23:54ab0becd730 | 24:93d4e6ffe330 |
---|---|
17 AND island.y <= ? | 17 AND island.y <= ? |
18 AND island.y >= ? | 18 AND island.y >= ? |
19 AND cities.status = 'i' | 19 AND cities.status = 'i' |
20 } | 20 } |
21 ); | 21 ); |
22 #Ikariam::User->set_sql(sheeps => qq { | |
23 # SELECT user.id | |
24 # FROM user, cities, island | |
25 # WHERE user.id == cities.user | |
26 # AND cities.island == island.id | |
27 # AND island.x <= ? | |
28 # AND island.x >= ? | |
29 # AND island.y <= ? | |
30 # AND island.y >= ? | |
31 # AND user.trader_score_secondary >= 50000 | |
32 # AND user.army_score_main <= 100 | |
33 # } | |
34 #); | |
22 | 35 |
23 Ikariam::User->set_sql(sheeps => qq { | 36 Ikariam::User->set_sql(sheeps => qq { |
24 SELECT user.id | 37 SELECT user.id |
25 FROM user, cities, island | 38 FROM user, cities |
26 WHERE user.id == cities.user | 39 WHERE user.id == cities.user |
27 AND cities.island == island.id | 40 AND user.trader_score_secondary >= 50000 |
28 AND island.x <= ? | 41 AND user.army_score_main <= 40 |
29 AND island.x >= ? | 42 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? ) |
30 AND island.y <= ? | |
31 AND island.y >= ? | |
32 AND user.score >= 500 | |
33 AND user.army_score_main <= 25 | |
34 } | 43 } |
35 ); | 44 ); |
36 | |
37 | 45 |
38 if($#ARGV != 1) { | 46 if($#ARGV != 1) { |
39 die("Usage: $0 x y\n"); | 47 die("Usage: $0 x y\n"); |
40 } | 48 } |
41 my ($x, $y) = @ARGV; | 49 my ($x, $y) = @ARGV; |
44 # listSheeps(Ikariam::User->search_inactivity(($x + 6), ($x - 6), ($y + 6), ($y - 6))); | 52 # listSheeps(Ikariam::User->search_inactivity(($x + 6), ($x - 6), ($y + 6), ($y - 6))); |
45 | 53 |
46 sub listSheeps | 54 sub listSheeps |
47 { | 55 { |
48 my @sheeps = @_; | 56 my @sheeps = @_; |
57 my %results; | |
49 | 58 |
50 my $s; | 59 my $s; |
51 foreach my $sheep (sort (@sheeps)) { | 60 foreach my $sheep (sort (@sheeps)) { |
52 # avoid duplicate | 61 # avoid duplicate |
53 next if($sheep->id == $s); $s = $sheep->id; | 62 next if($sheep->id == $s); $s = $sheep->id; |
54 | |
55 | 63 |
56 # 查聯盟數量 | 64 # 查聯盟數量 |
57 my $members = 1; | 65 my $members = 1; |
58 unless ($sheep->allyId == '0') { | 66 unless ($sheep->allyId == '0') { |
59 $members = Ikariam::User->search(allyId => $sheep->allyId)->count(); | 67 $members = Ikariam::User->search(allyId => $sheep->allyId)->count(); |
60 } | 68 } |
61 | 69 |
62 foreach my $c ($sheep->cities) { | 70 foreach my $c ($sheep->cities) { |
63 | 71 my $line = ""; |
64 # 假期模式 | 72 # Ignore 假期模式 |
65 next if($c->status eq 'v'); | 73 next if($c->status eq 'v'); |
66 | 74 |
67 unless($c->status eq 'i') { | 75 unless($c->status eq 'i') { |
68 next if($members > 3); | 76 next if($members > 3); |
69 } | 77 } |
70 | 78 |
71 printf("%d %s %d,%d,%s of %s (%d),", | 79 my $island = Ikariam::Island->retrieve($c->island); |
72 $sheep->trader_score_secondary, $c->status, $sheep->score, $sheep->army_score_main, $sheep->name, $sheep->ally, $members); | |
73 | 80 |
74 my $island = Ikariam::Island->retrieve($c->island); | 81 # 所得金錢 = 對方城鎮等級x(對方城鎮等級-1)x對方金錢/10000 |
75 printf("%s %d [%d,%d] %s http://s2.ikariam.tw/index.php?view=island&id=%d\n", $c->cityname, $c->citylevel, | 82 my $robbery = $c->citylevel * ($c->citylevel - 1) * $sheep->trader_score_secondary / 10000; |
83 | |
84 next if($robbery < 2000); | |
85 $line = sprintf("%d %s army %d %s/%s(%d),", | |
86 $robbery, | |
87 $c->status, $sheep->army_score_main, $sheep->name, $sheep->ally, $members); | |
88 | |
89 $line .= sprintf("\"%s\" %d [%d,%d] %s http://s2.ikariam.tw/index.php?view=island&id=%d\n", | |
90 $c->cityname, $c->citylevel, | |
76 $island->x, $island->y, | 91 $island->x, $island->y, |
77 $tradegoodText[$island->tradegood], | 92 $tradegoodText[$island->tradegood], |
78 $island->id); | 93 $island->id); |
94 | |
95 printf("%s", $line); | |
79 } | 96 } |
80 printf("\n"); | |
81 } | 97 } |
82 } | 98 } |
83 # find_or_create | 99 # find_or_create |