comparison 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
comparison
equal deleted inserted replaced
7:2040ccc95670 8:e4b3168d0319
1 #!/usr/bin/perl
2 use strict;
3 use Ikariam;
4 use Data::Dumper;
5
6 package main;
7
8 Ikariam::User->has_many(cities => 'Ikariam::Cities');
9 Ikariam::User->set_sql(sheeps => 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.score >= 500
19 AND user.army_score_main <= 20
20 }
21 );
22
23 if($#ARGV != 1) {
24 die("Usage: $0 x y\n");
25 }
26 my ($x, $y) = @ARGV;
27
28 my @sheeps = Ikariam::User->search_sheeps(($x + 6), ($x - 6), ($y + 6), ($y - 6));
29 my $s;
30 foreach my $sheep (sort (@sheeps)) {
31 # avoid duplicate
32 next if($sheep->id == $s); $s = $sheep->id;
33
34 # 查聯盟數量
35 next if(Ikariam::User->search(allyId => $sheep->allyId)->count() > 3);
36
37 printf("%s (%s),%d,%d\n", $sheep->name, $sheep->ally, $sheep->score, $sheep->army_score_main);
38 # print Dumper($sheep->_data_hash);
39 foreach my $c ($sheep->cities) {
40 # print Dumper($c->_data_hash);
41 my $island = Ikariam::Island->retrieve($c->island);
42 printf("%s,%d,(%d,%d),http://s2.ikariam.tw/index.php?view=island&id=%d\n", $c->cityname, $c->citylevel,
43 $island->x, $island->y,
44 $island->id);
45 }
46 printf("\n");
47 }
48
49 # find_or_create