Mercurial > eagle-eye
annotate scores.pl @ 318:e5e25d4a2c2f
merged
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Mon, 12 Jan 2009 22:26:48 +0800 |
parents | 53c87400183f |
children | e551351b18de |
rev | line source |
---|---|
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1 #!/usr/bin/perl |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
2 use strict; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
3 use Ikariam; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
4 use Data::Dumper; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
5 |
12
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
6 # highscoreType |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
7 # <option value="score">總積分</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
8 # <option value="building_score_main">建築大師</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
9 # <option value="building_score_secondary">建築等級</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
10 # <option value="research_score_main">科學巨人</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
11 # <option value="research_score_secondary">研究等級</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
12 # <option value="army_score_main" selected="selected">戰爭將軍</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
13 # <option value="trader_score_secondary">黃金存量</option> |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
14 # my $users = $i->viewScore('score', 'chihchun', '0'); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
15 |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
16 package main; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
17 |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
18 sub saveUser |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
19 { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
20 my $users = shift; |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
7
diff
changeset
|
21 |
91
53c87400183f
rewrite viewScore with Extractor.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
41
diff
changeset
|
22 foreach my $user (values(%{$users})) { |
7
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
23 printf("Saving %s\n", $user->{'name'}); |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
7
diff
changeset
|
24 if(my $c = Ikariam::User->retrieve($user->{id})) |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
25 { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
26 foreach my $i (keys(%$user)) { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
27 eval($c->$i($user->{$i})); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
28 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
29 $c->autoupdate(1); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
30 $c->update(); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
31 } else { |
8
e4b3168d0319
implemented sheep and enemy scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
7
diff
changeset
|
32 Ikariam::User->insert($user); |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
33 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
34 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
35 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
36 |
41
5849b6fdc76c
removed my password from scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
13
diff
changeset
|
37 my $i = new Ikariam($::server, $::user, $::pass); |
12
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
38 $i->login; |
7
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
39 |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
40 if($#ARGV == 0) { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
41 my $users; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
42 foreach my $x (qw/score army_score_main trader_score_secondary/) |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
43 { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
44 $users = $i->viewScore($x, $ARGV[0], 0); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
45 saveUser($users); |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
46 } |
7
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
47 } elsif ($#ARGV == 1) { |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
48 # search the islands and cities nearby |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
49 my ($x, $y) = @ARGV; |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
50 my $offset = 5; |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
51 |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
52 Ikariam::Island->has_many(cities => 'Ikariam::Cities'); |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
53 |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
54 my @islands = Ikariam::Island->retrieve_from_sql( |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
55 "x >= " . ($x - $offset) . " AND " . " x <= " . ($x + $offset) . |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
56 " AND " . |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
57 "y >= " . ($y - $offset) . " AND " . " y <= " . ($y + $offset) |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
58 ); |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
59 |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
60 my %owners; |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
61 foreach my $island (@islands) |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
62 { |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
63 my @cities = $island->cities; |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
64 foreach my $city (@cities) |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
65 { |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
66 $owners{$city->owner} += 1; |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
67 } |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
68 } |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
69 |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
70 foreach my $o (keys(%owners)) |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
71 { |
9
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
72 foreach my $type (qw/score army_score_main trader_score_secondary/) |
7
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
73 { |
9
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
74 my $users = $i->viewScore($type, $o, 0); |
7
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
75 saveUser($users); |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
76 } |
2040ccc95670
implemented scores collection.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
5
diff
changeset
|
77 } |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
78 } else { |
12
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
79 if(0) { |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
80 # Update all the users |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
81 my @users = Ikariam::User->retrieve_all(); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
82 foreach my $user (@users) |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
83 { |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
84 printf("%s\n", $user->name); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
85 foreach my $type (qw/score army_score_main trader_score_secondary/) |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
86 { |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
87 my $users = $i->viewScore($type, $user->name, 0); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
88 saveUser($users); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
89 } |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
90 } |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
91 } else { |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
92 # Update owner of cities |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
93 my @cities = Ikariam::Cities->retrieve_all(); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
94 foreach my $city (@cities) |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
95 { |
13
bb6eebd349fc
removed debug message
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
12
diff
changeset
|
96 # printf("%s\n", $city->owner); |
12
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
97 foreach my $type (qw/score army_score_main trader_score_secondary/) |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
98 { |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
99 my $users = $i->viewScore($type, $city->owner, 0); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
100 saveUser($users); |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
101 } |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
102 } |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
103 } |
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
104 # die("Usage: $0 nickname\nUsage: $0 x y"); |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
105 } |
12
0aeb0fe59257
added update owner of cities
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
106 $i->logout; |