Mercurial > eagle-eye
comparison scores.pl @ 7:2040ccc95670
implemented scores collection.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Wed, 08 Oct 2008 02:50:19 +0800 |
parents | dbb97c4265ba |
children | e4b3168d0319 |
comparison
equal
deleted
inserted
replaced
6:2975a94aa7a2 | 7:2040ccc95670 |
---|---|
8 sub saveUser | 8 sub saveUser |
9 { | 9 { |
10 my $users = shift; | 10 my $users = shift; |
11 foreach my $user (values(%{$users})) | 11 foreach my $user (values(%{$users})) |
12 { | 12 { |
13 printf("Saving %s\n", $user->{'name'}); | |
13 if(my $c = Ikariam::Users->retrieve($user->{id})) | 14 if(my $c = Ikariam::Users->retrieve($user->{id})) |
14 { | 15 { |
15 foreach my $i (keys(%$user)) { | 16 foreach my $i (keys(%$user)) { |
16 eval($c->$i($user->{$i})); | 17 eval($c->$i($user->{$i})); |
17 } | 18 } |
22 } | 23 } |
23 } | 24 } |
24 } | 25 } |
25 | 26 |
26 my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d"); | 27 my $i = new Ikariam("s2.ikariam.tw", "chihchun", "c795d57d"); |
27 # $i->login; | 28 $i->login; |
29 | |
28 if($#ARGV == 0) { | 30 if($#ARGV == 0) { |
29 my $users; | 31 my $users; |
30 foreach my $x (qw/score army_score_main trader_score_secondary/) | 32 foreach my $x (qw/score army_score_main trader_score_secondary/) |
31 { | 33 { |
32 $users = $i->viewScore($x, $ARGV[0], 0); | 34 $users = $i->viewScore($x, $ARGV[0], 0); |
33 saveUser($users); | 35 saveUser($users); |
34 } | 36 } |
37 } elsif ($#ARGV == 1) { | |
38 # search the islands and cities nearby | |
39 my ($x, $y) = @ARGV; | |
40 my $offset = 5; | |
41 | |
42 Ikariam::Island->has_many(cities => 'Ikariam::Cities'); | |
43 | |
44 my @islands = Ikariam::Island->retrieve_from_sql( | |
45 "x >= " . ($x - $offset) . " AND " . " x <= " . ($x + $offset) . | |
46 " AND " . | |
47 "y >= " . ($y - $offset) . " AND " . " y <= " . ($y + $offset) | |
48 ); | |
49 | |
50 my %owners; | |
51 foreach my $island (@islands) | |
52 { | |
53 my @cities = $island->cities; | |
54 foreach my $city (@cities) | |
55 { | |
56 $owners{$city->owner} += 1; | |
57 } | |
58 } | |
59 | |
60 | |
61 foreach my $o (keys(%owners)) | |
62 { | |
63 foreach my $x (qw/score army_score_main trader_score_secondary/) | |
64 { | |
65 my $users = $i->viewScore($x, $o, 0); | |
66 saveUser($users); | |
67 } | |
68 } | |
35 } else { | 69 } else { |
36 my $users = $i->viewScore('army_score_main'); | 70 # my $users = $i->viewScore('army_score_main'); |
37 saveUser($users); | 71 # saveUser($users); |
38 # die("Usage: $0 nickname\n"); | 72 die("Usage: $0 nickname\n"); |
39 } | 73 } |
40 | 74 |
41 # highscoreType | 75 # highscoreType |
42 # <option value="score">總積分</option> | 76 # <option value="score">總積分</option> |
43 # <option value="building_score_main">建築大師</option> | 77 # <option value="building_score_main">建築大師</option> |