Mercurial > eagle-eye
annotate sheep.pl @ 45:4d59ba5905f6
addressed the modules you need to install
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Fri, 17 Oct 2008 12:55:59 +0800 |
parents | 5849b6fdc76c |
children | d2ac1e198ce4 |
rev | line source |
---|---|
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1 #!/usr/bin/perl |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
2 use strict; |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
3 use Ikariam; |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
4 use Data::Dumper; |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
5 |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
6 package main; |
18 | 7 my @tradegoodText = qw/NULL 葡萄酒 大理石 水晶 硫磺/; |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
8 |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
9 Ikariam::User->has_many(cities => 'Ikariam::Cities'); |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
10 Ikariam::User->set_sql(inactivity => qq { |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
11 SELECT user.id |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
12 FROM user, cities, island |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
13 WHERE user.id == cities.user |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
14 AND cities.island == island.id |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
15 AND island.x <= ? |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
16 AND island.x >= ? |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
17 AND island.y <= ? |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
18 AND island.y >= ? |
15 | 19 AND cities.status = 'i' |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
20 } |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
21 ); |
24 | 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
552528bb4917
refined the cache timeout is 12 hours.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
18
diff
changeset
|
35 |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
36 Ikariam::User->set_sql(sheeps => qq { |
24 | 37 SELECT user.id |
38 FROM user, cities | |
39 WHERE user.id == cities.user | |
40 AND user.trader_score_secondary >= 50000 | |
41
5849b6fdc76c
removed my password from scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
33
diff
changeset
|
41 AND user.army_score_main <= 100 |
24 | 42 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? ) |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
43 } |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
44 ); |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
45 |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
46 if($#ARGV != 1) { |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
47 die("Usage: $0 x y\n"); |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
48 } |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
49 my ($x, $y) = @ARGV; |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
50 |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
51 listSheeps(Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6))); |
15 | 52 # listSheeps(Ikariam::User->search_inactivity(($x + 6), ($x - 6), ($y + 6), ($y - 6))); |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
53 |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
54 sub listSheeps |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
55 { |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
56 my @sheeps = @_; |
24 | 57 my %results; |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
58 |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
59 my $s; |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
60 foreach my $sheep (sort (@sheeps)) { |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
61 # avoid duplicate |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
62 next if($sheep->id == $s); $s = $sheep->id; |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
63 |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
64 # 查聯盟數量 |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
65 my $members = 1; |
15 | 66 unless ($sheep->allyId == '0') { |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
67 $members = Ikariam::User->search(allyId => $sheep->allyId)->count(); |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
68 } |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
69 |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
70 foreach my $c ($sheep->cities) { |
24 | 71 my $line = ""; |
72 # Ignore 假期模式 | |
15 | 73 next if($c->status eq 'v'); |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
74 |
15 | 75 unless($c->status eq 'i') { |
76 next if($members > 3); | |
77 } | |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
78 |
24 | 79 my $island = Ikariam::Island->retrieve($c->island); |
80 | |
81 # 所得金錢 = 對方城鎮等級x(對方城鎮等級-1)x對方金錢/10000 | |
82 my $robbery = $c->citylevel * ($c->citylevel - 1) * $sheep->trader_score_secondary / 10000; | |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
83 |
24 | 84 next if($robbery < 2000); |
33
d183277b4d93
refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
24
diff
changeset
|
85 |
24 | 86 $line = sprintf("%d %s army %d %s/%s(%d),", |
87 $robbery, | |
88 $c->status, $sheep->army_score_main, $sheep->name, $sheep->ally, $members); | |
89 | |
33
d183277b4d93
refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
24
diff
changeset
|
90 $line .= sprintf("\"%s\" %d [%d,%d] %s http://s2.ikariam.tw/index.php?view=island&id=%d&selectCity=%d\n", |
24 | 91 $c->cityname, $c->citylevel, |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
92 $island->x, $island->y, |
18 | 93 $tradegoodText[$island->tradegood], |
33
d183277b4d93
refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
24
diff
changeset
|
94 $island->id, |
d183277b4d93
refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
24
diff
changeset
|
95 $c->cityId |
d183277b4d93
refined the output message.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
24
diff
changeset
|
96 ); |
24 | 97 |
98 printf("%s", $line); | |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
99 } |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
100 } |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
101 } |
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
102 # find_or_create |