Mercurial > eagle-eye
annotate Ikariam.pm @ 183:2362c8c8909e
implemented military builder.
author | "Rex Tsai <chihchun@kalug.linux.org.tw>" |
---|---|
date | Sun, 02 Nov 2008 21:14:55 +0800 |
parents | 0cfc7a19a4d2 |
children | c6c6db6eea76 |
rev | line source |
---|---|
41
5849b6fdc76c
removed my password from scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
37
diff
changeset
|
1 BEGIN { |
48
96ee35378696
modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
41
diff
changeset
|
2 foreach (((getpwuid($<))[7], $ENV{HOME}, $ENV{LOGDIR}, ".")) { |
96ee35378696
modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
41
diff
changeset
|
3 require "$_/.eagleeye.pm" if (-f "$_/.eagleeye.pm"); |
96ee35378696
modified for searching configuration files
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
41
diff
changeset
|
4 } |
41
5849b6fdc76c
removed my password from scripts.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
37
diff
changeset
|
5 } |
2
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
6 |
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
7 use Class::DBI::AutoLoader ( |
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
8 dsn => 'dbi:SQLite:dbname=ikariam.sqlite', |
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
9 options => { RaiseError => 1 }, |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
10 tables => ['cities', 'island', 'user', 'ally', 'report'], |
2
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
11 use_base => 'Class::DBI::SQLite', |
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
12 namespace => 'Ikariam', |
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
13 ); |
0fb73a7a0b94
ok, we done basic island scanning functions.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
1
diff
changeset
|
14 |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
15 package Ikariam::Extractor; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
16 use strict; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
17 use Data::Dumper; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
18 use XML::LibXML; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
19 use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
20 use Carp; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
21 use utf8; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
22 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
23 sub new { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
24 Carp::croak("Options should be key/value pairs, not hash reference") if ref($_[1]) eq 'HASH'; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
25 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
26 my($class, %conf) = @_; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
27 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
28 my $self = bless { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
29 doc => undef, |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
30 gzip => 1, |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
31 }, $class; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
32 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
33 $self->{gzip} = $conf{'gzip'} if(defined($conf{'gzip'})); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
34 $self->parse($conf{'content'}) if(defined($conf{'content'})); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
35 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
36 return $self; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
37 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
38 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
39 sub parse { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
40 my ($self, $content) = @_; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
41 my $string; |
110
279a000eb3b0
fixed encoding issue of LibXML
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
106
diff
changeset
|
42 my $parser = XML::LibXML->new('1.0','UTF-8'); |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
43 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
44 if($self->{gzip} == 1) { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
45 gunzip \$content => \$string |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
46 or die "gunzip failed: $GunzipError\n"; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
47 } else { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
48 $string = $content; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
49 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
50 |
117
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
51 # dirty hack for stupid highScore search function. |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
52 $string =~ s/name="searchUser" value=".*?"/name="searchUser" value=""/; |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
53 |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
54 $self->{doc} = $parser->parse_html_string ($string, { suppress_errors => 1, encoding => 'UTF-8' }); |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
55 return; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
56 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
57 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
58 # find($XPathQuery); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
59 sub find { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
60 my $self = shift; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
61 my $query = shift; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
62 my $out = []; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
63 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
64 my $result = $self->{doc}->find($query); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
65 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
66 return undef unless defined($result); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
67 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
68 if ( $result->isa( 'XML::LibXML::NodeList' ) ) { |
150
fab1593cadf1
fixed the combat reading issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
148
diff
changeset
|
69 if($result->size() == 0) { |
fab1593cadf1
fixed the combat reading issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
148
diff
changeset
|
70 return undef unless wantarray; |
fab1593cadf1
fixed the combat reading issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
148
diff
changeset
|
71 return (); |
fab1593cadf1
fixed the combat reading issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
148
diff
changeset
|
72 } |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
73 foreach ( @$result ) { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
74 # $_ is XML::LibXML::Element, XML::LibXML::Node |
92
bcd2e32cfabb
fixed the user name encoding issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
91
diff
changeset
|
75 my $literal = $_->to_literal(); |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
76 utf8::encode($literal); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
77 # warn $_->toString(1) , "\n"; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
78 return $literal unless wantarray; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
79 push( @$out, $literal); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
80 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
81 } else { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
82 Carp::croak("Unsupported data type"); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
83 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
84 # TODO |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
85 # XML::LibXML::Literal |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
86 # XML::LibXML::Boolean |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
87 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
88 return @$out; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
89 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
90 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
91 1; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
92 |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
93 package Ikariam; |
27
dd85b55eec2a
implemented basic inference engine.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
26
diff
changeset
|
94 use strict; |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
95 use Data::Dumper; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
96 use LWP; |
154
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
97 |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
98 use HTTP::Cookies; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
99 use WWW::Mechanize; |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
100 use XML::LibXML qw(:encoding); |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
101 use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ; |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
102 use POSIX; |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
103 use utf8; |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
104 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
105 sub new |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
106 { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
107 my ($class, $server, $user, $pass) = @_; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
108 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
109 my $self = |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
110 { |
16
59f2c435760c
implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
111 mech => WWW::Mechanize->new( |
59f2c435760c
implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
112 agent => "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092816 Iceweasel/3.0.1 (Debian-3.0.1-1)", |
59f2c435760c
implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
113 timeout => 10, |
59f2c435760c
implemented cached by timing.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
10
diff
changeset
|
114 ), |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
115 server => $server, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
116 user => $user, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
117 pass => $pass, |
117
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
118 debug => undef, |
54
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
119 buildingIDs => { |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
120 townHall => 0, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
121 townhall => 0, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
122 port => 3, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
123 academy => 4, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
124 shipyard => 5, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
125 barracks => 6, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
126 warehouse => 7, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
127 wall => 8, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
128 tavern => 9, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
129 museum => 10, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
130 palace => 11, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
131 embassy => 12, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
132 branchOffice => 13, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
133 workshop => 15, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
134 'workshop-army' => 15, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
135 'workshop-fleet' => 15, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
136 safehouse => 16, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
137 palaceColony => 17, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
138 resource => 1, |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
139 tradegood => 2 |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
140 } |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
141 }; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
142 |
54
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
143 |
117
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
144 # if debug |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
145 LWP::Debug::level('+trace'); |
117
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
146 |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
147 $self->{mech}->cookie_jar(HTTP::Cookies->new(file => "/tmp/ikariam-cookies.txt", autosave => 1)); |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
148 $self->{mech}->default_headers->push_header('Accept-Encoding', 'deflate'); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
149 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
150 return bless $self, $class; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
151 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
152 |
98
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
153 sub viewAlly |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
154 { |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
155 my $self = shift; |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
156 my $allyId = shift; |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
157 |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
158 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=allyPage&allyId=%d", $self->{server}, $allyId)); |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
159 my $extractor = new Ikariam::Extractor(content => $res->content); |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
160 |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
161 my %ally; |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
162 $ally{'id'} = $allyId; |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
163 $ally{'name'} = $extractor->find("//table[\@id='allyinfo']/tr[1]/td[2]/text()"); |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
164 $ally{'members'} = $extractor->find("//table[\@id='allyinfo']/tr[2]/td[2]/text()"); |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
165 $ally{'url'} = $extractor->find("//table[\@id='allyinfo']/tr[5]/td[2]/text()"); |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
166 delete($ally{'url'}) if($ally{'url'} eq '-'); |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
167 |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
168 return \%ally; |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
169 } |
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
170 |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
171 sub viewScore |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
172 { |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
173 my $self = shift; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
174 my $type = shift || 'score'; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
175 my $user = shift || ''; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
176 my $offset = shift || 0; |
91
53c87400183f
rewrite viewScore with Extractor.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
88
diff
changeset
|
177 my %users; |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
178 |
117
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
179 $self->{mech}->get(sprintf("http://%s/index.php?view=highscore&showMe=1", $self->{server})); |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
180 my $res = $self->{mech}->submit_form( |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
181 form_number => 1, |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
182 fields => { |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
183 highscoreType => $type, |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
184 offset => $offset, |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
185 searchUser => $user, |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
186 } |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
187 ); |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
188 |
91
53c87400183f
rewrite viewScore with Extractor.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
88
diff
changeset
|
189 my $extractor = new Ikariam::Extractor(content => $res->content); |
53c87400183f
rewrite viewScore with Extractor.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
88
diff
changeset
|
190 my $result = $extractor->{doc}->find('//table[@class="table01"][2]//tr'); |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
191 |
91
53c87400183f
rewrite viewScore with Extractor.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
88
diff
changeset
|
192 foreach my $tr ( @$result ) { |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
193 my %user; |
117
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
194 my $extractor = new Ikariam::Extractor(content => $tr->toString(0)); |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
195 |
92
bcd2e32cfabb
fixed the user name encoding issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
91
diff
changeset
|
196 my $href = $extractor->find('//td[@class="action"]/a/@href'); |
91
53c87400183f
rewrite viewScore with Extractor.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
88
diff
changeset
|
197 if($href =~ /index\.php\?view=sendMessage&with=(\d+)&oldView=highscore/) { |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
198 $user{'id'} = $1; |
117
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
199 # $user{'name'} = $user; |
110
279a000eb3b0
fixed encoding issue of LibXML
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
106
diff
changeset
|
200 # encoding issue. |
279a000eb3b0
fixed encoding issue of LibXML
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
106
diff
changeset
|
201 $user{'name'} = $extractor->find('//td[@class="name"]/text()'); |
117
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
202 next if($user{'name'} eq ''); |
92
bcd2e32cfabb
fixed the user name encoding issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
91
diff
changeset
|
203 |
bcd2e32cfabb
fixed the user name encoding issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
91
diff
changeset
|
204 $user{'ally'} = $extractor->find('//td[@class="allytag"]/a/text()'); |
bcd2e32cfabb
fixed the user name encoding issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
91
diff
changeset
|
205 my $allyHref = $extractor->find('//td[@class="allytag"]/a/@href'); |
98
34749e907405
we now scan for ally
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
96
diff
changeset
|
206 if($allyHref =~ /\?view=allyPage&oldView=highscore&allyId=(\d+)/) { |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
207 $user{'allyId'} = $1; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
208 } |
92
bcd2e32cfabb
fixed the user name encoding issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
91
diff
changeset
|
209 $user{$type} = $extractor->find('//td[@class="score"]/text()'); |
19 | 210 $user{$type} =~ s/,//g; |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
211 $users{$user{'id'}} = \%user; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
212 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
213 } |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
214 # print(Dumper(\%users)); |
5
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
215 return \%users; |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
216 } |
dbb97c4265ba
implemented the scores search tool
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
3
diff
changeset
|
217 |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
218 sub viewWorldMap |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
219 { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
220 my $self = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
221 my $x = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
222 my $y = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
223 |
88
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
224 if(!defined($x) && !defined($y)) { |
1 | 225 die('location required'); |
226 } | |
227 | |
228 my $res = $self->{mech}->post(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server}), [ | |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
229 xajax => 'getMapData', |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
230 'xajaxargs[]' => $x, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
231 'xajaxargs[]' => $y, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
232 xajaxr => time, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
233 ]); |
1 | 234 |
235 my $c; | |
236 my $status = gunzip \$res->content => \$c | |
237 or die "gunzip failed: $GunzipError\n"; | |
238 | |
239 my @islands; | |
240 # parsing xjxobj | |
241 while($c =~ /<cmd n="jc" t="addToMap"><xjxobj><e><k>0<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>1<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>2<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>3<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>4<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>5<\/k><v><!\[CDATA\[(\w+)\]\]><\/v><\/e><e><k>6<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><e><k>7<\/k><v><!\[CDATA\[(\d+)\]\]><\/v><\/e><\/xjxobj><\/cmd>/g) | |
242 { | |
243 my %island; | |
244 $island{id} = $3; | |
245 $island{x} = $1; | |
246 $island{y} = $2; | |
247 $island{name} = $6; | |
248 $island{tradegood} = $4; | |
249 $island{wonder} = $5; | |
250 # $7 ? | |
251 $island{people} = $8; | |
252 push @islands, \%island; | |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
253 } |
1 | 254 return @islands; |
255 } | |
256 | |
3 | 257 sub viewHomeMap |
1 | 258 { |
259 my $self = shift; | |
260 | |
261 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=worldmap_iso", $self->{server})); | |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
262 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
263 my $c; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
264 my $status = gunzip \$res->content => \$c |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
265 or die "gunzip failed: $GunzipError\n"; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
266 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
267 # m[50][36]=new Array(564,1,5,'Risietia', '5', 13); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
268 # x = 43-57 = 6 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
269 # y = 27-41 = 6 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
270 my @islands; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
271 while($c =~ /m\[(\d+)\]\[(\d+)\]=new Array\((\d+),(\d+),(\d+),'(\w+)', '(\d+)', (\d+)\);/g) |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
272 { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
273 my %island; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
274 $island{id} = $3; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
275 $island{x} = $1; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
276 $island{y} = $2; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
277 $island{name} = $6; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
278 $island{tradegood} = $4; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
279 $island{wonder} = $5; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
280 # $7 ? |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
281 $island{people} = $8; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
282 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
283 #foreach my $i (sort(keys(%island))) |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
284 #{ |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
285 # printf ("%s %s\n", $i, $island{$i}); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
286 #} |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
287 #print("\n"); |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
288 push @islands, \%island; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
289 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
290 return @islands; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
291 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
292 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
293 sub viewIsland |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
294 { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
295 my $self = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
296 my $island = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
297 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
298 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=island&id=%s", $self->{server}, $island)); |
88
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
299 my $extractor = new Ikariam::Extractor(content => $res->content); |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
300 |
88
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
301 my @cities; |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
302 foreach my $i (0..16) { |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
303 my $cityLocations = $extractor->find(sprintf('//li[@id="cityLocation%s"]/@class', $i)); |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
304 if($cityLocations =~ /city level(\d+)/) { |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
305 my %info; |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
306 $info{'citylevel'} = $1; |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
307 $info{'cityname'} = $extractor->find(sprintf('//li[@id="cityLocation%s"]//li[@class="name"]/text()', $i)); |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
308 $info{'owner'} = $extractor->find(sprintf('//li[@id="cityLocation%s"]//li[@class="owner"]/text()', $i)); |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
309 $info{'owner'} =~ s/\s+//g; |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
310 $info{'ally'} = $extractor->find(sprintf('//li[@id="cityLocation%s"]//li[@class="ally"]/a/text()', $i)); |
117
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
311 if($info{'ally'} eq '-') { |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
312 delete($info{'ally'}) |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
313 } else { |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
314 my $href = $extractor->find(sprintf('//li[@id="cityLocation%s"]//li[@class="ally"]/a/@href', $i)); |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
315 if($href =~ /&allyId=(\d+)&/) { |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
316 $info{'allyId'} = $1; |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
317 } |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
318 } |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
319 |
5a66fea952fe
implemented a dirty hack to fixed the stupid highscore search function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
110
diff
changeset
|
320 # Ally Id |
88
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
321 my $href = $extractor->find(sprintf('//li[@id="cityLocation%s"]//a[@class="messageSend"]/@href', $i)); |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
322 if ($href =~ /with=(\d+)&destinationCityId=(\d+)/) { |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
323 $info{'user'} = $1; |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
324 $info{'cityId'} = $2; |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
325 } else { |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
326 # 聯盟 this is me. |
88
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
327 my $id = $extractor->find(sprintf('//li[@id="cityLocation%s"]/a/@id', $i)); |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
328 if($id =~ /city_(\d+)/) { |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
329 $info{'user'} = undef; # FIXME |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
330 $info{'cityId'} = $1; |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
331 } |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
332 } |
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
333 |
88
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
334 if(defined(($extractor->find(sprintf('//li[@id="cityLocation%s"]//span[@class="vacation"]', $i)))[0])) { |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
335 $info{'status'} = 'v'; |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
336 } |
96
65c102183458
saved the status of inactivity player
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
92
diff
changeset
|
337 if(defined(($extractor->find(sprintf('//li[@id="cityLocation%s"]//span[@class="inactivity"]', $i)))[0])) { |
65c102183458
saved the status of inactivity player
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
92
diff
changeset
|
338 $info{'status'} = 'i'; |
65c102183458
saved the status of inactivity player
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
92
diff
changeset
|
339 } |
88
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
340 push @cities, \%info; |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
341 } else { |
0fa9cd836e1e
rewrited the viewIsland function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
87
diff
changeset
|
342 # TODO: delete the old city. |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
343 } |
10
f590b5ea5e55
fixed bug of sheep.pl
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
9
diff
changeset
|
344 |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
345 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
346 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
347 return @cities; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
348 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
349 |
54
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
350 sub increaseTransporter { |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
351 my $self = shift; |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
352 my $param = shift; |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
353 my $cityId = shift; |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
354 |
80
7ab5fc8c847c
added some memo of TODO
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
79
diff
changeset
|
355 # TODO: 應該扣除買船之黃金, 以免誤計 |
7ab5fc8c847c
added some memo of TODO
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
79
diff
changeset
|
356 # TODO: 加上所有之船隻 |
7ab5fc8c847c
added some memo of TODO
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
79
diff
changeset
|
357 # my @cargoCost = qw/160 244 396 812 1240 1272 1832 1888 3848 3972 5204 5384 6868 7120 8864 9200 11268 11712 14108 14680 23320 24288 28664 29880 34956 36468 42348 44212 51024 53308 61236 64024 73096 76468 87020 91088 103224 116524 122072 137432 180060 202132 211964 237444 249108 278276 292076 306623 321963 338138 355198 373191 392171 412195 433320 455612 479135 503962 530166 557828 587031 617863 650420 684802 721113 759466 799981 842783 888005 935790 986286 1039654 1096062 1155689 1218724 1285369 1355837 1430353 1509159 1592508 1680670 1773932 1872597 1976989 2087448 2204338 2328045 2458976 2597567 2744276 2899594 3064040 3238163 3422550 3617820 3824635 4043693 4275738 4521561 4782000 5057946 5350345 5660202 5988585 6336630 6705540 7096598 7511164 7950683 8416694 8910828 9434823 9990523 10579889 11205006 11868090 12571498 13317734 14109462 14949514/; |
7ab5fc8c847c
added some memo of TODO
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
79
diff
changeset
|
358 # $city->{transporters}->{sum} |
7ab5fc8c847c
added some memo of TODO
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
79
diff
changeset
|
359 |
7ab5fc8c847c
added some memo of TODO
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
79
diff
changeset
|
360 # TODO: 找買船最便宜之城市 |
54
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
361 my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
362 foreach (1..2) { |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
363 if($locations[$_] eq 'port') { |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
364 my $res = $self->{mech}->get(sprintf('http://%s/index.php?action=CityScreen&function=increaseTransporter&id=%s&position=%s', |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
365 $self->{server}, $cityId, $_)); |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
366 } |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
367 } |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
368 } |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
369 |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
370 |
173
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
371 # for tavern only |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
372 sub set { |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
373 my $self = shift; |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
374 my $type = shift; |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
375 my $cityId = shift; |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
376 |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
377 die ("we don't know about this city") unless(defined($self->{'cities'}->{$cityId})); |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
378 |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
379 my $position = -1; |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
380 my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
381 foreach (0..$#locations) { |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
382 $position = $_ if($locations[$_] eq $type); |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
383 } |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
384 |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
385 if($position != -1) { |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
386 $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
387 $self->{mech}->submit_form( |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
388 form_number => 1, |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
389 fields => { |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
390 amount => $self->{'cities'}->{$cityId}->{$type}->{maxValue}, |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
391 } |
173
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
392 ); |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
393 |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
394 } |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
395 } |
e8a244ce5a1d
update the tavern setting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
172
diff
changeset
|
396 |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
397 sub is_shipyard_upgrading { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
398 my $self = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
399 my $cityId = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
400 my $type = "shipyard"; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
401 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
402 my $position = -1; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
403 my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
404 foreach (1..2) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
405 $position = $_ if($locations[$_] eq $type); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
406 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
407 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
408 if($position != -1) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
409 my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
410 if(defined(Ikariam::Extractor->new(content => $res->content)->find('//div[@class="isUpgrading"]'))) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
411 return 1; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
412 } else { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
413 return 0; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
414 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
415 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
416 return 0; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
417 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
418 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
419 sub is_navy_trainning { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
420 my $self = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
421 my $cityId = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
422 my $type = "shipyard"; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
423 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
424 my $position = -1; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
425 my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
426 foreach (1..2) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
427 $position = $_ if($locations[$_] eq $type); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
428 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
429 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
430 if($position != -1) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
431 my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
432 if(defined(Ikariam::Extractor->new(content => $res->content)->find('//div[@id="unitConstructionList"]//h4'))) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
433 return 1; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
434 } else { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
435 return 0; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
436 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
437 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
438 # FIXME we can not found the shipyard |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
439 return 0; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
440 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
441 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
442 sub buildShips { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
443 my $self = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
444 my $shipType = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
445 my $cityId = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
446 my $type = 'shipyard'; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
447 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
448 warn("buildShips $shipType"); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
449 my $position = -1; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
450 my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
451 foreach (1..2) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
452 $position = $_ if($locations[$_] eq $type); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
453 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
454 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
455 if($position != -1) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
456 my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
457 $self->{mech}->submit_form( |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
458 form_number => 1, |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
459 fields => { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
460 $shipType => 1, |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
461 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
462 ); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
463 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
464 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
465 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
466 sub is_army_trainning { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
467 my $self = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
468 my $cityId = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
469 my $type = "barracks"; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
470 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
471 my $position = -1; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
472 my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
473 foreach (2..$#locations) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
474 $position = $_ if($locations[$_] eq $type); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
475 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
476 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
477 if($position != -1) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
478 my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
479 if(defined(Ikariam::Extractor->new(content => $res->content)->find('//div[@id="unitConstructionList"]//h4'))) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
480 return 1; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
481 } else { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
482 return 0; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
483 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
484 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
485 # FIXME we can not found the shipyard |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
486 return 0; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
487 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
488 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
489 sub is_barracks_upgrading { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
490 my $self = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
491 my $cityId = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
492 my $type = 'barracks'; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
493 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
494 my $position = -1; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
495 my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
496 foreach (2..$#locations) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
497 $position = $_ if($locations[$_] eq $type); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
498 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
499 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
500 if($position != -1) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
501 my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
502 if(defined(Ikariam::Extractor->new(content => $res->content)->find('//div[@class="isUpgrading"]'))) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
503 return 1; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
504 } else { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
505 return 0; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
506 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
507 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
508 return 0; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
509 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
510 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
511 sub buildUnits { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
512 my $self = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
513 my $unitType = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
514 my $cityId = shift; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
515 my $type = 'barracks'; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
516 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
517 warn("buildShips $unitType"); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
518 my $position = -1; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
519 my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
520 foreach (2..$#locations) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
521 $position = $_ if($locations[$_] eq $type); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
522 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
523 |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
524 if($position != -1) { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
525 my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
526 $self->{mech}->submit_form( |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
527 form_number => 1, |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
528 fields => { |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
529 $unitType => 1, |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
530 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
531 ); |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
532 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
533 } |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
534 |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
535 sub build { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
536 my $self = shift; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
537 my $type = shift; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
538 my $cityId = shift; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
539 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
540 die ("we don't know about this city") unless(defined($self->{'cities'}->{$cityId})); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
541 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
542 my $position = -1; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
543 my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
544 foreach (0..$#locations) { |
54
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
545 $position = $_ if($locations[$_] eq $type); |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
546 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
547 |
82
82acbba33b97
fixed the build function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
81
diff
changeset
|
548 if($position == -1) { |
54
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
549 foreach (0..$#locations) { |
82
82acbba33b97
fixed the build function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
81
diff
changeset
|
550 # XXX |
54
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
551 next if($_ <= 2 && ($self->{buildingIDs}->{$type} ne "workshop-fleet" && |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
552 $self->{buildingIDs}->{$type} ne "shipyard")); |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
553 if($locations[$_] eq undef) { |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
554 my $res = $self->{mech}->get(sprintf('http://%s/index.php?action=CityScreen&function=build&id=%s&position=%s&building=%d', |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
555 $self->{server}, $cityId, $_, $self->{buildingIDs}->{$type} )); |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
556 last; |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
557 } |
2d3c394b7940
rules for build new building and buy transporters
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
52
diff
changeset
|
558 } |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
559 } else { |
82
82acbba33b97
fixed the build function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
81
diff
changeset
|
560 my $res = $self->{mech}->get (sprintf("http://%s/index.php?view=%s&id=%s&position=%d", $self->{server}, $type, $cityId, $position)); |
83 | 561 my $url = Ikariam::Extractor->new(content => $res->content)->find('//a[@title="升級建築物"]/@href'); |
562 $self->{mech}->get($url) if(defined($url)); | |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
563 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
564 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
565 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
566 sub run { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
567 my $self = shift; |
84
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
568 my $param = shift; |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
569 # defense. |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
570 warn ("run $param not implemented yet."); |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
571 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
572 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
573 sub research |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
574 { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
575 my $self = shift; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
576 my $type = shift; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
577 my $cityId = shift; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
578 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
579 # check if we are researching the same stuff |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
580 my $res = $self->{mech}->get(sprintf('http://%s/index.php?action=CityScreen&function=changeResearch&id=%s&researchType=%s', $self->{server}, $cityId, $type)); |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
581 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
582 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
583 sub checkResearch { |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
584 my $self = shift; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
585 my $cityId = shift; |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
586 |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
587 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=researchOverview&id=%s', $self->{server}, $cityId)); |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
588 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
589 my @urls = Ikariam::Extractor->new(content => $res->content)->find('//ul[@class="explored"]//a/@href'); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
590 my $out = {}; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
591 foreach(@urls) { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
592 if(/view=researchDetail&id=\d+&position=\d+&researchId=(\d+)$/) { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
593 # we ignore the chinese name of technology researched. |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
594 @$out{$1} = 1; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
595 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
596 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
597 return $out; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
598 } |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
599 |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
600 sub plunderCity { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
601 my $self = shift; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
602 my $cityId = shift; |
171
2efa901871e5
check peace treaty
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
603 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=plunder&destinationCityId=%d", $self->{server}, $cityId)); |
2efa901871e5
check peace treaty
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
604 |
2efa901871e5
check peace treaty
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
605 # check peace treaty |
2efa901871e5
check peace treaty
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
606 my $treaty = Ikariam::Extractor->new(content => $res->content)->find('//div[@class="warning"]'); |
2efa901871e5
check peace treaty
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
607 if(!defined($treaty)) { |
2efa901871e5
check peace treaty
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
608 $self->{mech}->submit_form( |
2efa901871e5
check peace treaty
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
609 form_number => 1, |
2efa901871e5
check peace treaty
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
610 fields => { |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
611 cargo_army_302 => '2', |
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
612 } |
171
2efa901871e5
check peace treaty
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
613 ); |
2efa901871e5
check peace treaty
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
614 } else { |
2efa901871e5
check peace treaty
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
615 warn ($treaty); |
2efa901871e5
check peace treaty
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
616 } |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
617 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
618 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
619 sub changeCity { |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
620 my $self = shift; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
621 my $cityId = shift; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
622 |
84
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
623 $self->{mech}->get(sprintf("http://%s/index.php", $self->{server})); |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
624 $self->{mech}->submit_form( |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
625 form_number => 2, |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
626 fields => { |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
627 cityId => $cityId, |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
628 } |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
629 ); |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
630 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
631 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
632 sub checkCity { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
633 my $self = shift; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
634 my $cityId = shift; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
635 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
636 $self->changeCity($cityId); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
637 |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
638 my $res = $self->{mech}->get(sprintf("http://%s/index.php?view=city&id=%d", $self->{server}, $cityId)); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
639 my $extractor = new Ikariam::Extractor(content => $res->content); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
640 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
641 $self->{'cities'}->{$cityId}->{resources}->{gold} = $extractor->find('//span[@id="value_gold"]/text()'); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
642 $self->{'cities'}->{$cityId}->{resources}->{gold} =~ s/,//g; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
643 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
644 $self->{'cities'}->{$cityId}->{name} = $extractor->find('//span[@class="city"]/text()'); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
645 |
125
4374173bab47
collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
117
diff
changeset
|
646 my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]'); |
4374173bab47
collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
117
diff
changeset
|
647 if($island =~ /(\w+)\[(\d+):(\d+)\]/) { |
4374173bab47
collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
117
diff
changeset
|
648 $self->{'cities'}->{$cityId}->{island}->{name} = $1; |
4374173bab47
collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
117
diff
changeset
|
649 $self->{'cities'}->{$cityId}->{island}->{x} = $2; |
4374173bab47
collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
117
diff
changeset
|
650 $self->{'cities'}->{$cityId}->{island}->{y} = $3; |
4374173bab47
collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
117
diff
changeset
|
651 $self->{'cities'}->{$cityId}->{island}->{id} = my $island = $extractor->find('//div[@id="breadcrumbs"]/a[@class="island"]/@href'); |
4374173bab47
collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
117
diff
changeset
|
652 $self->{'cities'}->{$cityId}->{island}->{id} =~ s/\?view=island&id=(\d+)/$1/; |
4374173bab47
collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
117
diff
changeset
|
653 } |
4374173bab47
collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
117
diff
changeset
|
654 |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
655 $self->{'cities'}->{$cityId}->{construction} = defined($extractor->find('//*[@class="constructionSite"]')) ? 1 : 0; |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
656 |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
657 # maxCapacity |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
658 my $page = $extractor->{doc}->toString(1); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
659 if($page =~ /maxCapacity : {\s+wood: (\d+),\s+wine: (\d+),\s+marble: (\d+),\s+crystal: (\d+),\s+sulfur: (\d+)\s+}/s) { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
660 $self->{'cities'}->{$cityId}->{maxCapacity}->{wood} = $1; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
661 $self->{'cities'}->{$cityId}->{maxCapacity}->{wine} = $2; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
662 $self->{'cities'}->{$cityId}->{maxCapacity}->{marble} = $3; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
663 $self->{'cities'}->{$cityId}->{maxCapacity}->{crystal} = $4; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
664 $self->{'cities'}->{$cityId}->{maxCapacity}->{sulfur} = $5; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
665 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
666 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
667 foreach my $good (qw/wood wine marble crystal sulfur/) { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
668 $self->{'cities'}->{$cityId}->{resources}->{$good} = $extractor->find(sprintf('//span[@id="value_%s"]', $good)); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
669 $self->{'cities'}->{$cityId}->{resources}->{$good} =~ s/,//g; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
670 } |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
671 |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
672 foreach my $i (0..14) { |
84
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
673 my @buildings = $extractor->find(sprintf('//li[@id="position%s"]/@class', $i)); |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
674 foreach my $building (@buildings) { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
675 if (!($building =~ /buildingGround/) && !($building =~ /townhall/)) { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
676 $self->{'cities'}->{$cityId}->{locations}[$i] = $building; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
677 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
678 my $span; |
84
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
679 my @spans = $extractor->find(sprintf('//li[@id="position%s"]//span[@class="textLabel"]/text()', $i)); |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
680 if($#spans >= 1) { |
81
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
681 $span = $spans[1]; |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
682 } else { |
81
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
683 $span = $spans[0]; |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
684 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
685 my (undef, undef, $level) = split(/ /, $span); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
686 $self->{'cities'}->{$cityId}->{buildings}->{$building} = $level; |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
687 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
688 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
689 } |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
690 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
691 $self->{'cities'}->{$cityId}->{transporters}->{avail} = $extractor->find('//span[@id="value_transAvail"]/text()'); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
692 $self->{'cities'}->{$cityId}->{transporters}->{sum} = $extractor->find('//span[@id="value_transSum"]/text()'); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
693 $self->{'cities'}->{$cityId}->{transporters}->{sum} =~ s/[\(|\)]//g; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
694 $self->{'cities'}->{$cityId}->{maxActionPoints} = $extractor->find('//span[@id="value_maxActionPoints"]');; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
695 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
696 |
172
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
697 sub checkTavern { |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
698 my $self = shift; |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
699 my $cityId = shift; |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
700 |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
701 my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
702 # init |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
703 $self->{'cities'}->{$cityId}->{'tavern'}->{'maxValue'} = 0; |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
704 $self->{'cities'}->{$cityId}->{'tavern'}->{'iniValue'} = 0; |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
705 foreach (0..$#locations) { |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
706 if($locations[$_] eq 'tavern') { |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
707 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=tavern&id=%d&position=%d', $self->{server}, $cityId, $_ )); |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
708 my $extractor = Ikariam::Extractor->new(content => $res->content); |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
709 if($extractor->{doc}->toString(0) =~ /maxValue : (\d+),\s+overcharge : \d+,\s+iniValue : (\d+),/) { |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
710 $self->{'cities'}->{$cityId}->{'tavern'}->{'maxValue'} = $1; |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
711 $self->{'cities'}->{$cityId}->{'tavern'}->{'iniValue'} = $2; |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
712 } |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
713 last; |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
714 } |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
715 } |
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
716 } |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
717 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
718 sub checkMilitaryAdvisorMilitaryMovements { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
719 my $self = shift; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
720 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorMilitaryMovements', $self->{server})); |
81
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
721 my $extractor = new Ikariam::Extractor(content => $res->content); |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
722 |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
723 $self->{'military'}->{wars} = 0; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
724 $self->{'military'}->{attack} = 0; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
725 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
726 foreach (qw/homeland elsewhere/) { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
727 $self->{'military'}->{$_} = (); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
728 my $result = $extractor->{doc}->find(sprintf('//div[@id="%s"]//ul[@id="battleReports"]/li[@class="enroute"]', $_)); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
729 foreach my $div ( @$result ) { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
730 my $extractor = new Ikariam::Extractor(content => $div->toString(1)); |
106 | 731 my $f = $extractor->find('//div[@class="report"]/a[1]/@href'); |
732 my $t = $extractor->find('//div[@class="report"]/a[2]/@href'); | |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
733 $f = $1 if($f =~ /\?view=island&cityId=(\d+)/); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
734 $t = $1 if($t =~ /\?view=island&cityId=(\d+)/); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
735 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
736 push @{$self->{'military'}->{$_}}, { from => $f, to => $t}; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
737 if($_ eq 'homeland') { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
738 $self->{'military'}->{wars}++; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
739 } else { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
740 $self->{'military'}->{attack}++; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
741 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
742 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
743 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
744 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
745 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
746 sub checkMilitaryAdvisorReportView { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
747 my $self = shift; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
748 my $combatId = shift; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
749 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorReportView&detailedCombatId=%s', $self->{server}, $combatId)); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
750 my $extractor = new Ikariam::Extractor(content => $res->content); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
751 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
752 my %report; |
81
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
753 |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
754 $report{id} = $combatId; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
755 my $c = $extractor->{doc}->toString(1); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
756 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
757 # FIXME 城鎮 6 級)的城牆( 2 級)為防禦部隊增加了 7% 的防禦力。 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
758 while($c =~ /城鎮\s+(\d+)/gs) { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
759 $report{cityLevel} = $1; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
760 $report{wallLevel} = $2; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
761 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
762 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
763 $report{attacker} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//th[@class="attackers"]'); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
764 $report{defender} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//th[@class="defenders"]'); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
765 $report{winner} = $extractor->find('//div[@id="troopsReport"]//table[@id="result"]//td[@class="winner"]'); |
81
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
766 |
150
fab1593cadf1
fixed the combat reading issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
148
diff
changeset
|
767 # the combat we win! |
147
7f9109a50679
trying to fixed report
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
146
diff
changeset
|
768 $report{targetCity} = $extractor->find('//div[@id="troopsReport"]/div/h3/a/text()'); |
7f9109a50679
trying to fixed report
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
146
diff
changeset
|
769 my $href = $extractor->find('//div[@id="troopsReport"]/div/h3/a/@href'); |
150
fab1593cadf1
fixed the combat reading issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
148
diff
changeset
|
770 if(!defined($href)) { |
fab1593cadf1
fixed the combat reading issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
148
diff
changeset
|
771 # the combat we lost! |
fab1593cadf1
fixed the combat reading issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
148
diff
changeset
|
772 $report{targetCity} = $extractor->find('//td[@class="battle"]/a/text()'); |
fab1593cadf1
fixed the combat reading issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
148
diff
changeset
|
773 $href = $extractor->find('//td[@class="battle"]/a/@href'); |
fab1593cadf1
fixed the combat reading issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
148
diff
changeset
|
774 } |
145
aad08889ddb3
hacked for s4.ikariam.tw
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
143
diff
changeset
|
775 |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
776 if($href =~ /index\.php\?view=island&id=(\d+)&selectCity=(\d+)/) { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
777 $report{island} = $1; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
778 $report{city} = $2; |
129
3756298f8e4b
fixed the island and city id in the military reports.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
125
diff
changeset
|
779 } else { |
150
fab1593cadf1
fixed the combat reading issue.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
148
diff
changeset
|
780 warn($href); |
143
bfa78302cf09
ignore some combat reports, which is not finished.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
129
diff
changeset
|
781 warn ("can not read combat reprot $combatId"); |
bfa78302cf09
ignore some combat reports, which is not finished.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
129
diff
changeset
|
782 return undef; |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
783 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
784 $report{gold} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="gold"]'); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
785 $report{wood} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="wood"]'); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
786 $report{crystal} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="glass"]'); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
787 $report{wine} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="wine"]'); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
788 $report{sulfur} = $extractor->find('//div[@id="troopsReport"]//ul[@class="resources"]/li[@class="sulfur"]'); |
81
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
789 |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
790 foreach(qw/gold wood crystal wine sulfur attacker defender winner/) { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
791 $report{$_} =~ s/^.*?:\s+//; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
792 $report{$_} =~ s/\s+$//; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
793 $report{$_} =~ s/,//g; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
794 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
795 return \%report; |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
796 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
797 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
798 sub checkMilitaryAdvisorCombatReports { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
799 my $self = shift; |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
800 my $page = shift || 0; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
801 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
802 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=militaryAdvisorCombatReports&start=%s', $self->{server}, $page)); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
803 my $extractor = new Ikariam::Extractor(content => $res->content); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
804 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
805 my $result = $extractor->{doc}->find('//div[@id="troopsOverview"]//table/tr[position()<=10]'); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
806 foreach my $tr ( @$result ) { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
807 my $trExtractor = new Ikariam::Extractor(content => $tr->toString(1)); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
808 my $date = $trExtractor->find('//td[@class="date"]'); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
809 $date =~ s/^\s+//g; $date =~ s/\s+$//g; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
810 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
811 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
812 my $href = $trExtractor->find('//td/a/@href'); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
813 if($href =~ /index.php\?view=militaryAdvisorReportView&combatId=(\d+)/) { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
814 my $report = Ikariam::Report->retrieve($1); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
815 if(!$report) { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
816 my $report_hash = $self->checkMilitaryAdvisorReportView($1); |
129
3756298f8e4b
fixed the island and city id in the military reports.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
125
diff
changeset
|
817 if(defined($report_hash)) { |
3756298f8e4b
fixed the island and city id in the military reports.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
125
diff
changeset
|
818 $report = Ikariam::Report->insert($report_hash); |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
819 |
129
3756298f8e4b
fixed the island and city id in the military reports.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
125
diff
changeset
|
820 if($date =~ /(\d+)\.(\d+)\. (\d+):(\d+)/) { |
3756298f8e4b
fixed the island and city id in the military reports.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
125
diff
changeset
|
821 my $unixtime = mktime (0, $4, $3, $1, ($2-1), '108'); |
3756298f8e4b
fixed the island and city id in the military reports.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
125
diff
changeset
|
822 $report->set('date', $unixtime); |
3756298f8e4b
fixed the island and city id in the military reports.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
125
diff
changeset
|
823 } |
3756298f8e4b
fixed the island and city id in the military reports.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
125
diff
changeset
|
824 $report->set('time', time); |
3756298f8e4b
fixed the island and city id in the military reports.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
125
diff
changeset
|
825 |
3756298f8e4b
fixed the island and city id in the military reports.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
125
diff
changeset
|
826 $report->update(); |
143
bfa78302cf09
ignore some combat reports, which is not finished.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
129
diff
changeset
|
827 } else { |
bfa78302cf09
ignore some combat reports, which is not finished.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
129
diff
changeset
|
828 # for some reason, we can not read the report. |
bfa78302cf09
ignore some combat reports, which is not finished.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
129
diff
changeset
|
829 next; |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
830 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
831 } else { |
129
3756298f8e4b
fixed the island and city id in the military reports.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
125
diff
changeset
|
832 # we have found the report we like to know, exit the function. |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
833 return; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
834 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
835 } else { |
129
3756298f8e4b
fixed the island and city id in the military reports.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
125
diff
changeset
|
836 # there is not report yet. |
101
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
837 return; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
838 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
839 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
840 |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
841 my @moreCombats = $extractor->find('//div[@id="troopsOverview"]//table/tr[position()>10]//a/@href'); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
842 foreach (@moreCombats){ |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
843 last if(/^javascript/); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
844 if(/\?view=militaryAdvisorCombatReports&start=(\d+)/) { |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
845 next if($1 le $page); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
846 $self->checkMilitaryAdvisorCombatReports($1); |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
847 last; |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
848 } |
592d3b3b7898
implemented the WAR robot
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
100
diff
changeset
|
849 } |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
850 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
851 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
852 sub checkTownHall { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
853 my $self = shift; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
854 my $cityId = shift; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
855 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
856 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=townHall&id=%d', $self->{server}, $cityId)); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
857 my $extractor = new Ikariam::Extractor(content => $res->content); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
858 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
859 # //div[@id='SatisfactionOverview']//div[@class='value'] |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
860 # //div[@id='SatisfactionOverview']//div[@class='text'] |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
861 $self->{"cities"}->{$cityId}->{happiness} = $extractor->find('//div[@id="SatisfactionOverview"]//div[@class="value"]'); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
862 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
863 # 取 SatisfactionOverview 中的其他值 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
864 # 一個城鎮的市民滿意度結合了多方面的因素 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
865 # check happiness |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
866 # Happiness = Basic bonuses (196 + Capital Bonus + Holiday Bonus(25)) + |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
867 # Wine (Tavern Base(12*level) + |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
868 # Tavern Bonus(80*step)) + |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
869 # Culture (Museum Base(20*level) + |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
870 # Cultural Goods Bonus(50*Cultural Goods)) - |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
871 # Population (population) - |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
872 # Corruption (Corruption rate * population) |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
873 # |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
874 # Growth Rate = Happiness * 0.02 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
875 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
876 # Space, 房屋數 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
877 $self->{'cities'}->{$cityId}->{"space"} = {}; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
878 $self->{'cities'}->{$cityId}->{"space"}->{'total'} = $extractor->find('//span[@class="value total"]/text()'); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
879 $self->{'cities'}->{$cityId}->{"space"}->{'occupied'} = $extractor->find('//span[@class="value occupied"]/text()'); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
880 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
881 my @values = $extractor->find('//div[@id="CityOverview"]//span[@class="value"]'); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
882 $self->{'cities'}->{$cityId}->{"growth"} = $values[0]; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
883 $self->{'cities'}->{$cityId}->{"incomegold"} = $values[1]; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
884 |
100 | 885 my $actionPoints = $extractor->find('//div[@id="CityOverview"]//li[@class="actions"]/text()'); |
886 if($actionPoints =~ /(\d+)\/(\d+)/) { | |
887 $self->{'cities'}->{$cityId}->{actionPoints} = $1; | |
888 $self->{'cities'}->{$cityId}->{maxActionPoints} = $2; | |
889 } | |
890 | |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
891 $self->{'cities'}->{$cityId}->{corruption} = $extractor->find('//li[@class="corruption"]//span[@title="目前腐敗程度"]'); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
892 $self->{'cities'}->{$cityId}->{corruption} =~ s/%//g; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
893 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
894 my @citizens_type = qw/citizens woodworkers specialworkers scientists/; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
895 @values = $extractor->find('//div[@id="PopulationGraph"]//span[@class="count"]'); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
896 foreach my $i (0..$#citizens_type) |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
897 { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
898 $self->{'cities'}->{$cityId}->{'citizens'}->{$citizens_type[$i]} = $values[$i]; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
899 $self->{'cities'}->{$cityId}->{'citizens'}->{total} += $values[$i]; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
900 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
901 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
902 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
903 sub checkArmies |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
904 { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
905 my $self = shift; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
906 my $cityId = shift; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
907 my %force_types; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
908 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
909 $force_types{'army'} = [ qw/undef undef Slinger Swordsman Phalanx Ram Archer Catapult Gunsman Mortar SteamGiant Gyrocopter Bombardier Doctor Cook/ ]; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
910 $force_types{'fleet'} = [ qw/undef undef Ram-Ship BallistaShip Flamethrower CatapultShip MortarShip PaddleWheelRam DivingBoat/ ]; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
911 |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
912 foreach my $x (qw/army fleet/) { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
913 $self->{'cities'}->{$cityId}->{$x} = {}; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
914 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=cityMilitary-%s&id=%d', $self->{server}, $x, $cityId)); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
915 my @numbers = Ikariam::Extractor->new(content => $res->content)->find('//table//tr/td'); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
916 foreach my $j (0..$#{$force_types{$x}}) { |
87
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
917 next if(!defined($force_types{$x}[$j])); |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
918 if ($numbers[$j] == '-') { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
919 $self->{'cities'}->{$cityId}->{$x}->{$force_types{$x}[$j]} = 0; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
920 } else { |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
921 $self->{'cities'}->{$cityId}->{$x}->{$force_types{$x}[$j]} = $numbers[$j]; |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
922 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
923 } |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
924 } |
52
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
925 } |
d2ac1e198ce4
implement a new agent based on Decision Tree (Decision::ParseTree)
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
48
diff
changeset
|
926 |
154
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
927 sub checkFriends |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
928 { |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
929 # must check cities first, so we know if we have a museum available. |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
930 my $self = shift; |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
931 |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
932 foreach my $cityId (keys(%{$self->{'cities'}})) { |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
933 my @locations = @{$self->{'cities'}->{$cityId}->{locations}}; |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
934 foreach (0..$#locations) { |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
935 if($locations[$_] eq 'museum') { |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
936 my $res = $self->{mech}->get(sprintf('http://%s/index.php?view=museum&id=%d&position=%d', $self->{server}, $cityId, $_ )); |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
937 my @hrefs = Ikariam::Extractor->new(content => $res->content)->find('//div[@class="content"]/table/tbody/tr/td/a[1]/@href'); |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
938 foreach my $href (@hrefs) { |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
939 if ($href =~ /&id=(\d+)&/) { |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
940 $self->{'friends'}->{$1} = undef; |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
941 } |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
942 } |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
943 last; |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
944 } |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
945 } |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
946 } |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
947 |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
948 if(-f "friends.txt") { |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
949 # load friends |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
950 open(IN, "friends.txt") or die "Unable to open friends.txt\n"; |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
951 while(<IN>) { |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
952 chomp; |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
953 my $friend = Ikariam::User->retrieve(name => $_); |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
954 $self->{friends}->{$friend->id} = undef if(defined($friend)); |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
955 } |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
956 close(IN); |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
957 } |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
958 } |
637314cc57ed
checking for friends.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
150
diff
changeset
|
959 |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
960 sub check |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
961 { |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
962 my $self = shift; |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
963 |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
964 # MilitaryAdvisor |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
965 $self->checkMilitaryAdvisorMilitaryMovements(); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
966 $self->checkMilitaryAdvisorCombatReports(); |
81
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
967 $self->{'research'} = $self->checkResearch((keys(%{$self->{'cities'}}))[0]); |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
968 |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
969 # alerts |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
970 # //li[@id="advCities"]/a[@class="normalalert"] |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
971 # //li[@id="advMilitary"]/a[@class="normalalert"] |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
972 # //li[@id="advResearch"]/a[@class="normalalert"] |
d57920014cb4
split buliding.yaml to city.yaml and overall.yaml
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
80
diff
changeset
|
973 # //li[@id="advDiplomacy"]/a[@class="normalalert"] |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
974 |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
975 # looking for cities |
125
4374173bab47
collect hometown island information.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
117
diff
changeset
|
976 foreach my $cityId (keys(%{$self->{'cities'}})) { |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
977 $self->checkCity($cityId); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
978 $self->checkTownHall($cityId); |
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
979 $self->checkArmies($cityId); |
172
ba03aa8abdb2
reading Tavern's infomration
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
154
diff
changeset
|
980 $self->checkTavern($cityId); |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
981 } |
26
d8117792c6f5
collecting more data from townHall
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
23
diff
changeset
|
982 return $self->{'cities'}; |
23
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
983 } |
54ab0becd730
implemented a prototype for collecting account status.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
19
diff
changeset
|
984 |
84
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
985 sub getNetIncome { |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
986 my $self = shift; |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
987 my $cityId = shift; |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
988 |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
989 Carp::croak("must assign cityId") if !defined($cityId); |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
990 |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
991 # 扣除研發每人花費 8 GOLD |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
992 return ($self->{cities}->{$cityId}->{citizens}->{total}*4 - $self->{cities}->{$cityId}->{citizens}->{scientists}*8 ); |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
993 } |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
994 |
87
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
995 sub getNavyExpenditure { |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
996 my $self = shift; |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
997 my $cityId = shift; |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
998 my $cities = $self->{cities}; |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
999 |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1000 my $ships = { |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1001 CargoShip => {n => "CargoShip",a => 0,d => 0,s => 4,c => "Steamship",v => 20,A => 0,D => 0}, |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1002 'Ram-Ship' => {n => "Ram-Ship",p => 6,w => 56,S => 21,b => "34m",u => 20,m => 1,o => 3,a => 16,d => 16,A => 4,D => 4,s => 10,c => "Sailer",v => 10}, |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1003 BallistaShip => {n => "BallistaShip",p => 5,w => 72,S => 29,b => "47m",u => 24,m => 3,o => 5,a => 20,d => 28,A => 5,D => 7,s => 11,c => "Sailer",v => 8,x => "Resistance"}, |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1004 Flamethrower => {n => "Flamethrower",p => 5,w => 105,S => 77,b => "1h 55m",u => 45,m => 5,o => 7,a => 40,d => 40,A => 10,D => 10,s => 12,c => "Steamship",v => 8,x => "Assault"}, |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1005 CatapultShip => {n => "CatapultShip",p => 10,w => 173,S => 76,b => "3h 11m",u => 57,m => 7,o => 10,a => 60,d => 60,A => 12,D => 12,s => 16,c => "Sailer",v => 6}, |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1006 MortarShip => {n => "MortarShip",p => 22,w => 456,S => 282,b => "3h 38m",u => 130,m => 12,o => 15,a => 160,d => 160,A => 35,D => 35,s => 14,c => "Steamship",v => 4}, |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1007 PaddleWheelRam => {n => "PaddleWheelRam",i => "steamboat",p => 12,w => 513,S => 167,b => "4h 8m",u => 114,m => 10,o => 13,a => 100,d => 90,A => 20,D => 18,s => 13,c => "Steamship",v => 8,x => "Assault"}, |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1008 DivingBoat => {n => "DivingBoat",i => "submarine",p => 16,w => 493,C => 378,b => "5h 5m",u => 126,m => 15,o => 16,a => 110,d => 155,A => 20,D => 30,s => 10,c => "Steamship",v => 2,x => "Resistance"} |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1009 }; |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1010 my $cost = 0; |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1011 foreach(keys(%{$cities->{$cityId}->{fleet}})) { |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1012 $cost += $cities->{$cityId}->{fleet}->{$_} * $ships->{$_}->{u}; |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1013 } |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1014 return $cost; |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1015 } |
4c82cf844aa8
counting navy expenditure
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
86
diff
changeset
|
1016 |
86
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1017 sub getMilityExpenditure { |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1018 my $self = shift; |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1019 my $cityId = shift; |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1020 my $cities = $self->{cities}; |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1021 my $troops = { |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1022 # p 需要人口 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1023 # w 木頭 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1024 # S 硫磺 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1025 # b 製造時間 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1026 # u 維持費用 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1027 # m 最低軍營等級 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1028 # o 最佳軍營等級 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1029 # a 攻擊力 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1030 # d 防守力 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1031 # A |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1032 # D |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1033 # s 耐力 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1034 # c 種類 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1035 # v speed |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1036 # x 加成 Assault, Resistance |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1037 Slinger => {n=>"Slinger",p=>1,w=>40,b=>"12m",u=>8,m=>1,o=>4,a=>7,d=>6,A=>2,D=>2,s=>10,c=>"Human",v=>20}, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1038 Swordsman => {n=>"Swordsman",p=>2,w=>47,S=>16,b=>"17m",u=>16,m=>3,o=>5,a=>18,d=>14,A=>4,D=>3,s=>12,c=>"Human",v=>20,x=>"Assault"}, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1039 Phalanx => {n=>"Phalanx",p=>4,w=>104,S=>64,b=>"40m",u=>24,m=>4,o=>7,a=>24,d=>40,A=>6,D=>10,s=>14,c=>"Human",v=>20,x=>"Resistance"}, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1040 Ram => {n=>"Ram",p=>8,w=>198,S=>128,b=>"42m",u=>52,m=>5,o=>8,a=>14,d=>18,A=>3,D=>4,s=>16,c=>"Machina",v=>20,x=>"Ram"}, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1041 Archer => {n=>"Archer",p=>4,w=>172,S=>86,b=>"49m",u=>32,m=>7,o=>10,a=>40,d=>40,A=>10,D=>10,s=>12,c=>"Human",v=>20}, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1042 Catapult => {n=>"Catapult",p=>10,w=>342,S=>232,b=>"49m",u=>72,m=>10,o=>14,a=>36,d=>28,A=>9,D=>7,s=>16,c=>"Machina",v=>20,x=>"Ram"}, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1043 Gunsman => {n=>"Gunsman",i=>"marksman",p=>7,w=>355,S=>154,b=>"1h 23m",u=>58,m=>14,o=>18,a=>80,d=>64,A=>18,D=>14,s=>10,c=>"Human",v=>20}, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1044 Mortar => {n=>"Mortar",p=>12,w=>1325,S=>938,b=>"1h 53m",u=>128,m=>19,o=>21,a=>64,d=>64,A=>15,D=>15,s=>16,c=>"Machina",v=>20,x=>"Ram"}, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1045 SteamGiant => {n=>"SteamGiant",i=>"steamgiant",p=>6,w=>1150,S=>716,b=>"1h 45m",u=>68,m=>16,o=>20,a=>100,d=>140,A=>20,D=>30,s=>14,c=>"Machina",v=>20,x=>"Resistance"}, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1046 Gyrocopter => {n=>"Gyrocopter",p=>8,w=>1250,S=>670,b=>"1h 2m",u=>97,m=>12,o=>16,a=>112,d=>112,A=>25,D=>25,s=>12,c=>"Machina",v=>20}, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1047 Bombardier => {n=>"Bombardier",p=>24,w=>2270,S=>878,b=>"2h 10m",u=>228,m=>22,o=>24,a=>200,d=>165,A=>45,D=>35,s=>14,c=>"Machina",v=>20,x=>"Assault"}, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1048 Doctor => {n=>"Doctor",i=>"medic",p=>6,w=>640,C=>361,b=>"1h 2m",u=>244,m=>11,o=>12,a=>4,d=>28,A=>0,D=>0,s=>14,c=>"Human",v=>20,x=>"Healer"}, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1049 Cook => {n=>"Cook",p=>4,w=>520,W=>103,b=>"38m",u=>138,m=>8,o=>8,a=>6,d=>26,A=>0,D=>0,s=>16,c=>"Human",v=>20,x=>"Regeneration"} |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1050 }; |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1051 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1052 my $cost = 0; |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1053 foreach(keys(%{$cities->{$cityId}->{army}})) { |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1054 # printf("%s %d = %d\n", $_, $cities->{$cityId}->{army}->{$_}, $cities->{$cityId}->{army}->{$_} * $troops->{$_}->{u}); |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1055 $cost += $cities->{$cityId}->{army}->{$_} * $troops->{$_}->{u}; |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1056 } |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1057 return $cost; |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1058 } |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1059 |
84
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1060 sub blanceHurmanResource { |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1061 my $self = shift; |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1062 my $cityId = shift; |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1063 my $workersRatio = { |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1064 'citizens' => 0.4, |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1065 'specialworkers' => 0.3, |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1066 'woodworkers' => 0.7, |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1067 }; |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1068 |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1069 my $netincome = $self->getNetIncome($cityId); |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1070 |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1071 # --- HR --- |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1072 # 扣除研發,四成種田生產,剩下 3:7 挖資源 |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1073 # 四成收入中可用兩成做軍事用途 |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1074 # 生產共四成 |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1075 my $produceworkers = int(($netincome * $workersRatio->{citizens}) / 4); |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1076 |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1077 # 換成生產人力 |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1078 my $freePeople = $self->{cities}->{$cityId}->{citizens}->{total} - ($produceworkers + $self->{cities}->{$cityId}->{scientists}); |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1079 |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1080 # XXX |
86
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1081 # 需計算資源開挖上限, 依照島等級區分 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1082 # 木頭 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1083 # create_slider({ |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1084 # dir : 'ltr', |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1085 # id : "default", |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1086 # maxValue : 367, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1087 # overcharge : 0, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1088 # iniValue : 367, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1089 # bg : "sliderbg", |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1090 # thumb : "sliderthumb", |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1091 # topConstraint: -10, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1092 # bottomConstraint: 344, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1093 # bg_value : "actualValue", |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1094 # bg_overcharge : "overcharge", |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1095 # textfield:"inputWorkers" |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1096 # }); |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1097 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1098 # create_slider({ |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1099 # dir : 'ltr', |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1100 # id : "default", |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1101 # maxValue : 367, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1102 # overcharge : 0, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1103 # iniValue : 367, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1104 # bg : "sliderbg", |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1105 # thumb : "sliderthumb", |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1106 # topConstraint: -10, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1107 # bottomConstraint: 344, |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1108 # bg_value : "actualValue", |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1109 # bg_overcharge : "overcharge", |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1110 # textfield:"inputWorkers" |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1111 # }); |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1112 |
a8acf50bf7bb
implemented a simple MilityExpenditure counting
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
84
diff
changeset
|
1113 Carp::carp(sprintf("Suggested HR palnning - produce: %s wood %s special %s\n", $produceworkers, int($freePeople*0.3), int($freePeople*0.7))); |
84
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1114 } |
2c6c219dc3ff
fixed the checkCity function, implemneted a human resources palnning function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
83
diff
changeset
|
1115 |
9
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
1116 sub logout |
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
1117 { |
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
1118 my $self = shift; |
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
1119 $self->{mech}->get(sprintf('http://%s/index.php?action=loginAvatar&function=logout', $self->{server})); |
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
1120 } |
ae412d1f7761
added logout function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
8
diff
changeset
|
1121 |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1122 sub login |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1123 { |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1124 my $self = shift; |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1125 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1126 my $res = $self->{mech}->post(sprintf("http://%s/index.php?action=loginAvatar&function=login", $self->{server}), [ |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1127 name => $self->{user}, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1128 password => $self->{pass}, |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1129 ]); |
79
9d92e8c12f58
rewrited the code in XPath.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
75
diff
changeset
|
1130 |
82
82acbba33b97
fixed the build function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
81
diff
changeset
|
1131 my @cities = Ikariam::Extractor->new(content => $res->content)->find('//option[@class="avatarCities coords"]/@value'); |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1132 |
82
82acbba33b97
fixed the build function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
81
diff
changeset
|
1133 if($#cities<0) { |
82acbba33b97
fixed the build function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
81
diff
changeset
|
1134 die ("login failed\n"); |
82acbba33b97
fixed the build function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
81
diff
changeset
|
1135 } |
82acbba33b97
fixed the build function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
81
diff
changeset
|
1136 foreach(@cities) { |
82acbba33b97
fixed the build function.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
81
diff
changeset
|
1137 $self->{'cities'}->{$_} = {}; |
183
2362c8c8909e
implemented military builder.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
174
diff
changeset
|
1138 $self->{'cities'}->{$_}->{id} = $_; |
0
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1139 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1140 } |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1141 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1142 |
abaee7064429
new scanning prototype.
"Rex Tsai <chihchun@kalug.linux.org.tw>"
parents:
diff
changeset
|
1143 1; |