annotate scan.pl @ 232:978a949602e5

Auto-update Scientists numbers for Academy. Refined the rules for safehouse, the safe house must be same or higher level then Town Hall. Make people very happy, when the townHall is less then 16. Build museum first then tavern THG: changed warfare.pl
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Thu, 06 Nov 2008 20:31:05 +0800
parents 541bc1fba446
children 1a7b2d42fcbf
rev   line source
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
1 #!/usr/bin/perl
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
2 use strict;
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
3 use Data::Dumper;
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
4 use Ikariam;
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
5
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
6 package main;
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
7
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
8 sub saveCities
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
9 {
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
10 my ($island, @cities) = @_;
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
11
48
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
12 if ($#cities == -1) {
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
13 warn ("empty cities list.\n");
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
14 return;
96ee35378696 modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 41
diff changeset
15 }
25
51a35c3d057e cached 12 hours for user account.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 22
diff changeset
16
121
0bab14dddf60 fixed the timestamp for scanning
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 99
diff changeset
17 foreach my $h_city (@cities) {
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
18 $h_city->{island} = $island;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
19 $h_city->{'time'} = time;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
20 my $c = Ikariam::Cities->retrieve($h_city->{cityId});
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
21 if(defined($c)) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
22 foreach (keys(%$h_city)) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
23 $c->set($_ => $h_city->{$_});
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
24 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
25 } else {
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
26 $c = Ikariam::Cities->insert($h_city);
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
27 }
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
28 $c->update();
36
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
29
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
30 my $user = Ikariam::User->retrieve($h_city->{'user'});
211
541bc1fba446 update very 30 minutes.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 206
diff changeset
31 next if (defined($user) && defined($user->time) && $user->time le (time - 30*60*1));
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
32
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
33 saveUser($h_city->{owner});
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
34 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
35 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
36
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
37 sub saveUser
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
38 {
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
39 my $userName = shift;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
40 my $users;
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
41
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
42 foreach my $x (qw/score army_score_main trader_score_secondary/) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
43 $users = $::i->viewScore($x, $userName, 0);
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
44
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
45 foreach my $h_user (values(%{$users})) {
88
0fa9cd836e1e rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 48
diff changeset
46 printf("Saving user %s\n", $h_user->{'name'});
0fa9cd836e1e rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 48
diff changeset
47 $h_user->{'time'} = time;
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
48
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
49 my $user = Ikariam::User->retrieve($h_user->{'id'});
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
50 if(defined($user)) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
51 foreach (keys(%$h_user)) { $user->set($_ => $h_user->{$_}); }
88
0fa9cd836e1e rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 48
diff changeset
52 } else {
0fa9cd836e1e rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 48
diff changeset
53 $user = Ikariam::User->insert($h_user);
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
54 }
88
0fa9cd836e1e rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 48
diff changeset
55 $user->update();
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
56 saveAlly($h_user->{allyId});
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
57 }
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
58 }
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
59 }
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
60
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
61 sub saveAlly
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
62 {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
63 my $allyId = shift;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
64 return unless (defined($allyId) && $allyId ne '0');
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
65
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
66 # Save for member of ally
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
67 my $ally = Ikariam::Ally->retrieve($allyId);
211
541bc1fba446 update very 30 minutes.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 206
diff changeset
68 if(!defined($ally) || $ally->time le (time - 30*60*1)) {
98
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
69 my $h_ally = $::i->viewAlly($allyId);
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
70 $h_ally->{'time'} = time;
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
71 if(defined($ally)) {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
72 foreach (keys(%$h_ally)) { $ally->set($_ => $h_ally->{$_}); }
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
73 } else {
34749e907405 we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 89
diff changeset
74 $ally = Ikariam::Ally->insert($h_ally);
14
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
75 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
76 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
77 }
8b7bc598ba06 we now also save user's profile when scanning islands.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 10
diff changeset
78
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
79 sub saveIslands {
141
0da6658697df fixed the param of islands
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 140
diff changeset
80 my @islands = @_;
18
fd44e3a1f800 fixed the cache.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 16
diff changeset
81
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
82 foreach my $h_island (@islands)
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
83 {
206
b7af307a222d added build safehouse
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 141
diff changeset
84 # printf("checking island %d\n", $h_island->{id});
0
abaee7064429 new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff changeset
85
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
86 my $island;
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
87 if($island = Ikariam::Island->retrieve($h_island->{id})) {
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
88 foreach my $i (keys(%$h_island)) {
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
89 $island->set($i => $h_island->{$i});
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
90 }
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
91 } else {
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
92 $island = Ikariam::Island->insert($h_island);
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
93 }
16
59f2c435760c implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 14
diff changeset
94
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
95 # scanning the island
211
541bc1fba446 update very 30 minutes.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 206
diff changeset
96 if($island->time le (time - 30*60*6))
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
97 {
232
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
98 my @cities = $::i->viewIsland($h_island->{id});
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
99 saveCities($h_island->{id}, @cities);
36
704d76b67670 fixed the island cache problem
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 25
diff changeset
100
140
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
101 $island->set('time', time);
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
102 }
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
103 $island->update();
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
104
124fc7abda39 scan all the islands nearby our own cities.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 123
diff changeset
105 }
10
f590b5ea5e55 fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 8
diff changeset
106 }
232
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
107
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
108
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
109 local $SIG{ALRM} = sub { die "timeout\n" };
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
110 alarm 3;
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
111 our $i = new Ikariam($::server, $::user, $::pass);
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
112
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
113 if($#ARGV == 1) {
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
114 $i->login;
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
115 my @islands = $i->viewWorldMap($ARGV[0], $ARGV[1]);
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
116 saveIslands(@islands);
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
117 $i->logout;
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
118 } elsif($#ARGV == 0) {
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
119 $i->login;
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
120 my $island = $ARGV[0];
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
121 my @cities = $i->viewIsland($island);
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
122 saveCities($island, @cities);
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
123 $i->logout;
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
124 } elsif($#ARGV == -1) {
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
125 $i->login;
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
126 my $cities = $i->check;
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
127 # random
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
128 foreach my $cityId (keys(%$cities)) {
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
129 printf("%s %s\n", $cities->{$cityId}->{island}->{x}, $cities->{$cityId}->{island}->{y});
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
130 my @islands = $i->viewWorldMap( $cities->{$cityId}->{island}->{x}, $cities->{$cityId}->{island}->{y});
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
131 saveIslands(@islands);
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
132 }
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
133 $i->logout;
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
134 } else {
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
135 die("Usage: $0\nUsage: $0 x y\n");
978a949602e5 Auto-update Scientists numbers for Academy.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents: 211
diff changeset
136 }