annotate sheep.pl @ 8:e4b3168d0319

implemented sheep and enemy scripts.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 08 Oct 2008 04:23:01 +0800
parents
children f590b5ea5e55
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;
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
7
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
8 Ikariam::User->has_many(cities => 'Ikariam::Cities');
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
9 Ikariam::User->set_sql(sheeps => qq {
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
10 SELECT user.id
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
11 FROM user, cities, island
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
12 WHERE user.id == cities.user
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
13 AND cities.island == island.id
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
14 AND island.x <= ?
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
15 AND island.x >= ?
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
16 AND island.y <= ?
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
17 AND island.y >= ?
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
18 AND user.score >= 500
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
19 AND user.army_score_main <= 20
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
20 }
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
21 );
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
22
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
23 if($#ARGV != 1) {
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
24 die("Usage: $0 x y\n");
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
25 }
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
26 my ($x, $y) = @ARGV;
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
27
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
28 my @sheeps = Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6));
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
29 my $s;
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
30 foreach my $sheep (sort (@sheeps)) {
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
31 # avoid duplicate
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
32 next if($sheep->id == $s); $s = $sheep->id;
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
33
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
34 # 查聯盟數量
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
35 next if(Ikariam::User->search(allyId => $sheep->allyId)->count() > 3);
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
36
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
37 printf("%s (%s),%d,%d\n", $sheep->name, $sheep->ally, $sheep->score, $sheep->army_score_main);
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
38 # print Dumper($sheep->_data_hash);
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
39 foreach my $c ($sheep->cities) {
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
40 # print Dumper($c->_data_hash);
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
41 my $island = Ikariam::Island->retrieve($c->island);
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
42 printf("%s,%d,(%d,%d),http://s2.ikariam.tw/index.php?view=island&id=%d\n", $c->cityname, $c->citylevel,
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
43 $island->x, $island->y,
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
44 $island->id);
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 printf("\n");
e4b3168d0319 implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
47 }
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 # find_or_create