annotate freeland.pl @ 60:610bbe1824ef

basic Python login script
author kevin@localhost.localdomain
date Tue, 21 Oct 2008 16:14:45 +0800
parents b18369979b58
children f25d13153501
rev   line source
32
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
1 #!/usr/bin/perl
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
2 use strict;
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
3 use Ikariam;
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
4 use Data::Dumper;
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
5
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
6 package main;
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
7
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
8 if($#ARGV != 1) {
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
9 die("Usage: $0 x y\n");
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
10 }
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
11 my ($x, $y) = @ARGV;
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
12
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
13 my @location = (($x + 6), ($x - 6), ($y + 6), ($y - 6));
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
14
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
15 # 找空位
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
16 Ikariam::Cities->set_sql(lamers => qq {
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
17 SELECT cities.cityId
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
18 FROM user, cities
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
19 WHERE user.id == cities.user
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
20 AND user.score <= 1000
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
21 AND cities.status != 'v'
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
22 AND cities.island IN (SELECT island.id FROM island WHERE island.x <= ? AND island.x >= ? AND island.y <= ? AND island.y >= ? AND tradegood == 2)
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
23 }
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
24 );
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
25
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
26 my @islands = Ikariam::Island->retrieve_from_sql(qq{
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
27 tradegood == 2
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
28 AND people < 16
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
29 AND x <= $location[0]
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
30 AND x >= $location[1]
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
31 AND y <= $location[2]
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
32 AND y >= $location[3]
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
33 });
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
34
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
35 if($#islands == -1) {
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
36 my @cities = Ikariam::Cities->search_lamers(@location);
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
37 foreach my $city (@cities) {
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
38 my $island = Ikariam::Island->retrieve($city->island);
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
39 my $user = Ikariam::User->retrieve($city->user);
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
40 printf("%s (%d) \"%s\" %d [%d,%d] http://s2.ikariam.tw/index.php?view=island&id=%d&selectCity=%d\n",
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
41 $user->name, $user->score,
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
42 $city->cityname, $city->citylevel,
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
43 $island->x, $island->y,
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
44 $island->id,
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
45 $city->cityId
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
46 );
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
47 }
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
48 } else {
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
49 foreach my $island (@islands)
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
50 {
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
51 printf("[%d:%d] http://s2.ikariam.tw/index.php?view=island&id=%d%s\n",
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
52 $island->x, $island->y,
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
53 $island->id,
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
54 );
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
55 }
b18369979b58 looking for available land.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
56 }